From 1adc2aac9ee5e98f78b83ef194a984c2ace6c09e Mon Sep 17 00:00:00 2001 From: thermalthrottle Date: Sat, 20 Mar 2021 18:30:12 +0200 Subject: [PATCH] Updates Comments --- .../Business/Business/Sales/DealController.cs | 113 ++++++++++++++++-- .../Business/Sales/ProductController.cs | 75 ++++++++---- .../Business/Sales/StockController.cs | 74 ++++++++++-- .../Controllers/RoleController.cs | 24 ++-- .../Controllers/UserController.cs | 15 +-- 5 files changed, 233 insertions(+), 68 deletions(-) diff --git a/LuminousSales/Business/Business/Sales/DealController.cs b/LuminousSales/Business/Business/Sales/DealController.cs index 1db2e94..74a523a 100644 --- a/LuminousSales/Business/Business/Sales/DealController.cs +++ b/LuminousSales/Business/Business/Sales/DealController.cs @@ -10,21 +10,91 @@ namespace Business.Business.Sales { public class DealController : ISalesController { - private LuminousContext context = new LuminousContext(); + private LuminousContext context; private User currentUser; - private ProductController productCtrl; + private ProductController productctrl; private UserController userctrl; + + /// + /// Constructor that accepts a user object + /// + /// + /// User object is used for role checking + /// + public DealController(User currentUser) { this.currentUser = currentUser; - this.productCtrl = new ProductController(currentUser); + this.context = new LuminousContext(); + this.productctrl = new ProductController(currentUser); this.userctrl = new UserController(currentUser); } + + /// + /// Constructor that accepts custom context, ProductController, UserController and a user object + /// + /// + /// Mainly Used for Unit Teststing + /// + /// + /// User object is used for role checking + /// + + public DealController(User currentUser, LuminousContext context, ProductController productctrl, UserController userctrl) + { + this.currentUser = currentUser; + this.context = context; + this.productctrl = productctrl; + this.userctrl = userctrl; + } + + /// + /// Gets All Deals + /// + /// + /// Requires no special roles. + /// + /// + /// Returns a ICollection of all Deals. + /// public ICollection GetAll() { return context.Deal.ToList(); } + + /// + /// Searches a deal by given Id. + /// + /// + /// Requires Manager role or better. + /// + /// + /// Returns an object of the role with the given Id. + /// + + public Deal Get(int id) + { + if (currentUser != null || currentUser.RoleId > 1) + { + return context.Deal.Find(id); + } + else + { + throw new ArgumentException("Insufficient Roles"); + } + } + + /// + /// Gets deals between time periods. + /// + /// + /// Requires Manager role or better. + /// + /// + /// Returns a collection of all the deal in the criteria. + /// + public ICollection GetByTime(DateTime startTime, DateTime endTime) { if (currentUser.RoleId > 1) @@ -37,6 +107,17 @@ namespace Business.Business.Sales } } + /// + /// Gets deals made by certain user. + /// + /// + /// Accepts user id for getting the user. + /// Requires Manager role or better. + /// + /// + /// Returns an Collection of all the deals in the criteria. + /// + public ICollection GetByUser(int id) { if (currentUser != null || currentUser.RoleId > 1) @@ -57,6 +138,17 @@ namespace Business.Business.Sales } } + /// + /// Gets deals made by certain user. + /// + /// + /// Accepts username for getting the user. + /// Requires Manager role or better. + /// + /// + /// Returns an Collection of all the deals in the criteria. + /// + public ICollection GetByUser(string username) { if (currentUser != null || currentUser.RoleId > 1) @@ -82,7 +174,7 @@ namespace Business.Business.Sales if (Amount > 0) { var deal = new Deal(currentUser.Id, productId, Amount, time); - productCtrl.RemoveAmount(productId, Amount); + productctrl.RemoveAmount(productId, Amount); context.Deal.Add(deal); context.SaveChanges(); } @@ -91,20 +183,15 @@ namespace Business.Business.Sales throw new ArgumentException("Amount cannot be negative"); } } - - public Deal Get(int id) - { - return context.Deal.Find(id); - } public void Add(string productName, double Amount, DateTime time) { if (Amount > 0) { - productCtrl = new ProductController(currentUser); - var productId = productCtrl.Get(productName).Id; + productctrl = new ProductController(currentUser); + var productId = productctrl.Get(productName).Id; var deal = new Deal(currentUser.Id, productId, Amount, time); - productCtrl.RemoveAmount(productId, Amount); + productctrl.RemoveAmount(productId, Amount); context.Deal.Add(deal); context.SaveChanges(); } @@ -121,7 +208,7 @@ namespace Business.Business.Sales var deal = Get(id); if (deal != null) { - productCtrl.AddAmount(deal.ProductId, deal.Amount); + productctrl.AddAmount(deal.ProductId, deal.Amount); context.Deal.Remove(deal); context.SaveChanges(); } diff --git a/LuminousSales/Business/Business/Sales/ProductController.cs b/LuminousSales/Business/Business/Sales/ProductController.cs index c2e7ed3..a05595e 100644 --- a/LuminousSales/Business/Business/Sales/ProductController.cs +++ b/LuminousSales/Business/Business/Sales/ProductController.cs @@ -31,23 +31,25 @@ namespace Business.Business.Sales /// /// /// Custom context is mainly used for Unit Testing + /// + /// /// User object is used for role checking /// - public ProductController(LuminousContext context, User currenUser) + public ProductController(User currenUser, LuminousContext context) { this.currentUser = currenUser; this.context = context; } /// - /// Gets All Roles + /// Gets All Products /// /// /// Requires no special roles. /// /// - /// Returns a ICollection of all roles. + /// Returns a ICollection of all products. /// public ICollection GetAll() @@ -56,7 +58,7 @@ namespace Business.Business.Sales } /// - /// Searches the role by given Id. + /// Searches a product by given Id. /// /// /// Requires no special roles. @@ -79,7 +81,7 @@ namespace Business.Business.Sales } /// - /// Searches the role by given name + /// Searches a product by given name /// /// /// Requires no special roles. @@ -102,7 +104,7 @@ namespace Business.Business.Sales } /// - /// Searches the role by a given substring + /// Searches a product by a given substring /// /// /// Requires no special roles. @@ -128,9 +130,10 @@ namespace Business.Business.Sales /// Adds an product in the database /// /// + /// Requires Admin role. + /// + /// /// Accepts an item name and price. - /// - /// Requires no special roles /// public void AddItem(string name, double price) @@ -165,9 +168,10 @@ namespace Business.Business.Sales /// Updates the name of the given product /// /// + /// Requires Admin role. + /// + /// /// Accepts the id for getting the product. - /// - /// Requires Admin role /// public void UpdateName(int id, string newName) @@ -202,9 +206,10 @@ namespace Business.Business.Sales /// Updates the name of the given product /// /// + /// Requires Admin role. + /// + /// /// Accepts the current name for getting the product. - /// - /// Requires Admin role /// public void UpdateName(string oldName, string newName) @@ -239,9 +244,10 @@ namespace Business.Business.Sales /// Updates the price of the given product /// /// + /// Requires Admin role. + /// + /// /// Accepts the id for getting the product. - /// - /// Requires Admin role /// public void UpdatePrice(int id, double price) @@ -273,12 +279,13 @@ namespace Business.Business.Sales } /// - /// Updates the price of the given product + /// Updates the price of the given product. /// /// + /// Requires Admin role. + /// + /// /// Accepts the name for getting the product. - /// - /// Requires Admin role /// public void UpdatePrice(string name, double price) @@ -309,6 +316,15 @@ namespace Business.Business.Sales } } + /// + /// Adds to the amount of a given product. + /// + /// + /// Requires no special roles. + /// + /// + /// Accepts the product id for getting the product and amount to add + /// public void AddAmount(int productId ,double Amount) { @@ -330,6 +346,17 @@ namespace Business.Business.Sales throw new ArgumentException("Insufficient Role!"); } } + + /// + /// Subtracts to the amount of a given product. + /// + /// + /// Requires no special roles. + /// + /// + /// Accepts the product id for getting the product and amount to substract + /// + public void RemoveAmount(int productId, double Amount) { if (currentUser.RoleId > 1) @@ -352,12 +379,13 @@ namespace Business.Business.Sales } /// - /// Deletes the given product + /// Deletes the given product. /// /// - /// Accepts an product for getting the product - /// - /// Requires Admin role + /// Requires Admin Role + /// + /// + /// Accepts an product for getting the product. /// @@ -386,10 +414,11 @@ namespace Business.Business.Sales /// Deletes the given product /// /// - /// Accepts an name for getting the product - /// /// Requires Admin role /// + /// + /// Accepts an name for getting the product + /// public void Delete(string name) { diff --git a/LuminousSales/Business/Business/Sales/StockController.cs b/LuminousSales/Business/Business/Sales/StockController.cs index d5fb9a0..678b296 100644 --- a/LuminousSales/Business/Business/Sales/StockController.cs +++ b/LuminousSales/Business/Business/Sales/StockController.cs @@ -11,24 +11,54 @@ namespace Business.Business.Sales { public class StockController : ISalesController { - private LuminousContext context = new LuminousContext(); + private LuminousContext context; private User currentUser; - private ProductController productCtrl; + private ProductController productctrl; private UserController userctrl; + /// + /// Constructor that accepts a user object + /// + /// + /// User object is used for role checking + /// + public StockController(User currentUser) { this.currentUser = currentUser; - this.productCtrl = new ProductController(currentUser); + this.context = new LuminousContext(); + this.productctrl = new ProductController(currentUser); this.userctrl = new UserController(currentUser); } - public StockController(User currentUser, ProductController productctrl, UserController userctrl) + /// + /// Constructor that accepts custom context, ProductController, UserController and a user object + /// + /// + /// Mainly Used for Unit Teststing + /// + /// + /// User object is used for role checking + /// + + public StockController(User currentUser, LuminousContext context ,ProductController productctrl, UserController userctrl) { this.currentUser = currentUser; - this.productCtrl = new ProductController(currentUser); - this.userctrl = new UserController(currentUser); + this.context = context; + this.productctrl = productctrl; + this.userctrl = userctrl; } + + /// + /// Gets All Stocks + /// + /// + /// Requires no special roles. + /// + /// + /// Returns a ICollection of all Deals. + /// + public ICollection GetAll() { if (currentUser != null || currentUser.RoleId > 1) @@ -42,6 +72,16 @@ namespace Business.Business.Sales } + /// + /// Searches a stocks session by given Id. + /// + /// + /// Requires Manager role or better. + /// + /// + /// Returns an object of the role with the given Id. + /// + public Stock Get(int id) { if (currentUser != null || currentUser.RoleId > 1) @@ -50,10 +90,20 @@ namespace Business.Business.Sales } else { - throw new ArgumentException("Cannot get stock!"); + throw new ArgumentException("Insufficient Roles"); } } + /// + /// Gets stocks between time periods. + /// + /// + /// Requires Manager role or better. + /// + /// + /// Returns a collection of all the stocks in the criteria. + /// + public ICollection GetByTime(DateTime startTime, DateTime endTime) { if (currentUser != null || currentUser.RoleId > 1) @@ -113,7 +163,7 @@ namespace Business.Business.Sales if (Amount > 0) { var stock = new Stock(currentUser.Id, productId, Amount, time); - productCtrl.AddAmount(productId, Amount); + productctrl.AddAmount(productId, Amount); context.Stock.Add(stock); context.SaveChanges(); } @@ -135,10 +185,10 @@ namespace Business.Business.Sales { if (Amount > 0) { - productCtrl = new ProductController(currentUser); - var productId = productCtrl.Get(productName).Id; + productctrl = new ProductController(currentUser); + var productId = productctrl.Get(productName).Id; var stock = new Stock(currentUser.Id, productId, Amount, time); - productCtrl.AddAmount(productId, Amount); + productctrl.AddAmount(productId, Amount); context.Stock.Add(stock); context.SaveChanges(); } @@ -162,7 +212,7 @@ namespace Business.Business.Sales var stock = Get(id); if (stock != null) { - productCtrl.RemoveAmount(stock.ProductId, stock.Amount); + productctrl.RemoveAmount(stock.ProductId, stock.Amount); context.Stock.Remove(stock); context.SaveChanges(); } diff --git a/LuminousSales/Business/Business/UserManagment/Controllers/RoleController.cs b/LuminousSales/Business/Business/UserManagment/Controllers/RoleController.cs index 1b5d9a3..4a306af 100644 --- a/LuminousSales/Business/Business/UserManagment/Controllers/RoleController.cs +++ b/LuminousSales/Business/Business/UserManagment/Controllers/RoleController.cs @@ -14,10 +14,10 @@ namespace Business.Business.UserManagment.Controllers private User currentUser; /// - /// Empty Constructor + /// Empty Constructor. /// /// - /// Used for Initialiation of the roles in the database + /// Used for Initialiation of the roles in the database. /// public RoleController() @@ -31,10 +31,10 @@ namespace Business.Business.UserManagment.Controllers } /// - /// Constructor that accepts a user object + /// Constructor that accepts a user object. /// /// - /// User object is used for role checking + /// User object is used for role checking. /// public RoleController(User currentUser) @@ -44,13 +44,15 @@ namespace Business.Business.UserManagment.Controllers } /// - /// Constructor that accepts custom context and a user object + /// Constructor that accepts custom context and a user object. /// /// - /// Custom context is mainly used for Unit Testing - /// User object is used for role checking + /// Custom context is mainly used for Unit Testing. /// - + /// + /// User object is used for role checking. + /// + public RoleController(User currentUser, LuminousContext context) { this.context = context; @@ -58,13 +60,13 @@ namespace Business.Business.UserManagment.Controllers } /// - /// Creates the roles + /// Creates the roles. /// /// /// Requires no special roles. Not even an registered user. /// /// - /// Almost every method of each class checks if the user has suffficient roles for the task + /// Almost every method of each class checks if the user has suffficient roles for the task. /// public void CreateInitialRoles() @@ -83,7 +85,7 @@ namespace Business.Business.UserManagment.Controllers /// Requires Admin role. /// /// - /// Returns a ICollection of all roles + /// Returns a ICollection of all roles. /// public ICollection GetAll() diff --git a/LuminousSales/Business/Business/UserManagment/Controllers/UserController.cs b/LuminousSales/Business/Business/UserManagment/Controllers/UserController.cs index f57e2ff..14dbaad 100644 --- a/LuminousSales/Business/Business/UserManagment/Controllers/UserController.cs +++ b/LuminousSales/Business/Business/UserManagment/Controllers/UserController.cs @@ -39,21 +39,18 @@ namespace Business.Business.UserManagment this.rolectrl = new RoleController(currentUser); } - /// - /// Constructor that accepts custom context and a user object + + // + /// Constructor that accepts custom context, rolectrl and a user object /// /// /// Custom context is mainly used for Unit Testing + /// + /// + /// Custom context is mainly used for Unit Testing /// User object is used for role checking /// - public UserController(User currentUser, LuminousContext context) - { - this.currentUser = currentUser; - this.context = context; - this.rolectrl = new RoleController(currentUser); - } - public UserController(User currentUser, LuminousContext context, RoleController rolectrl) { this.currentUser = currentUser;