Updates Comments
This commit is contained in:
@@ -10,21 +10,91 @@ namespace Business.Business.Sales
|
||||
{
|
||||
public class DealController : ISalesController<Deal>
|
||||
{
|
||||
private LuminousContext context = new LuminousContext();
|
||||
private LuminousContext context;
|
||||
private User currentUser;
|
||||
private ProductController productCtrl;
|
||||
private ProductController productctrl;
|
||||
private UserController userctrl;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that accepts a user object
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// User object is used for role checking
|
||||
/// </remarks>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that accepts custom context, ProductController, UserController and a user object
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Mainly Used for Unit Teststing
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// User object is used for role checking
|
||||
/// </remarks>
|
||||
|
||||
public DealController(User currentUser, LuminousContext context, ProductController productctrl, UserController userctrl)
|
||||
{
|
||||
this.currentUser = currentUser;
|
||||
this.context = context;
|
||||
this.productctrl = productctrl;
|
||||
this.userctrl = userctrl;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets All Deals
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires no special roles.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// Returns a ICollection of all Deals.
|
||||
/// </returns>
|
||||
|
||||
public ICollection<Deal> GetAll()
|
||||
{
|
||||
return context.Deal.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches a deal by given Id.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires Manager role or better.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// Returns an object of the role with the given Id.
|
||||
/// </returns>
|
||||
|
||||
public Deal Get(int id)
|
||||
{
|
||||
if (currentUser != null || currentUser.RoleId > 1)
|
||||
{
|
||||
return context.Deal.Find(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Insufficient Roles");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets deals between time periods.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires Manager role or better.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// Returns a collection of all the deal in the criteria.
|
||||
/// </returns>
|
||||
|
||||
public ICollection<Deal> GetByTime(DateTime startTime, DateTime endTime)
|
||||
{
|
||||
if (currentUser.RoleId > 1)
|
||||
@@ -37,6 +107,17 @@ namespace Business.Business.Sales
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets deals made by certain user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Accepts user id for getting the user.
|
||||
/// Requires Manager role or better.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// Returns an Collection of all the deals in the criteria.
|
||||
/// </returns>
|
||||
|
||||
public ICollection<Deal> GetByUser(int id)
|
||||
{
|
||||
if (currentUser != null || currentUser.RoleId > 1)
|
||||
@@ -57,6 +138,17 @@ namespace Business.Business.Sales
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets deals made by certain user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Accepts username for getting the user.
|
||||
/// Requires Manager role or better.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// Returns an Collection of all the deals in the criteria.
|
||||
/// </returns>
|
||||
|
||||
public ICollection<Deal> 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();
|
||||
}
|
||||
|
@@ -31,23 +31,25 @@ namespace Business.Business.Sales
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Custom context is mainly used for Unit Testing
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// User object is used for role checking
|
||||
/// </remarks>
|
||||
|
||||
public ProductController(LuminousContext context, User currenUser)
|
||||
public ProductController(User currenUser, LuminousContext context)
|
||||
{
|
||||
this.currentUser = currenUser;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets All Roles
|
||||
/// Gets All Products
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires no special roles.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// Returns a ICollection of all roles.
|
||||
/// Returns a ICollection of all products.
|
||||
/// </returns>
|
||||
|
||||
public ICollection<Product> GetAll()
|
||||
@@ -56,7 +58,7 @@ namespace Business.Business.Sales
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches the role by given Id.
|
||||
/// Searches a product by given Id.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires no special roles.
|
||||
@@ -79,7 +81,7 @@ namespace Business.Business.Sales
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches the role by given name
|
||||
/// Searches a product by given name
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires no special roles.
|
||||
@@ -102,7 +104,7 @@ namespace Business.Business.Sales
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches the role by a given substring
|
||||
/// Searches a product by a given substring
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires no special roles.
|
||||
@@ -128,9 +130,10 @@ namespace Business.Business.Sales
|
||||
/// Adds an product in the database
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires Admin role.
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// Accepts an item name and price.
|
||||
///
|
||||
/// Requires no special roles
|
||||
/// </remarks>
|
||||
|
||||
public void AddItem(string name, double price)
|
||||
@@ -165,9 +168,10 @@ namespace Business.Business.Sales
|
||||
/// Updates the name of the given product
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires Admin role.
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// Accepts the id for getting the product.
|
||||
///
|
||||
/// Requires Admin role
|
||||
/// </remarks>
|
||||
|
||||
public void UpdateName(int id, string newName)
|
||||
@@ -202,9 +206,10 @@ namespace Business.Business.Sales
|
||||
/// Updates the name of the given product
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires Admin role.
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// Accepts the current name for getting the product.
|
||||
///
|
||||
/// Requires Admin role
|
||||
/// </remarks>
|
||||
|
||||
public void UpdateName(string oldName, string newName)
|
||||
@@ -239,9 +244,10 @@ namespace Business.Business.Sales
|
||||
/// Updates the price of the given product
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires Admin role.
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// Accepts the id for getting the product.
|
||||
///
|
||||
/// Requires Admin role
|
||||
/// </remarks>
|
||||
|
||||
public void UpdatePrice(int id, double price)
|
||||
@@ -273,12 +279,13 @@ namespace Business.Business.Sales
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the price of the given product
|
||||
/// Updates the price of the given product.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires Admin role.
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// Accepts the name for getting the product.
|
||||
///
|
||||
/// Requires Admin role
|
||||
/// </remarks>
|
||||
|
||||
public void UpdatePrice(string name, double price)
|
||||
@@ -309,6 +316,15 @@ namespace Business.Business.Sales
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds to the amount of a given product.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires no special roles.
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// Accepts the product id for getting the product and amount to add
|
||||
/// </remarks>
|
||||
|
||||
public void AddAmount(int productId ,double Amount)
|
||||
{
|
||||
@@ -330,6 +346,17 @@ namespace Business.Business.Sales
|
||||
throw new ArgumentException("Insufficient Role!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts to the amount of a given product.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires no special roles.
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// Accepts the product id for getting the product and amount to substract
|
||||
/// </remarks>
|
||||
|
||||
public void RemoveAmount(int productId, double Amount)
|
||||
{
|
||||
if (currentUser.RoleId > 1)
|
||||
@@ -352,12 +379,13 @@ namespace Business.Business.Sales
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the given product
|
||||
/// Deletes the given product.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Accepts an product for getting the product
|
||||
///
|
||||
/// Requires Admin role
|
||||
/// Requires Admin Role
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// Accepts an product for getting the product.
|
||||
/// </remarks>
|
||||
|
||||
|
||||
@@ -386,10 +414,11 @@ namespace Business.Business.Sales
|
||||
/// Deletes the given product
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Accepts an name for getting the product
|
||||
///
|
||||
/// Requires Admin role
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// Accepts an name for getting the product
|
||||
/// </remarks>
|
||||
|
||||
public void Delete(string name)
|
||||
{
|
||||
|
@@ -11,24 +11,54 @@ namespace Business.Business.Sales
|
||||
{
|
||||
public class StockController : ISalesController<Stock>
|
||||
{
|
||||
private LuminousContext context = new LuminousContext();
|
||||
private LuminousContext context;
|
||||
private User currentUser;
|
||||
private ProductController productCtrl;
|
||||
private ProductController productctrl;
|
||||
private UserController userctrl;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that accepts a user object
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// User object is used for role checking
|
||||
/// </remarks>
|
||||
|
||||
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)
|
||||
/// <summary>
|
||||
/// Constructor that accepts custom context, ProductController, UserController and a user object
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Mainly Used for Unit Teststing
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// User object is used for role checking
|
||||
/// </remarks>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets All Stocks
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires no special roles.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// Returns a ICollection of all Deals.
|
||||
/// </returns>
|
||||
|
||||
public ICollection<Stock> GetAll()
|
||||
{
|
||||
if (currentUser != null || currentUser.RoleId > 1)
|
||||
@@ -42,6 +72,16 @@ namespace Business.Business.Sales
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches a stocks session by given Id.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires Manager role or better.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// Returns an object of the role with the given Id.
|
||||
/// </returns>
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets stocks between time periods.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires Manager role or better.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// Returns a collection of all the stocks in the criteria.
|
||||
/// </returns>
|
||||
|
||||
public ICollection<Stock> 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();
|
||||
}
|
||||
|
@@ -14,10 +14,10 @@ namespace Business.Business.UserManagment.Controllers
|
||||
private User currentUser;
|
||||
|
||||
/// <summary>
|
||||
/// Empty Constructor
|
||||
/// Empty Constructor.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Used for Initialiation of the roles in the database
|
||||
/// Used for Initialiation of the roles in the database.
|
||||
/// </remarks>
|
||||
|
||||
public RoleController()
|
||||
@@ -31,10 +31,10 @@ namespace Business.Business.UserManagment.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that accepts a user object
|
||||
/// Constructor that accepts a user object.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// User object is used for role checking
|
||||
/// User object is used for role checking.
|
||||
/// </remarks>
|
||||
|
||||
public RoleController(User currentUser)
|
||||
@@ -44,13 +44,15 @@ namespace Business.Business.UserManagment.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that accepts custom context and a user object
|
||||
/// Constructor that accepts custom context and a user object.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Custom context is mainly used for Unit Testing
|
||||
/// User object is used for role checking
|
||||
/// Custom context is mainly used for Unit Testing.
|
||||
/// </remarks>
|
||||
|
||||
/// <remarks>
|
||||
/// User object is used for role checking.
|
||||
/// </remarks>
|
||||
|
||||
public RoleController(User currentUser, LuminousContext context)
|
||||
{
|
||||
this.context = context;
|
||||
@@ -58,13 +60,13 @@ namespace Business.Business.UserManagment.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the roles
|
||||
/// Creates the roles.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires no special roles. Not even an registered user.
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// 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.
|
||||
/// </remarks>
|
||||
|
||||
public void CreateInitialRoles()
|
||||
@@ -83,7 +85,7 @@ namespace Business.Business.UserManagment.Controllers
|
||||
/// Requires Admin role.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// Returns a ICollection of all roles
|
||||
/// Returns a ICollection of all roles.
|
||||
/// </returns>
|
||||
|
||||
public ICollection<Role> GetAll()
|
||||
|
@@ -39,21 +39,18 @@ namespace Business.Business.UserManagment
|
||||
this.rolectrl = new RoleController(currentUser);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that accepts custom context and a user object
|
||||
|
||||
// <summary>
|
||||
/// Constructor that accepts custom context, rolectrl and a user object
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Custom context is mainly used for Unit Testing
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// Custom context is mainly used for Unit Testing
|
||||
/// User object is used for role checking
|
||||
/// </remarks>
|
||||
|
||||
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;
|
||||
|
Reference in New Issue
Block a user