コード例 #1
0
        public async Task <List <ShoppingCart> > GetShoppingCarts(string userId, int?restaurantId)
        {
            var userEntity = _userService.Get(userId);

            if (userEntity is null)
            {
                throw new ArgumentNullException("User doesn't exist");
            }

            var restaurantEntity = _restaurantService.Get(restaurantId);

            if (restaurantEntity is null)
            {
                throw new ArgumentNullException("Restaurant doesn't exist");
            }

            return(await _shoppingBasketRepository.GetShoppingCarts(x => x.UserId == userId && x.RestaurantId == restaurantId));
        }
コード例 #2
0
        public async Task <int> CreateOrder(Order order, string userId, int restaurantId)
        {
            var productsFromBasket = await _shoppingBasketRepository.GetShoppingCarts(s => s.UserId == userId && s.RestaurantId == restaurantId);

            var orderItems = productsFromBasket.Select(x => new OrderItem
            {
                Count  = x.Count,
                DishId = x.DishId,
            });

            order.CreateAt        = DateTime.Now;
            order.TotalGrossPrice = productsFromBasket.Sum(x => x.Dish.GrossPrice * x.Count);
            order.TotalQuantity   = productsFromBasket.Sum(x => x.Count);
            order.UserId          = userId;
            order.OrderItems      = orderItems.ToList();

            await _orderRepository.Create(order);

            return(order.Id);
        }