Latest sold info implemented

This commit is contained in:
2021-05-14 00:10:55 +02:00
parent f0b3b3d264
commit 27db60bbb2
5 changed files with 110 additions and 6 deletions

View File

@ -43,10 +43,27 @@ namespace StockDAL
entity.ActAmount = rest < 0 ? 0 : rest;
entity.SoldDate = DateTime.Today;
entity.SoldValue = sellAmount * sellPrice;
entity.SoldStockPrice = sellPrice;
context.SaveChanges();
}
public LatestSoldStock LatestSell(string StockName)
{
using var context = new StockContext();
var result = (from stk in context.Stocks
where stk.StockId == StockName
&& stk.SoldDate == (from stk2 in context.Stocks
where stk2.StockId == stk.StockId
select stk2.SoldDate).Max()
select new LatestSoldStock
{
SoldStockPrice = stk.SoldStockPrice,
LatestSoldDate = stk.SoldDate
}).FirstOrDefault();
return result;
}
public IEnumerable<StockMember> GetAllStocks()
{
@ -100,7 +117,8 @@ namespace StockDAL
SoldValue = o.SoldValue,
SoldDate = o.SoldDate,
Comment = o.Comment,
PostAmount = o.PostAmount
PostAmount = o.PostAmount,
SoldStockPrice = o.SoldStockPrice
}).ToList();
context.Stocks.AddRange(insertStocks);
context.SaveChanges();