public async Task <ServiceResult> RemoveItemFromCart(Guid id, [FromBody] RemoveItemFromCartModel apiEntity) { var result = await _cartService.RemoveItemFromCartAsync(id, apiEntity.ShopItemDetailId, apiEntity.ShouldBeRemovedAllItems ?? false); if (result.TryCastModel(out Cart cart)) { result.ViewModel = CartViewModel.Map(cart); } return(result); }
public async Task <ServiceResult> AddItemToCart(Guid id, [FromBody] AddItemToCartModel apiEntity) { var result = await _cartService.AddItemToCartAsync(id, apiEntity.ShopItemDetailId, apiEntity.Count ?? 1); if (result.TryCastModel(out Cart cart)) { result.ViewModel = CartViewModel.Map(cart); } return(result); }
public async Task <ServiceResult> CreateNew([FromBody] CartAddModel apiEntity) { var entity = CartAddModel.Map(apiEntity); var result = await _cartService.AddAsync(entity); if (result.TryCastModel(out Cart cart)) { result.ViewModel = CartViewModel.Map(cart); } return(result); }
public static OrderViewModel Map(Order model) { if (model == null) { return(null); } return(new OrderViewModel { Id = model.Id, Name = model.Name, Mobile = model.Mobile, Address = model.Address, Comment = model.Comment, DateOfCreation = model.DateOfCreation, Cart = CartViewModel.Map(model.Cart), DateOfApproved = model.DateOfApproved, ApproveUser = UserShortViewModel.Map(model.ApproveUser), DateOfRejected = model.DateOfRejected, RejectUser = UserShortViewModel.Map(model.RejectUser), DateOfClosed = model.DateOfClosed, CloseUser = UserShortViewModel.Map(model.CloseUser) }); }
public async Task <CartViewModel> GetOne(Guid id) { var entity = await _cartService.FindByAsync(x => x.Id == id); return(CartViewModel.Map(entity)); }