public List <Order> ReadOrder() { var orderStore = new OrderStore() { Path = ordersPath }; var orderList = orderStore.GetCollection(); return(orderList); }
public IActionResult Test() { var orderStore = new OrderStore() { Path = orderPath }; var orderList = orderStore.GetCollection(); var val = orderList.Sum(x => x.Amount * x.Price); var orderCopy = orderList.GroupBy(x => x.Id).Select(y => new Order { Id = y.First().Id, Name = y.First().Name, Price = y.First().Price, Amount = y.Key }); ViewData["TotalAmount"] = val; return(View(orderList)); }
public IActionResult Answer(int ProductID, int ID) { int ProduxtAmount = int.Parse(Request.Form["Amount"].ToString()); var productStore = new ProductStore() { Path = productPath }; var orderStore = new OrderStore() { Path = orderPath }; var productList = productStore.GetCollection(); var orderList = orderStore.GetCollection(); ViewData["ID"] = ID; ViewData["ProductID"] = ProductID; if (productList.Where(x => x.Id == ProductID).First().Amount < ProduxtAmount) { ViewData["Answer"] = "Error. We don't have so many items"; } else { var c = productList.Where(x => x.Id == ProductID).First(); int val = orderList.Where(x => x.Id == ProductID).Sum(x => x.Amount); if (val + ProduxtAmount > c.Amount) { ViewData["Answer"] = "Error. We don't have so many items"; } else { orderStore.WriteData(c.Id, c.Name, c.Price, ProduxtAmount); ViewData["Answer"] = "Ok. Your request is in process"; } } return(View()); }