コード例 #1
0
        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));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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));
        }