public CartBO Create(CartBO cart) { using (var uow = facade.UnitOfWork) { _newCart = uow.CartRepository.Create(cartConv.Convert(cart)); uow.Complete(); return(cartConv.Convert(_newCart)); } }
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))); }
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)); } }
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()); } }