예제 #1
0
파일: Prog.cs 프로젝트: OmaraliA/.NET-
        public List <Order> ReadOrder()
        {
            var orderStore = new OrderStore()
            {
                Path = ordersPath
            };
            var orderList = orderStore.GetCollection();

            return(orderList);
        }
예제 #2
0
        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));
        }
예제 #3
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());
        }