public BasketViewModel Clear(Guid basketId) { var basket = _basketStore.Get(basketId); if (basket == null) { return(null); } basket.Items = new List <ItemEntity>(); _basketStore.Update(basket); return(_basketMapper.MapFrom(basket)); }
public Task Handle(DeleteItemsRequest request) { var domainBasket = _store.GetById(request.BasketId); if (domainBasket == null) { return(Task.CompletedTask); } domainBasket.Items?.Clear(); _store.Update(domainBasket); return(Task.CompletedTask); }
public Task Handle(DeleteItemRequest request) { var domainBasket = _store.GetById(request.BasketId); if (domainBasket == null) { return(Task.CompletedTask); } var domainItem = domainBasket.Items?.RemoveAll(i => i.Id == request.Id); _store.Update(domainBasket); return(Task.CompletedTask); }
public Task <Item> Handle(UpdateItemRequest request) { var domainBasket = _store.GetById(request.BasketId); var domainItem = domainBasket?.Items?.FirstOrDefault(i => i.Id == request.Id); if (domainItem == null) { return(Task.FromResult <Item>(null)); } domainItem.Quantity = request.Item.Quantity; _store.Update(domainBasket); var item = _mapper.Map <Item>(domainItem); return(Task.FromResult(item)); }
public Task <Item> Handle(CreateItemRequest request) { var domainBasket = _store.GetById(request.BasketId); if (domainBasket == null) { return(Task.FromResult <Item>(null)); } var domainItem = new Models.Domain.Item { Id = Guid.NewGuid(), Description = request.Item.Description, Quantity = request.Item.Quantity }; domainBasket.Items.Add(domainItem); _store.Update(domainBasket); var item = _mapper.Map <Item>(domainItem); return(Task.FromResult(item)); }