コード例 #1
0
        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());
        }