Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Logo,Category")] Vendor vendor)
        {
            if (!authenticateVendorId(id).Result)
            {
                return(NotFound());
            }
            if (id != vendor.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vendor);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VendorExists(vendor.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index", new { id = id }));
            }
            return(View(vendor));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Logo,Category")] Vendor vendor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vendor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vendor));
        }
Пример #3
0
        private async Task <int> SaveOrderByVendor(List <Item> cart, Payment payment)
        {
            Dictionary <int, int> VendorOrderIndex = new Dictionary <int, int>();
            List <Order>          Orders           = new List <Order>();
            int i = 0;

            foreach (Item item in cart)
            {
                try
                {
                    int index = VendorOrderIndex[item.food.VendorId];
                }
                catch (KeyNotFoundException)
                {
                    VendorOrderIndex[item.food.VendorId] = i++;
                    Order order = new Order();
                    order.Status    = "Cooking";
                    order.Date      = DateTime.Now;
                    order.UserId    = payment.UserId;
                    order.PaymentId = payment.Id;
                    order.VendorId  = item.food.VendorId;
                    _context.Add(order);
                    await _context.SaveChangesAsync();

                    Orders.Add(order);
                    Console.WriteLine(order.VendorId);
                }
            }
            foreach (KeyValuePair <int, int> entry in VendorOrderIndex)
            {
                await sendMess(entry.Key);
            }
            foreach (Item item in cart)
            {
                int   ind   = VendorOrderIndex[item.food.VendorId];
                Order order = Orders[ind];
                Food  food  = await _context.Food.FindAsync(item.food.Id);

                if (food.OrderFoods == null)
                {
                    food.OrderFoods = new List <OrderFood>();
                }
                food.OrderFoods.Add
                (
                    new OrderFood
                {
                    Order  = order,
                    Food   = food,
                    Amount = item.quantity
                }
                );
                await _context.SaveChangesAsync();
            }
            return(0);
        }
Пример #4
0
        //POST: Order/UpdateOrderStatus?orderId=orderId&status=status
        public async Task <IActionResult> UpdateOrderStatus(int?orderId, string status, string typeDate)
        {
            if (orderId == null || status == null)
            {
                return(NotFound());
            }

            var order = await _context.Order.FindAsync(orderId);

            if (order == null)
            {
                return(NotFound());
            }
            order.Status = status;
            _context.Update(order);
            await _context.SaveChangesAsync();

            return(RedirectToAction("UpdateOrderStatus", new{ typeDate = typeDate }));
        }