Exemplo n.º 1
0
        public async Task <Response <int> > Handle(SaveItemCommand request, CancellationToken cancellationToken)
        {
            var item = await _itemRepository.GetByCode(request.Code);

            if (item != null)
            {
                throw new ConflictException("This code is already registered!");
            }

            var itemModel = _mapper.Map <Item>(request);

            itemModel.Active = true;
            await _itemRepository.AddAsync(itemModel);

            return(new Response <int>(itemModel.Id));
        }