Exemplo n.º 1
0
        public async Task <ActionResult <BasketLine> > Put(Guid basketId,
                                                           Guid basketLineId,
                                                           [FromBody] BasketLineForUpdate basketLineForUpdate)
        {
            if (!await _basketRepository.BasketExists(basketId))
            {
                return(NotFound());
            }

            var basketLineEntity = await _basketLinesRepository.GetBasketLineById(basketLineId);

            if (basketLineEntity == null)
            {
                return(NotFound());
            }

            // map the entity to a dto
            // apply the updated field values to that dto
            // map the dto back to an entity
            _mapper.Map(basketLineForUpdate, basketLineEntity);

            _basketLinesRepository.UpdateBasketLine(basketLineEntity);
            await _basketLinesRepository.SaveChanges();

            return(Ok(_mapper.Map <BasketLine>(basketLineEntity)));
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public async Task <Unit> Handle(UpdateBasketLineCommand request, CancellationToken cancellationToken)
        {
            _basketLinesRepository.UpdateBasketLine(request.BasketLine);
            await _basketLinesRepository.SaveChanges();

            return(Unit.Value);
        }