From 93ec3b009a4ffd634654068ebc77a21513661e81 Mon Sep 17 00:00:00 2001 From: thermalthrottle Date: Sat, 20 Mar 2021 22:03:55 +0200 Subject: [PATCH] Controllers updates --- .../Business/Sales/ProductController.cs | 52 ++++++------------- 1 file changed, 15 insertions(+), 37 deletions(-) diff --git a/LuminousSales/Business/Business/Sales/ProductController.cs b/LuminousSales/Business/Business/Sales/ProductController.cs index 0b01c1a..370abef 100644 --- a/LuminousSales/Business/Business/Sales/ProductController.cs +++ b/LuminousSales/Business/Business/Sales/ProductController.cs @@ -328,22 +328,15 @@ namespace Business.Business.Sales public void AddAmount(int productId ,double Amount) { - if (currentUser.RoleId > 1) + var product = Get(productId); + if (product != null) { - var product = Get(productId); - if (product != null) - { - product.AmountInStock += Amount; - context.SaveChanges(); - } - else - { - throw new ArgumentException("Product id not valid!"); - } + product.AmountInStock += Amount; + context.SaveChanges(); } else { - throw new ArgumentException("Insufficient Role!"); + throw new ArgumentException("Product id not valid!"); } } @@ -359,25 +352,17 @@ namespace Business.Business.Sales public void AddAmount(string productName, double Amount) { - if (currentUser.RoleId > 1) + var product = Get(productName); + if (product != null) { - var product = Get(productName); - if (product != null) - { - product.AmountInStock += Amount; - context.SaveChanges(); - } - else - { - throw new ArgumentException("Product name not valid!"); - } + product.AmountInStock += Amount; + context.SaveChanges(); } else { - throw new ArgumentException("Insufficient Role!"); + throw new ArgumentException("Product name not valid!"); } } - /// /// Subtracts to the amount of a given product. /// @@ -414,22 +399,15 @@ namespace Business.Business.Sales public void RemoveAmount(string productName, double Amount) { - if (currentUser.RoleId > 1) + var product = Get(productName); + if (product != null) { - var product = Get(productName); - if (product != null) - { - product.AmountInStock -= Amount; - context.SaveChanges(); - } - else - { - throw new ArgumentException("Product id not valid!"); - } + product.AmountInStock -= Amount; + context.SaveChanges(); } else { - throw new ArgumentException("Insufficient Role!"); + throw new ArgumentException("Product id not valid!"); } }