diff --git a/StockWebHistory/Controllers/DataLoadController.cs b/StockWebHistory/Controllers/DataLoadController.cs index fb92d03..6b87489 100644 --- a/StockWebHistory/Controllers/DataLoadController.cs +++ b/StockWebHistory/Controllers/DataLoadController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using StockWebHistory.Models; using StockWebHistory.Services; namespace StockWebHistory.Controllers @@ -22,6 +23,35 @@ namespace StockWebHistory.Controllers { return View(); } + [HttpGet] + public IActionResult ShareEquity() + { + return View(new ShareEquityModel()); + } + + [HttpPost] + public IActionResult ShareEquity(ShareEquityModel model) + { + if (!ModelState.IsValid) + return View(model); + + // Exempel: skicka vidare till en resultatsida + return RedirectToAction(nameof(EquityFindings), new { date = model.SelectedDate }); + } + + public IActionResult EquityFindings(DateTime date) + { + (List EquityList, decimal TotalValue) stockList = _processingService.LoadStockListAsync(date).Result; + + ViewBag.TotalSum = stockList.TotalValue; + + var vm = new ShareEquityModel + { + SelectedDate = date, + StockEquities = stockList.EquityList + }; + return View(vm); + } [HttpPost] [ValidateAntiForgeryToken] diff --git a/StockWebHistory/Models/EquityTemp.cs b/StockWebHistory/Models/EquityTemp.cs new file mode 100644 index 0000000..216c466 --- /dev/null +++ b/StockWebHistory/Models/EquityTemp.cs @@ -0,0 +1,10 @@ +namespace StockWebHistory.Models; + +public class EquityTemp +{ + public string StockCode { get; set; } = string.Empty; + public DateTime Bought { get; set; } + public decimal BoughtPrice { get; set; } + public int Quantity { get; set; } + public decimal TotalValue => BoughtPrice * Quantity; +} diff --git a/StockWebHistory/Models/ShareEquityModel.cs b/StockWebHistory/Models/ShareEquityModel.cs new file mode 100644 index 0000000..8109ddf --- /dev/null +++ b/StockWebHistory/Models/ShareEquityModel.cs @@ -0,0 +1,9 @@ +namespace StockWebHistory.Models; + +public class ShareEquityModel +{ + + // Du kan även lägga till fler fält om du vill skicka med mer data i formuläret + public DateTime? SelectedDate { get; set; } + public List StockEquities { get; set; } = new List(); +} diff --git a/StockWebHistory/Services/FileProcessingService.cs b/StockWebHistory/Services/FileProcessingService.cs index 3e97cce..a295e03 100644 --- a/StockWebHistory/Services/FileProcessingService.cs +++ b/StockWebHistory/Services/FileProcessingService.cs @@ -12,14 +12,19 @@ public class FileProcessingService : IFileProcessingService private readonly StockWebDbContext _db; private readonly ILogger _logger; private readonly ITransactionNotesServices _notesServices; + private readonly IStockEquityServices _equityServices; + List stockList = new(); + public FileProcessingService(StockWebDbContext db, ILogger logger, - ITransactionNotesServices notesServices) + ITransactionNotesServices notesServices, + IStockEquityServices equityServices) { _db = db; _logger = logger; _notesServices = notesServices; + _equityServices = equityServices; } public async Task ProcessFileAsync(Stream stream, string fileExtension) @@ -142,4 +147,71 @@ public class FileProcessingService : IFileProcessingService } return result; } + + public async Task<(List EquityList, decimal TotalValue)> LoadStockListAsync(DateTime equityDate) + { + stockList = await _notesServices.GetAllExistingStockCodes(); + + + var stocks = await _equityServices.GetAllAsync(equityDate); + // var stocks = await _equityServices.GetAllAsync(); + + if (stocks == null || stocks.Count == 0) + { + await _equityServices.GenerateStockVisionAsync(); + stocks = await _equityServices.GetAllAsync(equityDate); + } + + // lwStocks.Items.Clear(); + var dTotal = stocks.Sum(s => s.BoughtPrice * s.Quantity); + // lblTotalValue.Text = dTotal.ToString("C"); + + var equityTempList = new List(); + + EquityTemp equityTemp = new EquityTemp + { + StockCode = "Total", + Bought = DateTime.MinValue, + BoughtPrice = 0, + Quantity = 0 + }; + + foreach (var t in stocks.OrderBy(s => s.StockCode + s.Bought).ToList()) + { + if (t.StockCode != equityTemp.StockCode) + { + stockList.Remove(t.StockCode); + + if (equityTemp.StockCode != "Total") + { + EquityTemp equityTempSave = new EquityTemp + { + StockCode = equityTemp.StockCode, + Bought = equityTemp.Bought, + BoughtPrice = equityTemp.BoughtPrice, + Quantity = equityTemp.Quantity + }; + equityTempList.Add(equityTempSave); + } + equityTemp.StockCode = t.StockCode; + equityTemp.Bought = t.Bought; + equityTemp.Quantity = t.Quantity; + equityTemp.BoughtPrice = t.BoughtPrice; + continue; + } + else + { + if (t.Bought < equityTemp.Bought) + equityTemp.Bought = t.Bought; + if (t.BoughtPrice < equityTemp.BoughtPrice || equityTemp.BoughtPrice == 0) + equityTemp.BoughtPrice = t.BoughtPrice; + equityTemp.Quantity += t.Quantity; + } + + } + stockList.Remove(equityTemp.StockCode); + + equityTempList.Add(equityTemp); + return (equityTempList, dTotal); + } } diff --git a/StockWebHistory/Services/IFileProcessingService.cs b/StockWebHistory/Services/IFileProcessingService.cs index ed623a9..95501d8 100644 --- a/StockWebHistory/Services/IFileProcessingService.cs +++ b/StockWebHistory/Services/IFileProcessingService.cs @@ -1,7 +1,10 @@ -namespace StockWebHistory.Services +using StockWebHistory.Models; + +namespace StockWebHistory.Services { public interface IFileProcessingService { Task ProcessFileAsync(Stream stream, string fileExtension); + Task<(List EquityList, decimal TotalValue)> LoadStockListAsync(DateTime equityDate); } } diff --git a/StockWebHistory/Services/IStockEquityServices.cs b/StockWebHistory/Services/IStockEquityServices.cs index 094477c..7732a98 100644 --- a/StockWebHistory/Services/IStockEquityServices.cs +++ b/StockWebHistory/Services/IStockEquityServices.cs @@ -4,7 +4,7 @@ namespace StockWebHistory.Services { public interface IStockEquityServices { - Task> GenerateStockVision(); + Task> GenerateStockVisionAsync(); Task> GetAllAsync(); Task> GetLatestSoldInfoAsync(); Task> GetAllAsync(DateTime equityDate); diff --git a/StockWebHistory/Services/StockEquityServices.cs b/StockWebHistory/Services/StockEquityServices.cs index 619641f..093b433 100644 --- a/StockWebHistory/Services/StockEquityServices.cs +++ b/StockWebHistory/Services/StockEquityServices.cs @@ -84,7 +84,7 @@ public class StockEquityServices : IStockEquityServices /// utgående från alla befintliga notor skapa en lista med aktieinnehav. /// /// - public async Task> GenerateStockVision() + public async Task> GenerateStockVisionAsync() { var oldStock = "OldStock"; var nyAktie = false; diff --git a/StockWebHistory/StaticAssetsExtensions.cs b/StockWebHistory/StaticAssetsExtensions.cs new file mode 100644 index 0000000..d8d13b6 --- /dev/null +++ b/StockWebHistory/StaticAssetsExtensions.cs @@ -0,0 +1,20 @@ +// C# +public static class StaticAssetsExtensions +{ + public static IApplicationBuilder MapStaticAssets(this WebApplication app) + { + if (app == null) throw new ArgumentNullException(nameof(app)); + var env = app.Environment ?? throw new InvalidOperationException("IWebHostEnvironment not available."); + // Ensure static files middleware is present + app.UseStaticFiles(); // registers default file provider; safe even if WebRootPath is null + // Additional config: guard against null file provider or missing configuration + return app; + } + + public static IEndpointRouteBuilder WithStaticAssets(this IEndpointRouteBuilder endpoints) + { + if (endpoints == null) throw new ArgumentNullException(nameof(endpoints)); + // safe usage of environment/config should be via DI, with null checks + return endpoints; + } +} \ No newline at end of file diff --git a/StockWebHistory/StockWebHistory.csproj b/StockWebHistory/StockWebHistory.csproj index 4beaeec..a279726 100644 --- a/StockWebHistory/StockWebHistory.csproj +++ b/StockWebHistory/StockWebHistory.csproj @@ -8,6 +8,8 @@ + + diff --git a/StockWebHistory/StockWebHistory.db b/StockWebHistory/StockWebHistory.db index 69ce72c..769d3d6 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 26f7092..c3befad 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 a4a2070..0ecc0b5 100644 Binary files a/StockWebHistory/StockWebHistory.db-wal and b/StockWebHistory/StockWebHistory.db-wal differ diff --git a/StockWebHistory/Views/DataLoad/EquityFindings.cshtml b/StockWebHistory/Views/DataLoad/EquityFindings.cshtml new file mode 100644 index 0000000..a173b0c --- /dev/null +++ b/StockWebHistory/Views/DataLoad/EquityFindings.cshtml @@ -0,0 +1,39 @@ +@{ + ViewData["Title"] = "Equity Findings"; +} +@model StockWebHistory.Models.ShareEquityModel + + +

Du valde datumet:

+

@Model.SelectedDate?.ToString("yyyy-MM-dd")

+
+
+

Total Stock Value @ViewBag.TotalSum.ToString("F2") SEK

+
+ + + + + + + + + + + + + @{ + foreach (var note in Model.StockEquities) + { + + + + + + + + } + } + +
StockCodeBoughtBoughtPriceQuantityTotalValue
@note.StockCode@note.Bought.ToString("yyyy-MM-dd")@note.BoughtPrice.ToString("F2")@note.Quantity.ToString("F")@(note.TotalValue == null ? "" : ((decimal)note.TotalValue).ToString("F2", System.Globalization.CultureInfo.InvariantCulture))
+ diff --git a/StockWebHistory/Views/DataLoad/EquityFindings.cshtml.cs b/StockWebHistory/Views/DataLoad/EquityFindings.cshtml.cs new file mode 100644 index 0000000..25427fa --- /dev/null +++ b/StockWebHistory/Views/DataLoad/EquityFindings.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace StockWebHistory.Views.DataLoad +{ + public class EquityFindingsModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/StockWebHistory/Views/DataLoad/Files.cshtml b/StockWebHistory/Views/DataLoad/Files.cshtml index 072fb29..47b27c0 100644 --- a/StockWebHistory/Views/DataLoad/Files.cshtml +++ b/StockWebHistory/Views/DataLoad/Files.cshtml @@ -1,4 +1,6 @@ -@page +@{ + ViewData["Title"] = "File Upload"; +} @model FileUploadViewModel diff --git a/StockWebHistory/Views/DataLoad/Index.cshtml b/StockWebHistory/Views/DataLoad/Index.cshtml index 7f8ff2b..6523667 100644 --- a/StockWebHistory/Views/DataLoad/Index.cshtml +++ b/StockWebHistory/Views/DataLoad/Index.cshtml @@ -5,5 +5,5 @@

Welcome to Data Loading

File Types - History + Share Equity
\ No newline at end of file diff --git a/StockWebHistory/Views/DataLoad/ShareEquity.cs b/StockWebHistory/Views/DataLoad/ShareEquity.cs new file mode 100644 index 0000000..e1ea95b --- /dev/null +++ b/StockWebHistory/Views/DataLoad/ShareEquity.cs @@ -0,0 +1,6 @@ +namespace StockWebHistory.Views.DataLoad +{ + public class ShareEquity + { + } +} diff --git a/StockWebHistory/Views/DataLoad/ShareEquity.cshtml b/StockWebHistory/Views/DataLoad/ShareEquity.cshtml new file mode 100644 index 0000000..da0cfe1 --- /dev/null +++ b/StockWebHistory/Views/DataLoad/ShareEquity.cshtml @@ -0,0 +1,59 @@ +@{ + ViewData["Title"] = "Share Equity"; +} + +@model ShareEquityModel + +
+

Analyse stock notes

+
+ +
+

Välj ett datum

+ +
+
+ + +
+ + +
+
+ +@section Scripts { + +} + + + +@* + *@ \ No newline at end of file diff --git a/StockWebHistory/Views/DataLoad/ShareEquity.cshtml.cs b/StockWebHistory/Views/DataLoad/ShareEquity.cshtml.cs new file mode 100644 index 0000000..1146b72 --- /dev/null +++ b/StockWebHistory/Views/DataLoad/ShareEquity.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace StockWebHistory.Views.DataLoad +{ + public class ShareEquityModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/StockWebHistory/Views/Shared/_Layout.cshtml b/StockWebHistory/Views/Shared/_Layout.cshtml index d708eb8..280e990 100644 --- a/StockWebHistory/Views/Shared/_Layout.cshtml +++ b/StockWebHistory/Views/Shared/_Layout.cshtml @@ -1,5 +1,6 @@  + @@ -9,6 +10,7 @@ +