public async Task <CheckoutResponse> CheckoutAsync(CheckoutRequest request) { var cart = await GetCart(request.Id); cart.IsCheckout = true; var checkoutCart = await _mutateRepository.UpdateAsync(cart); return(new CheckoutResponse { IsSucceed = checkoutCart != null }); }
public async Task <IActionResult> Put(Guid id, [FromBody] PostInputModel model) { var post = await _postRepo.GetByIdAsync(id); if (post == null) { return(NotFound()); } post.Content = model.Description; post.Title = model.Title; await _postRepo.UpdateAsync(post); return(new NoContentResult()); }
public async Task <UpdateTaskResponse> Update(Guid id, [FromBody] UpdateTaskRequest request) { var oldOne = await _taskQuery.GetByIdAsync(id); if (oldOne == null) { throw new CoreException($"Could not delete item #{id}."); } oldOne.ChangeName(request.Name) .ChangeAssignedTo(request.AssignedTo) .ChangeCategoryType((Domain.CategoryType)request.CategoryType); var response = await _taskRepository.UpdateAsync(oldOne); return(new UpdateTaskResponse()); }
public async Task <GetCartByIdResponse> UpdateItemInCartAsync(UpdateItemInCartRequest request) { var isNewItem = false; var cart = await GetCart(request.CartId); cart = await InitCart(cart); var item = cart.CartItems.FirstOrDefault(x => x.Product.ProductId == request.ProductId); // if not exists then it should be a new item if (item == null) { isNewItem = true; item = new CartItem() { Quantity = request.Quantity, Product = new Product(request.ProductId) }; cart.CartItems.Add(item); } else { // otherwise is updating the current item in the cart item.Quantity = request.Quantity; } cart = PriceCalculatorContext.Execute(cart); var result = await _mutateRepository.UpdateAsync(cart); // Todo: refactor to unit of work later if (!isNewItem) { await _cartItemMutateRepository.UpdateAsync(item); } else { await _cartItemMutateRepository.AddAsync(item); } return(GetCartByIdResponse(cart)); }