From 541b001d31f72df05a1848249e8b96b8aa27a534 Mon Sep 17 00:00:00 2001 From: thermalthrottle Date: Thu, 18 Mar 2021 21:25:10 +0200 Subject: [PATCH] Product Context --- .../Business/Interfaces/ISalesController.cs | 16 ++++ .../Business/Interfaces/IStockController.cs | 19 ----- .../Business/Sales/ProductController.cs | 78 +++++++++++++++++++ .../Controllers/UserController.cs | 6 +- 4 files changed, 98 insertions(+), 21 deletions(-) create mode 100644 LuminousSales/Business/Business/Interfaces/ISalesController.cs delete mode 100644 LuminousSales/Business/Business/Interfaces/IStockController.cs create mode 100644 LuminousSales/Business/Business/Sales/ProductController.cs diff --git a/LuminousSales/Business/Business/Interfaces/ISalesController.cs b/LuminousSales/Business/Business/Interfaces/ISalesController.cs new file mode 100644 index 0000000..1b6e2fe --- /dev/null +++ b/LuminousSales/Business/Business/Interfaces/ISalesController.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Business.Business.Sales +{ + interface ISalesController + { + ICollection GetAll(); + T Get(int id); + ICollection GetByTime(byte[] startPeriod, byte[] endPeriod); + void Add(int productId, double Amount); + void Add(string productName, double Amount); + void Delete(int id); + } +} diff --git a/LuminousSales/Business/Business/Interfaces/IStockController.cs b/LuminousSales/Business/Business/Interfaces/IStockController.cs deleted file mode 100644 index 809b18d..0000000 --- a/LuminousSales/Business/Business/Interfaces/IStockController.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Business.Business.Sales -{ - interface IStockController - { - ICollection GetAll(); - T GetById(int id); - T GetByName(string name); - void AddProduct(T product); - void LoadProductByName(T product); - void LoadProductById(int id); - void Sale(int id); - void Sale(string name); - - } -} diff --git a/LuminousSales/Business/Business/Sales/ProductController.cs b/LuminousSales/Business/Business/Sales/ProductController.cs new file mode 100644 index 0000000..0cb59cd --- /dev/null +++ b/LuminousSales/Business/Business/Sales/ProductController.cs @@ -0,0 +1,78 @@ +using Business.Business.UserManagment; +using Models; +using Models.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Business.Business.Sales +{ + class ProductController : IController + { + private LuminousContext context = new LuminousContext(); + private User currentUser; + public ProductController(User currenUser) + { + this.currentUser = currenUser; + } + public ICollection GetAll() + { + return context.Product.ToList(); + } + public Product Get(int id) + { + return context.Product.Find(id); + } + public Product Get(string name) + { + return context.Product.FirstOrDefault(p => p.Name == name); + } + public ICollection GetByApproximateName(string name) + { + return context.Product.Where(u => u.Name.Contains(name)).ToList(); + } + public void AddItem(string name, double price) + { + var product = new Product(name, price); + context.Product.Add(product); + } + public void UpdateName(int id, string newName) + { + if (currentUser.RoleId > 1) + { + var product = Get(id); + if (product != null) + { + + } + else + { + + } + } + } + public void UpdateName(string oldName, string newName) + { + throw new NotImplementedException(); + } + public void UpdatePrice(int id) + { + + } + public void UpdatePrice(string name) + { + + } + public void Delete(int id) + { + throw new NotImplementedException(); + } + + public void Delete(string name) + { + throw new NotImplementedException(); + } + + } +} diff --git a/LuminousSales/Business/Business/UserManagment/Controllers/UserController.cs b/LuminousSales/Business/Business/UserManagment/Controllers/UserController.cs index 8b82427..b4da3be 100644 --- a/LuminousSales/Business/Business/UserManagment/Controllers/UserController.cs +++ b/LuminousSales/Business/Business/UserManagment/Controllers/UserController.cs @@ -30,12 +30,14 @@ namespace Business.Business.UserManagment { return context.User.FirstOrDefault(u => u.Name == name); } - public void ValidatePassword(string password) + public User ValidatePassword(string password) { - if (!GetAll().Where(u => u.Password == password).Any()) + var user = context.User.FirstOrDefault(); + if (user == null) { throw new ArgumentException("Invalid User!"); } + return user; } public ICollection GetByApproximateName(string name) {