Ejemplo n.º 1
0
        public async Task <ActionResult <SaleHeaderDto> > PostSale(PostSaleHeaderDto postSaleHeaderDto)
        {
            SaleHeader result = _mapper.Map <SaleHeader>(postSaleHeaderDto);

            _saleService.Create(result);

            return(CreatedAtAction(nameof(GetSale), new { id = result.Id }, _mapper.Map <SaleHeaderDto>(result)));
        }
        public async Task <ActionResult <SaleHeaderDto> > PostSale(PostSaleHeaderDto postSaleHeaderDto)
        {
            Wholesaler wholesaler = await _wholesalerService.GetAsync(postSaleHeaderDto.WholeSalerId);

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

            SaleHeader result = _mapper.Map <SaleHeader>(postSaleHeaderDto);

            await _saleHeaderService.Validate(result);

            await _saleHeaderService.Compute(result);

            _saleHeaderService.Add(result);

            await _saleHeaderService.SaveAsync();

            return(CreatedAtAction(nameof(GetSale), new { id = result.Id }, _mapper.Map <SaleHeaderDto>(result)));
        }