public void stockDeduct(double quantity, int?stockid) { Sprint_3_V1Context db = new Sprint_3_V1Context(); var stockGet = (from x in db.Stocks where x.StockID == stockid select x.CurQuantity).Single(); Stock stock = db.Stocks.Find(stockid); stock.CurQuantity = Convert.ToDouble(stockGet) - quantity; db.Entry(stock).State = EntityState.Modified; db.SaveChanges(); }
public List <StockViewModel> sortValue(string sort) { Sprint_3_V1Context db = new Sprint_3_V1Context(); List <StockViewModel> searchStockList = new List <StockViewModel>(); if (sort != null) { if (sort == "Name Ascending") { var mergedList = (from c in db.CropInfoes join x in db.Stocks on c.CropID equals x.CropID join y in db.StocksImages on x.StockID equals y.StockID orderby c.Name ascending select new { x.StockID, c.CropID, c.Name, x.CurQuantity, x.Expiery, x.Price, y.StockImage }).ToList(); if (mergedList.Count() > 0) { foreach (var item in mergedList) { StockViewModel stk = new StockViewModel(); stk.StockID = item.StockID; stk.CropID = item.CropID; stk.CropName = item.Name; stk.CurQuantity = item.CurQuantity; stk.Expiery = item.Expiery; stk.StockImage = item.StockImage; stk.Price = item.Price; searchStockList.Add(stk); } } } else if (sort == "Name Descending") { var mergedList = (from c in db.CropInfoes join x in db.Stocks on c.CropID equals x.CropID join y in db.StocksImages on x.StockID equals y.StockID orderby c.Name descending select new { x.StockID, c.CropID, c.Name, x.CurQuantity, x.Expiery, x.Price, y.StockImage }).ToList(); if (mergedList.Count() > 0) { foreach (var item in mergedList) { StockViewModel stk = new StockViewModel(); stk.StockID = item.StockID; stk.CropID = item.CropID; stk.CropName = item.Name; stk.CurQuantity = item.CurQuantity; stk.Expiery = item.Expiery; stk.StockImage = item.StockImage; stk.Price = item.Price; searchStockList.Add(stk); } } } else if (sort == "Price Ascending") { var mergedList = (from c in db.CropInfoes join x in db.Stocks on c.CropID equals x.CropID join y in db.StocksImages on x.StockID equals y.StockID orderby x.Price ascending select new { x.StockID, c.CropID, c.Name, x.CurQuantity, x.Expiery, x.Price, y.StockImage }).ToList(); if (mergedList.Count() > 0) { foreach (var item in mergedList) { StockViewModel stk = new StockViewModel(); stk.StockID = item.StockID; stk.CropID = item.CropID; stk.CropName = item.Name; stk.CurQuantity = item.CurQuantity; stk.Expiery = item.Expiery; stk.StockImage = item.StockImage; stk.Price = item.Price; searchStockList.Add(stk); } } } else if (sort == "Price Descending") { var mergedList = (from c in db.CropInfoes join x in db.Stocks on c.CropID equals x.CropID join y in db.StocksImages on x.StockID equals y.StockID orderby x.Price descending select new { x.StockID, c.CropID, c.Name, x.CurQuantity, x.Expiery, x.Price, y.StockImage }).ToList(); if (mergedList.Count() > 0) { foreach (var item in mergedList) { StockViewModel stk = new StockViewModel(); stk.StockID = item.StockID; stk.CropID = item.CropID; stk.CropName = item.Name; stk.CurQuantity = item.CurQuantity; stk.Expiery = item.Expiery; stk.StockImage = item.StockImage; stk.Price = item.Price; searchStockList.Add(stk); } } } } return(searchStockList); }