Handles even selling

This commit is contained in:
2021-03-04 10:38:47 +01:00
parent 3959943607
commit 2841ada2cf
4 changed files with 90 additions and 7 deletions

View File

@ -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;
}