From 25ac717b56cbf58dfec68a820baab1101a392a32 Mon Sep 17 00:00:00 2001 From: Dimitar Byalkov Date: Sat, 20 Mar 2021 12:12:28 +0200 Subject: [PATCH] Views, Add Time in Deal & Stock --- Luminous Sales.pptx | Bin 294103 -> 294341 bytes .../Business/Interfaces/ISalesController.cs | 4 +- .../Business/Business/Sales/DealController.cs | 9 +- .../Business/Sales/StockController.cs | 11 ++- LuminousSales/Display/Display.csproj | 7 +- .../{InitialSetup => }/InitialSetup.cs | 18 ++-- LuminousSales/Display/Program.cs | 2 + LuminousSales/Display/Views/AdminView.cs | 78 ++++++++++++------ LuminousSales/Display/Views/BaseView.cs | 51 +++++++----- LuminousSales/Display/Views/ManagerView.cs | 70 +++++++++------- LuminousSales/Models/Models/Base/BaseSales.cs | 3 +- LuminousSales/Models/Models/Deal.cs | 3 +- LuminousSales/Models/Models/Stock.cs | 2 +- 13 files changed, 155 insertions(+), 103 deletions(-) rename LuminousSales/Display/{InitialSetup => }/InitialSetup.cs (60%) diff --git a/Luminous Sales.pptx b/Luminous Sales.pptx index 539d8656cbcea277f00a4b965e19d94f8da5c09b..5a4b013c8cdb585e459533c79b919eb9225bd5b8 100644 GIT binary patch delta 4011 zcmY+H1yGb-7sr=nmu6{@rIGGNL0J$Mq*FSUknUKTrKD40$(0tQQ3OR0M8p?GcwOmO zT99s$@LP1|`{sLQ?wtSco^#{5Gxwf36K6C7=QJ&8G$?ifLy2@S0ANQ605AXm0AJrg z@c>UZr-uQ5jf_}`muG|7ocD|zeGf-VFm+(F`Qu}c_ks>nVq{1B_os;wJPNexmuXeo zPW{nMOkL~4-b56W!?xw-6OC3AN^uwJiahY!U-W0V$f>RPsHjHHz62{7ou7Wuc4&}z zh=SXs>$;4{QCe3AnVPsb9!_CjF%%Ll*A7wF3Ez|Q%O!4+8W1>SlEd(!c(3Gy%zBs z$fHXkU827IDK){(XZU-Fhk)~fdec1V1_~ght$&}d$Ko*8K?L(`EONR;M#Dr8X3J(+ z`4J$Ftu-KR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8-nHAC}I z1JJBF^!Z*6zkV#)fwQUm1s<{o}urk=p2KXO)dz(~_R*5K+c>BNRa9s0*- z>yKLG9B-a@7lW)`1HtOfE+)V_=$fiJqW}N`rps}1TaHaf{y}%{xDt0 zX%UK!JQpPujiA_zvI1%TFiEfm;N%ZO0dxMaGmvwrzvl^JtiUJwJj6)szhgjV09|7t z{&)QOcN{43pZNH1J)A<6gtPx+Aq)+W0%4aS2a>;4Kp_#v2^<8%PD4&f|92URkqj%~ zNTgel02GLHE7e4p5=24v?*z(Kxj$aufY?nKKSW)QJ|hCS-lUrgIRm8Mgc(CVsL{s+ zfnPUaauCC_6f=wnpiDOdTnnNnC}ROq5M4B5{71AJL>I|e{$cf7bbey}hZBBtwGBP_ zBtZMk@(zC(9ZY8z=RcaD-`qj?!+pOwDuB-aKGDa4|8c1tLfbd()~Zw0Bk~G=OA;=Kw&6M3*zVs%!a}+5G_1#G7Khi;_q6) s00P1PIaN9>xdHZJFyRw_t|1r%Dxg;s#Q!N?djNU#H5lCq^hYb`U*oi*5dZ)H diff --git a/LuminousSales/Business/Business/Interfaces/ISalesController.cs b/LuminousSales/Business/Business/Interfaces/ISalesController.cs index b0f726f..57898d3 100644 --- a/LuminousSales/Business/Business/Interfaces/ISalesController.cs +++ b/LuminousSales/Business/Business/Interfaces/ISalesController.cs @@ -9,8 +9,8 @@ namespace Business.Business.Sales ICollection GetAll(); T Get(int id); ICollection GetByTime(DateTime startTime, DateTime endTime); - void Add(int productId, double Amount); - void Add(string productName, double Amount); + void Add(int productId, double Amount, DateTime time); + void Add(string productName, double Amount, DateTime time); void Delete(int id); } } diff --git a/LuminousSales/Business/Business/Sales/DealController.cs b/LuminousSales/Business/Business/Sales/DealController.cs index a097c21..4b7766a 100644 --- a/LuminousSales/Business/Business/Sales/DealController.cs +++ b/LuminousSales/Business/Business/Sales/DealController.cs @@ -16,11 +16,11 @@ namespace Business.Business.Sales { this.currentUser = currentUser; } - public void Add(int productId, double Amount) + public void Add(int productId, double Amount, DateTime time) { if (Amount > 0) { - var deal = new Deal(currentUser.Id, productId, Amount); + var deal = new Deal(currentUser.Id, productId, Amount, time); context.Deal.Add(deal); context.SaveChanges(); } @@ -30,17 +30,16 @@ namespace Business.Business.Sales } } - public void Add(string productName, double Amount) + public void Add(string productName, double Amount, DateTime time) { if (Amount > 0) { productCtrl = new ProductController(currentUser); var productId = productCtrl.Get(productName).Id; - var deal = new Deal(currentUser.Id, productId, Amount); + var deal = new Deal(currentUser.Id, productId, Amount, time); context.Deal.Add(deal); context.SaveChanges(); } - else { throw new ArgumentException("Amount cannot be negative"); diff --git a/LuminousSales/Business/Business/Sales/StockController.cs b/LuminousSales/Business/Business/Sales/StockController.cs index 47cad2f..4cf2477 100644 --- a/LuminousSales/Business/Business/Sales/StockController.cs +++ b/LuminousSales/Business/Business/Sales/StockController.cs @@ -56,13 +56,15 @@ namespace Business.Business.Sales } } - public void Add(int productId, double Amount) + public void Add(int productId, double Amount, DateTime time) { if (currentUser.RoleId > 1) { if (Amount > 0) { - var stock = new Stock(currentUser.Id, productId, Amount); + var stock = new Stock(currentUser.Id, productId, Amount, time); + productCtrl = new ProductController(currentUser); + productCtrl.Get(productId).AmountInStock += Amount; context.Stock.Add(stock); context.SaveChanges(); } @@ -78,7 +80,7 @@ namespace Business.Business.Sales } } - public void Add(string productName, double Amount) + public void Add(string productName, double Amount, DateTime time) { if (currentUser.RoleId > 1) { @@ -86,7 +88,8 @@ namespace Business.Business.Sales { productCtrl = new ProductController(currentUser); var productId = productCtrl.Get(productName).Id; - var stock = new Stock(currentUser.Id, productId, Amount); + var stock = new Stock(currentUser.Id, productId, Amount, time); + productCtrl.Get(productId).AmountInStock += Amount; context.Stock.Add(stock); context.SaveChanges(); } diff --git a/LuminousSales/Display/Display.csproj b/LuminousSales/Display/Display.csproj index f39496e..e4f4d1c 100644 --- a/LuminousSales/Display/Display.csproj +++ b/LuminousSales/Display/Display.csproj @@ -1,4 +1,4 @@ - + Exe @@ -17,9 +17,4 @@ - - - - - diff --git a/LuminousSales/Display/InitialSetup/InitialSetup.cs b/LuminousSales/Display/InitialSetup.cs similarity index 60% rename from LuminousSales/Display/InitialSetup/InitialSetup.cs rename to LuminousSales/Display/InitialSetup.cs index 81f94f8..17c3ff5 100644 --- a/LuminousSales/Display/InitialSetup/InitialSetup.cs +++ b/LuminousSales/Display/InitialSetup.cs @@ -1,9 +1,10 @@ using Business.Business.UserManagment; +using Business.Business.UserManagment.Controllers; using System; using System.Collections.Generic; using System.Text; -namespace Display.InitialSetup +namespace Display { public class InitialSetup { @@ -11,9 +12,8 @@ namespace Display.InitialSetup { } - public string[] InitialUserInput() + public static void InitialUserInput(out string userName, out string password) { - string userName = "", password = ""; try { Console.Write("Enter username: "); @@ -23,13 +23,13 @@ namespace Display.InitialSetup } catch (Exception e) { + userName = string.Empty; + password = string.Empty; Console.WriteLine(e.Message); } - return new string[] { userName, password }; } - public void InitialRegistration() + public static void InitialRegistration(UserController uc) { - var uc = new UserController(); try { if (uc.CheckIfUserEverCreated()) @@ -38,7 +38,11 @@ namespace Display.InitialSetup } else { - uc.RegisterItem(InitialUserInput()[0], InitialUserInput()[1]); + RoleController rc = new RoleController(); + rc.CreateInitialRoles(); + string userName, password; + InitialUserInput(out userName, out password); + uc.RegisterItem(userName, password); } } catch (Exception e) diff --git a/LuminousSales/Display/Program.cs b/LuminousSales/Display/Program.cs index 7b7312b..4c24219 100644 --- a/LuminousSales/Display/Program.cs +++ b/LuminousSales/Display/Program.cs @@ -15,6 +15,7 @@ namespace Display try { var uc = new UserController(); + InitialSetup.InitialRegistration(uc); Console.Write("Enter password: "); User currentUser = uc.ValidatePassword(Console.ReadLine()); uc = new UserController(currentUser); @@ -33,6 +34,7 @@ namespace Display default: break; } + Console.WriteLine("Luminous Sales v0.1"); view.ActionHandle(); } catch (Exception e) diff --git a/LuminousSales/Display/Views/AdminView.cs b/LuminousSales/Display/Views/AdminView.cs index 3fbef4e..9944e25 100644 --- a/LuminousSales/Display/Views/AdminView.cs +++ b/LuminousSales/Display/Views/AdminView.cs @@ -17,32 +17,35 @@ namespace Display.Views public override void ShowAvaliableCommands() { base.ShowAvaliableCommands(); - Console.WriteLine("4. User Managment"); + Console.WriteLine("3. Administration"); } public override void ActionHandle() { - ShowAvaliableCommands(); - Console.Write("> "); try { - int input = int.Parse(Console.ReadLine()); - if (input == 0) + while (true) { - Environment.Exit(0); + ShowAvaliableCommands(); + Console.Write("> "); + int input = int.Parse(Console.ReadLine()); + if (input == 0) + { + Environment.Exit(0); + } + else if (input == 1) + { + SaleHandle(); + } + else if (input == 2) + { + ManageHandle(); + } + else if (input == 3) + { + AdminHandle(); + } + else Console.WriteLine("Invalid operation"); } - else if (input == 1) - { - SaleHandle(); - } - else if (input == 2) - { - ManageHandle(); - } - else if (input == 3) - { - AdminHandle(); - } - else Console.WriteLine("Invalid operation"); } catch (Exception e) { @@ -54,16 +57,22 @@ namespace Display.Views bool running = true; while (running) { + Console.WriteLine(); + Console.WriteLine("User Managment"); Console.WriteLine("1. GetAll"); Console.WriteLine("2. Get"); Console.WriteLine("3. GetByApproximateName"); - Console.WriteLine("4. RegisterItem"); - Console.WriteLine("5. UpdateRole"); - Console.WriteLine("6. UpdateName"); + Console.WriteLine("4. Register user"); + Console.WriteLine("5. Update Role"); + Console.WriteLine("6. Update username"); Console.WriteLine("7. UpdatePassword"); - Console.WriteLine("8. Delete"); - Console.WriteLine("9. Exit"); - Console.Write("Your choice: "); + Console.WriteLine("8. Delete User"); + Console.WriteLine(); + Console.WriteLine("Product Managment"); + Console.WriteLine("9. AddItem"); + Console.WriteLine(); + Console.WriteLine("10. Back"); + Console.Write("> "); try { int choice = int.Parse(Console.ReadLine()); @@ -94,6 +103,9 @@ namespace Display.Views Delete(); break; case 9: + AddItem(); + break; + case 10: running = false; break; default: @@ -286,5 +298,21 @@ namespace Display.Views Console.WriteLine(e.Message); } } + public void AddItem() + { + try + { + Console.WriteLine("Adding item to database..."); + Console.Write("Enter product name: "); + string product = Console.ReadLine(); + Console.Write("Enter price: "); + double price = double.Parse(Console.ReadLine()); + productctrl.AddItem(product, price); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } } } diff --git a/LuminousSales/Display/Views/BaseView.cs b/LuminousSales/Display/Views/BaseView.cs index 7b0f051..9382ce0 100644 --- a/LuminousSales/Display/Views/BaseView.cs +++ b/LuminousSales/Display/Views/BaseView.cs @@ -9,7 +9,7 @@ namespace Display.Views { public class BaseView { - ProductController productctrl; + internal ProductController productctrl; DealController dealctrl; public BaseView(User currentUser) { @@ -18,25 +18,30 @@ namespace Display.Views } public virtual void ShowAvaliableCommands() { + Console.WriteLine(); + Console.WriteLine("=== MAIN MENU ==="); Console.WriteLine("0. Exit"); Console.WriteLine("1. Sales"); } public virtual void ActionHandle() { - ShowAvaliableCommands(); - Console.Write("> "); try { - int input = int.Parse(Console.ReadLine()); - if (input == 0) + while (true) { - Environment.Exit(0); + ShowAvaliableCommands(); + Console.Write("> "); + int input = int.Parse(Console.ReadLine()); + if (input == 0) + { + Environment.Exit(0); + } + else if (input == 1) + { + SaleHandle(); + } + else Console.WriteLine("Invalid operation"); } - else if (input == 1) - { - SaleHandle(); - } - else Console.WriteLine("Invalid operation"); } catch (Exception e) { @@ -48,10 +53,12 @@ namespace Display.Views bool running = true; while (running) { + Console.WriteLine(); + Console.WriteLine("Deal Managment"); Console.WriteLine("1. Search"); Console.WriteLine("2. Sale"); - Console.WriteLine("3. Exit"); - Console.Write("Your choice: "); + Console.WriteLine("3. Back"); + Console.Write("> "); try { int choice = int.Parse(Console.ReadLine()); @@ -83,12 +90,12 @@ namespace Display.Views try { Console.Write("Search item: "); - string search = Console.ReadLine(); - ICollection productsFound = productctrl.GetByApproximateName(search).ToArray(); - foreach (var item in productsFound) - { - Console.WriteLine($"{item.Id} {item.Name} {item.Price} {item.AmountInStock}"); - } + string search = Console.ReadLine(); + ICollection productsFound = productctrl.GetByApproximateName(search).ToArray(); + foreach (var item in productsFound) + { + Console.WriteLine($"{item.Id} {item.Name} {item.Price} {item.AmountInStock}"); + } } catch (Exception e) { @@ -103,19 +110,19 @@ namespace Display.Views Console.Write("Type in item id or name: "); string itemInput = Console.ReadLine(); int itemId; - if (Int32.TryParse(itemInput, out itemId)) + if (int.TryParse(itemInput, out itemId)) { var productToAdd = productctrl.Get(itemId); Console.Write("Amount: "); double amount = double.Parse(Console.ReadLine()); - dealctrl.Add(itemId, amount); + dealctrl.Add(itemId, amount, DateTime.Now); } else { var productToAdd = productctrl.Get(itemInput); Console.Write("Amount: "); double amount = double.Parse(Console.ReadLine()); - dealctrl.Add(itemInput, amount); + dealctrl.Add(itemInput, amount, DateTime.Now); } } catch (Exception e) diff --git a/LuminousSales/Display/Views/ManagerView.cs b/LuminousSales/Display/Views/ManagerView.cs index d61fddc..7fe21c7 100644 --- a/LuminousSales/Display/Views/ManagerView.cs +++ b/LuminousSales/Display/Views/ManagerView.cs @@ -22,24 +22,27 @@ namespace Display.Views } public override void ActionHandle() { - ShowAvaliableCommands(); - Console.Write("> "); try { - int input = int.Parse(Console.ReadLine()); - if (input == 0) + while (true) { - Environment.Exit(0); + ShowAvaliableCommands(); + Console.Write("> "); + int input = int.Parse(Console.ReadLine()); + if (input == 0) + { + Environment.Exit(0); + } + else if (input == 1) + { + SaleHandle(); + } + else if (input == 2) + { + ManageHandle(); + } + else Console.WriteLine("Invalid operation"); } - else if (input == 1) - { - SaleHandle(); - } - else if (input == 2) - { - ManageHandle(); - } - else Console.WriteLine("Invalid operation"); } catch (Exception e) { @@ -51,13 +54,15 @@ namespace Display.Views bool running = true; while (running) { + Console.WriteLine(); + Console.WriteLine("Stock Managment"); Console.WriteLine("1. GetAll"); Console.WriteLine("2. Get"); Console.WriteLine("3. GetByTime"); Console.WriteLine("4. Add"); Console.WriteLine("5. Delete"); - Console.WriteLine("6. Exit"); - Console.Write("Your choice: "); + Console.WriteLine("6. Back"); + Console.Write("> "); try { int choice = int.Parse(Console.ReadLine()); @@ -97,11 +102,11 @@ namespace Display.Views { try { - Console.Write("Getting all stock..."); - + Console.WriteLine("Getting all stock..."); + Console.WriteLine("ID - Product ID - Amount - Time"); foreach (var item in stockctrl.GetAll()) { - Console.WriteLine($"{item.Id} {item.ProductId} {item.Amount} "); + Console.WriteLine($"{item.Id} - {item.ProductId} - {item.Amount} - {item.Time}"); } } catch (Exception e) @@ -119,7 +124,9 @@ namespace Display.Views { Console.Write("Enter stock id: "); int id = int.Parse(Console.ReadLine()); - stockctrl.Get(id); + var result = stockctrl.Get(id); + Console.WriteLine("ID - Product ID - Amount - Time"); + Console.WriteLine($"{result.Id} - {result.ProductId} - {result.Amount} - {result.Time}"); } catch (Exception e) @@ -135,11 +142,16 @@ namespace Display.Views try { Console.WriteLine("Getting stock by time..."); - Console.WriteLine("Enter start time: "); + Console.Write("Enter start time: "); DateTime startTime = DateTime.Parse(Console.ReadLine()); - Console.WriteLine("Enter end time: "); + Console.Write("Enter end time: "); DateTime endTime = DateTime.Parse(Console.ReadLine()); - stockctrl.GetByTime(startTime, endTime); + Console.WriteLine("ID - Product ID - Amount - Time"); + foreach (var item in stockctrl.GetByTime(startTime, endTime)) + { + Console.WriteLine($"{item.Id} - {item.ProductId} - {item.Amount} - {item.Time}"); + } + } catch (Exception e) { @@ -151,19 +163,19 @@ namespace Display.Views { try { - Console.WriteLine("Adding stock by product id..."); + Console.WriteLine("Adding stock by product id or name..."); Console.Write("Enter product ID or name: "); string product = Console.ReadLine(); - Console.Write("Enter stock amount:"); + Console.Write("Enter stock amount: "); double amount = double.Parse(Console.ReadLine()); bool result = int.TryParse(product, out int productId); if (result) { - stockctrl.Add(productId, amount); + stockctrl.Add(productId, amount, DateTime.Now); } else { - stockctrl.Add(product, amount); + stockctrl.Add(product, amount, DateTime.Now); } } catch (Exception e) @@ -178,9 +190,9 @@ namespace Display.Views try { Console.WriteLine("Deleting stock..."); - Console.Write("Enter deal id: "); + Console.Write("Enter stock id: "); int id = int.Parse(Console.ReadLine()); - dealctrl.Delete(id); + stockctrl.Delete(id); } catch (Exception e) { diff --git a/LuminousSales/Models/Models/Base/BaseSales.cs b/LuminousSales/Models/Models/Base/BaseSales.cs index 3fbf1f1..2e85fe6 100644 --- a/LuminousSales/Models/Models/Base/BaseSales.cs +++ b/LuminousSales/Models/Models/Base/BaseSales.cs @@ -13,11 +13,12 @@ namespace Data.Base { } - protected BaseSales(int UserId, int ProductId, double Amount) + protected BaseSales(int UserId, int ProductId, double Amount, DateTime Time) { this.UserId = UserId; this.ProductId = ProductId; this.Amount = Amount; + this.Time = Time; } [Key] public int Id { get; set; } diff --git a/LuminousSales/Models/Models/Deal.cs b/LuminousSales/Models/Models/Deal.cs index 7790ffe..e1404cd 100644 --- a/LuminousSales/Models/Models/Deal.cs +++ b/LuminousSales/Models/Models/Deal.cs @@ -1,4 +1,5 @@ using Data.Base; +using System; using System.Collections.Generic; namespace Models.Models @@ -6,6 +7,6 @@ namespace Models.Models public class Deal : BaseSales { public Deal() : base(){} - public Deal(int UserId, int ProductId, double Amount) : base(UserId, ProductId, Amount) { } + public Deal(int UserId, int ProductId, double Amount, DateTime Time) : base(UserId, ProductId, Amount, Time) { } } } \ No newline at end of file diff --git a/LuminousSales/Models/Models/Stock.cs b/LuminousSales/Models/Models/Stock.cs index 8161b30..ad969ab 100644 --- a/LuminousSales/Models/Models/Stock.cs +++ b/LuminousSales/Models/Models/Stock.cs @@ -9,6 +9,6 @@ namespace Models.Models public class Stock : BaseSales { public Stock() : base(){} - public Stock(int UserId, int ProductId, double Amount) : base(UserId, ProductId, Amount){} + public Stock(int UserId, int ProductId, double Amount, DateTime Time) : base(UserId, ProductId, Amount, Time){} } }