예제 #1
0
 public CartBO Create(CartBO cart)
 {
     using (var uow = facade.UnitOfWork)
     {
         _newCart = uow.CartRepository.Create(cartConv.Convert(cart));
         uow.Complete();
         return(cartConv.Convert(_newCart));
     }
 }
예제 #2
0
        public async Task <IActionResult> Update([FromBody] CartViewModel viewModel)
        {
            var user = await userManager.FindByNameAsync(User.Identity.Name).ConfigureAwait(false);

            var cart = await context.Carts
                       .Where(x => x.UserId == user.Id)
                       .Include(x => x.Items)
                       .ThenInclude(y => y.Product)
                       .ThenInclude(z => z.Mesurement)
                       .FirstOrDefaultAsync()
                       .ConfigureAwait(false);

            var newCart = updateService.UpdateCart(cart, viewModel, user);

            if (string.IsNullOrEmpty(newCart.Id))
            {
                context.Carts.Add(newCart);
            }
            else
            {
                context.Carts.Update(newCart);
            }
            await context.SaveChangesAsync().ConfigureAwait(false);

            return(Ok(CartConverter.Convert(newCart)));
        }
예제 #3
0
        public CartItemBO Update(CartItemBO cartItem)
        {
            using (var uow = facade.UnitOfWork)
            {
                var cartItemFromDb = uow.CartItemRepository.Get(cartItem.Id);
                if (cartItemFromDb == null)
                {
                    throw new InvalidOperationException("Cart not found");
                }

                cartItemFromDb.Id        = cartItem.Id;
                cartItemFromDb.Cart      = cartConv.Convert(cartItem.Cart);
                cartItemFromDb.CartId    = cartItem.CartId;
                cartItemFromDb.Product   = prodConv.Convert(cartItem.Product);
                cartItemFromDb.ProductId = cartItem.ProductId;

                uow.Complete();

                return(cartItemConv.Convert(cartItemFromDb));
            }
        }
예제 #4
0
        public async Task <IActionResult> View()
        {
            var user = await userManager.FindByNameAsync(User.Identity.Name).ConfigureAwait(false);

            var cart = await context.Carts
                       .Where(x => x.UserId == user.Id)
                       .Include(x => x.Items)
                       .ThenInclude(y => y.Product)
                       .ThenInclude(z => z.Mesurement)
                       .FirstOrDefaultAsync()
                       .ConfigureAwait(false);

            if (cart != null)
            {
                return(Ok(CartConverter.Convert(cart)));
            }
            else
            {
                return(NotFound());
            }
        }