public Task <Basket> Handle(GetBasketRequest request) { var domainBasket = _store.GetById(request.Id); var basket = _mapper.Map <Basket>(domainBasket); return(Task.FromResult(basket)); }
public Task <IList <Item> > Handle(GetItemsRequest request) { var domainBasket = _store.GetById(request.BasketId); var items = _mapper.Map <IList <Item> >(domainBasket?.Items); return(Task.FromResult(items)); }
public Task <Item> Handle(GetItemRequest request) { var domainBasket = _store.GetById(request.BasketId); var domainItem = domainBasket?.Items?.FirstOrDefault(i => i.Id == request.Id); var item = _mapper.Map <Item>(domainItem); return(Task.FromResult(item)); }
public Task Handle(DeleteBasketRequest request) { var domainBasket = _store.GetById(request.Id); if (domainBasket == null) { return(Task.CompletedTask); } _store.Delete(request.Id); 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 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 <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)); }