public async Task <IActionResult> FinishOrder()
        {
            var shoppingCartId = this.HttpContext.Session.GetShoppingCartId();

            var user = await userManager.GetUserAsync(User);

            var order = new Order
            {
                ClientId     = user.Id,
                RestaurantId = this.shoppingCartService.GetRestauratId(shoppingCartId)
            };

            var itemsWithDetails = await GetItemsFromCartWithQuantities(shoppingCartId);

            foreach (var item in itemsWithDetails)
            {
                order.Products.Add(new OrderProduct
                {
                    ProductId = item.ProductId,
                    Price     = item.ProductPrice,
                    Quantity  = item.ProductQuantity
                });
            }

            await db.Orders.AddAsync(order);

            await db.SaveChangesAsync();

            this.shoppingCartService.ClearCart(shoppingCartId);

            this.TempData.AddSuccessMessage("Order accepted.");

            return(Redirect("/"));
        }
Beispiel #2
0
        public async Task Edit(int id, string name, string description, int cityId, int menuId, string userId)
        {
            var restaurant = await this.db.Restaurants.FirstOrDefaultAsync(m => m.Id == id && m.OwnerId == userId);

            if (restaurant == null)
            {
                return;
            }

            restaurant.Name        = name;
            restaurant.Description = description;
            restaurant.CityId      = cityId;
            restaurant.MenuId      = menuId;

            await db.SaveChangesAsync();
        }