diff --git a/StockWebHistory/Data/StockWebDbContext.cs b/StockWebHistory/Data/StockWebDbContext.cs index 48ca7a3..111dcd9 100644 --- a/StockWebHistory/Data/StockWebDbContext.cs +++ b/StockWebHistory/Data/StockWebDbContext.cs @@ -15,7 +15,7 @@ namespace StockWebHistory.Data { base.OnModelCreating(modelBuilder); modelBuilder.Entity() - .HasIndex(t => new { t.StockCode, t.TransactionDate }) + .HasIndex(t => new { t.StockISIN, t.StockCode, t.TransactionDate }) .IsUnique(true); modelBuilder.Entity() .HasIndex(s => new { s.Bought }) @@ -24,7 +24,7 @@ namespace StockWebHistory.Data .HasIndex(s => new { s.Sold }) .IsUnique(false); modelBuilder.Entity() - .HasIndex(s => new { s.Bought, s.StockCode, s.Quantity }) + .HasIndex(s => new { s.Bought, s.StockISIN, s.Quantity }) .IsUnique(false); } } diff --git a/StockWebHistory/Migrations/20260927091703_newfield_ISIN.Designer.cs b/StockWebHistory/Migrations/20260927091703_newfield_ISIN.Designer.cs new file mode 100644 index 0000000..8c4482b --- /dev/null +++ b/StockWebHistory/Migrations/20260927091703_newfield_ISIN.Designer.cs @@ -0,0 +1,116 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StockWebHistory.Data; + +#nullable disable + +namespace StockWebHistory.Migrations +{ + [DbContext(typeof(StockWebDbContext))] + [Migration("20260927091703_newfield_ISIN")] + partial class newfield_ISIN + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "9.0.0"); + + modelBuilder.Entity("StockWebHistory.Models.StockEquity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Bought") + .HasColumnType("TEXT"); + + b.Property("BoughtPrice") + .HasColumnType("TEXT"); + + b.Property("Quantity") + .HasColumnType("INTEGER"); + + b.Property("Sold") + .HasColumnType("TEXT"); + + b.Property("SoldPrice") + .HasColumnType("TEXT"); + + b.Property("SoldQuant") + .HasColumnType("INTEGER"); + + b.Property("StockCode") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("StockISIN") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Bought"); + + b.HasIndex("Sold"); + + b.HasIndex("Bought", "StockISIN", "Quantity"); + + b.ToTable("Stocks"); + }); + + modelBuilder.Entity("StockWebHistory.Models.TransactionNote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AmountToPay") + .HasColumnType("TEXT"); + + b.Property("Commission") + .HasColumnType("TEXT"); + + b.Property("Currency") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ExchangeRate") + .HasColumnType("TEXT"); + + b.Property("StockCode") + .HasColumnType("TEXT"); + + b.Property("StockISIN") + .HasColumnType("TEXT"); + + b.Property("StockPrice") + .HasColumnType("TEXT"); + + b.Property("StockQuantity") + .HasColumnType("INTEGER"); + + b.Property("TotalAmount") + .HasColumnType("TEXT"); + + b.Property("TransactionDate") + .HasColumnType("TEXT"); + + b.Property("TransactionType") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("StockISIN", "StockCode", "TransactionDate") + .IsUnique(); + + b.ToTable("TransactionNotes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/StockWebHistory/Migrations/20260927091703_newfield_ISIN.cs b/StockWebHistory/Migrations/20260927091703_newfield_ISIN.cs new file mode 100644 index 0000000..90a275a --- /dev/null +++ b/StockWebHistory/Migrations/20260927091703_newfield_ISIN.cs @@ -0,0 +1,77 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace StockWebHistory.Migrations +{ + /// + public partial class newfield_ISIN : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_TransactionNotes_StockCode_TransactionDate", + table: "TransactionNotes"); + + migrationBuilder.DropIndex( + name: "IX_Stocks_Bought_StockCode_Quantity", + table: "Stocks"); + + migrationBuilder.AddColumn( + name: "StockISIN", + table: "TransactionNotes", + type: "TEXT", + nullable: true); + + migrationBuilder.AddColumn( + name: "StockISIN", + table: "Stocks", + type: "TEXT", + nullable: false, + defaultValue: ""); + + migrationBuilder.CreateIndex( + name: "IX_TransactionNotes_StockISIN_StockCode_TransactionDate", + table: "TransactionNotes", + columns: new[] { "StockISIN", "StockCode", "TransactionDate" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Stocks_Bought_StockISIN_Quantity", + table: "Stocks", + columns: new[] { "Bought", "StockISIN", "Quantity" }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_TransactionNotes_StockISIN_StockCode_TransactionDate", + table: "TransactionNotes"); + + migrationBuilder.DropIndex( + name: "IX_Stocks_Bought_StockISIN_Quantity", + table: "Stocks"); + + migrationBuilder.DropColumn( + name: "StockISIN", + table: "TransactionNotes"); + + migrationBuilder.DropColumn( + name: "StockISIN", + table: "Stocks"); + + migrationBuilder.CreateIndex( + name: "IX_TransactionNotes_StockCode_TransactionDate", + table: "TransactionNotes", + columns: new[] { "StockCode", "TransactionDate" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Stocks_Bought_StockCode_Quantity", + table: "Stocks", + columns: new[] { "Bought", "StockCode", "Quantity" }); + } + } +} diff --git a/StockWebHistory/Migrations/StockWebDbContextModelSnapshot.cs b/StockWebHistory/Migrations/StockWebDbContextModelSnapshot.cs index 6ed848a..d081d41 100644 --- a/StockWebHistory/Migrations/StockWebDbContextModelSnapshot.cs +++ b/StockWebHistory/Migrations/StockWebDbContextModelSnapshot.cs @@ -45,13 +45,17 @@ namespace StockWebHistory.Migrations .IsRequired() .HasColumnType("TEXT"); + b.Property("StockISIN") + .IsRequired() + .HasColumnType("TEXT"); + b.HasKey("Id"); b.HasIndex("Bought"); b.HasIndex("Sold"); - b.HasIndex("Bought", "StockCode", "Quantity"); + b.HasIndex("Bought", "StockISIN", "Quantity"); b.ToTable("Stocks"); }); @@ -78,6 +82,9 @@ namespace StockWebHistory.Migrations b.Property("StockCode") .HasColumnType("TEXT"); + b.Property("StockISIN") + .HasColumnType("TEXT"); + b.Property("StockPrice") .HasColumnType("TEXT"); @@ -95,7 +102,7 @@ namespace StockWebHistory.Migrations b.HasKey("Id"); - b.HasIndex("StockCode", "TransactionDate") + b.HasIndex("StockISIN", "StockCode", "TransactionDate") .IsUnique(); b.ToTable("TransactionNotes"); diff --git a/StockWebHistory/Models/EquityTemp.cs b/StockWebHistory/Models/EquityTemp.cs index 216c466..8501932 100644 --- a/StockWebHistory/Models/EquityTemp.cs +++ b/StockWebHistory/Models/EquityTemp.cs @@ -3,6 +3,7 @@ public class EquityTemp { public string StockCode { get; set; } = string.Empty; + public string StockISIN { get; set; } = string.Empty; public DateTime Bought { get; set; } public decimal BoughtPrice { get; set; } public int Quantity { get; set; } diff --git a/StockWebHistory/Models/StockEquity.cs b/StockWebHistory/Models/StockEquity.cs index 14db324..e8eccbb 100644 --- a/StockWebHistory/Models/StockEquity.cs +++ b/StockWebHistory/Models/StockEquity.cs @@ -4,6 +4,7 @@ public class StockEquity { public int Id { get; set; } public string StockCode { get; set; } = string.Empty; + public string StockISIN { get; set; } = string.Empty; public DateTime Bought { get; set; } public decimal BoughtPrice { get; set; } public int Quantity { get; set; } diff --git a/StockWebHistory/Models/TransactionNote.cs b/StockWebHistory/Models/TransactionNote.cs index 7930b8d..9a9b859 100644 --- a/StockWebHistory/Models/TransactionNote.cs +++ b/StockWebHistory/Models/TransactionNote.cs @@ -6,6 +6,7 @@ public class TransactionNote public DateTime TransactionDate { get; set; } public string? TransactionType { get; set; } public string? StockCode { get; set; } + public string? StockISIN { get; set; } public decimal StockPrice { get; set; } public decimal? ExchangeRate { get; set; } public string Currency { get; set; } diff --git a/StockWebHistory/Models/TransactionNoteMap.cs b/StockWebHistory/Models/TransactionNoteMap.cs index 4a73729..64660f9 100644 --- a/StockWebHistory/Models/TransactionNoteMap.cs +++ b/StockWebHistory/Models/TransactionNoteMap.cs @@ -12,6 +12,7 @@ namespace StockWebHistory.Models Map(m => m.Id).Ignore(); // Matcha CSV-kolumner mot C#-egenskaper Map(m => m.StockCode).Name(@"Värdepapper/beskrivning", @"Värdepapper"); // Exemplet kollar flera alternativa namn + Map(m => m.StockISIN).Name(@"ISIN"); // Exemplet kollar flera alternativa namn Map(m => m.TransactionDate).Name("Datum", "Date", "Affärsdag"); Map(m => m.TransactionType).Name("Typ av transaktion", "Transaktion"); Map(m => m.StockQuantity).Name("Antal", "Innehavsförändring"); diff --git a/StockWebHistory/Services/StockEquityServices.cs b/StockWebHistory/Services/StockEquityServices.cs index 093b433..8251367 100644 --- a/StockWebHistory/Services/StockEquityServices.cs +++ b/StockWebHistory/Services/StockEquityServices.cs @@ -127,6 +127,7 @@ public class StockEquityServices : IStockEquityServices var equity = new StockEquity { StockCode = note.StockCode, + StockISIN = note.StockISIN, Bought = note.TransactionDate, BoughtPrice = note.StockPrice, Quantity = note.StockQuantity, @@ -151,14 +152,8 @@ public class StockEquityServices : IStockEquityServices { equityWarningList.Add(new StockEquity { - //StockCode = note.StockCode, - //Bought = DateTime.MinValue, - //BoughtPrice = 0, - //Quantity = 0, - //Sold = note.TransactionDate, - //SoldPrice = note.StockPrice, - //SoldQuant = note.StockQuantity StockCode = note.StockCode, + StockISIN = note.StockISIN, Bought = note.TransactionDate, BoughtPrice = note.StockPrice * -1, Quantity = note.StockQuantity, @@ -201,6 +196,7 @@ public class StockEquityServices : IStockEquityServices var splitEquity = new StockEquity { StockCode = eq.StockCode, + StockISIN = eq.StockISIN, Bought = eq.Bought, BoughtPrice = eq.BoughtPrice, Quantity = soldQuant, diff --git a/StockWebHistory/StockWebHistory.db b/StockWebHistory/StockWebHistory.db index 769d3d6..3f33e72 100644 Binary files a/StockWebHistory/StockWebHistory.db and b/StockWebHistory/StockWebHistory.db differ diff --git a/StockWebHistory/StockWebHistory.db-shm b/StockWebHistory/StockWebHistory.db-shm index c3befad..fe9ac28 100644 Binary files a/StockWebHistory/StockWebHistory.db-shm and b/StockWebHistory/StockWebHistory.db-shm differ diff --git a/StockWebHistory/StockWebHistory.db-wal b/StockWebHistory/StockWebHistory.db-wal index 0ecc0b5..e69de29 100644 Binary files a/StockWebHistory/StockWebHistory.db-wal and b/StockWebHistory/StockWebHistory.db-wal differ diff --git a/StockWebHistory/Views/Home/Notes.cshtml b/StockWebHistory/Views/Home/Notes.cshtml index 0faf500..fde6e6e 100644 --- a/StockWebHistory/Views/Home/Notes.cshtml +++ b/StockWebHistory/Views/Home/Notes.cshtml @@ -19,6 +19,7 @@ Id TransactionDate TransactionType + StockCodeISIN StockCode StockPrice ExchangeRate @@ -37,6 +38,7 @@ @note.Id @note.TransactionDate.ToString("yyyy-MM-dd") @note.TransactionType + @note.StockISIN @note.StockCode @note.StockPrice.ToString("F2") @(note.ExchangeRate == null ? "" : ((decimal)note.ExchangeRate).ToString("F2", System.Globalization.CultureInfo.InvariantCulture)) @@ -47,11 +49,13 @@ @(note.AmountToPay == null ? "" : ((decimal)note.AmountToPay).ToString("F2", System.Globalization.CultureInfo.InvariantCulture)) Edit - Delete - - } + + Delete + + } - - + } + +