Handles even selling
This commit is contained in:
@ -33,6 +33,21 @@ namespace StockDAL
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
public void UpdateActualForSell(int id, int sellAmount, decimal sellPrice, DateTime sellDate)
|
||||
{
|
||||
using var context = new StockContext();
|
||||
var entity = (from stk in context.Stocks
|
||||
where stk.Id == id
|
||||
select stk).FirstOrDefault();
|
||||
var rest = entity.ActAmount - sellAmount;
|
||||
entity.ActAmount = rest < 0 ? 0 : rest;
|
||||
entity.SoldDate = DateTime.Today;
|
||||
entity.SoldValue = sellAmount * sellPrice;
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<StockMember> GetAllStocks()
|
||||
{
|
||||
using var context = new StockContext();
|
||||
@ -44,7 +59,7 @@ namespace StockDAL
|
||||
{
|
||||
using var context = new StockContext();
|
||||
var output = (from stk in context.Stocks
|
||||
where stk.SoldDate == null || stk.ActValue > 0
|
||||
where stk.SoldDate == null || stk.ActAmount > 0
|
||||
select stk).ToList();
|
||||
return output;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user