Exemplo n.º 1
0
        public async Task <IActionResult> PutProductSold(int id, PublicApi.v1.DTO.ProductSold productSold)
        {
            if (!ModelState.IsValid || id != productSold.Id)
            {
                return(BadRequest());
            }

            if (await _bll.ProductsSold.EditProductInSale(id, productSold.ProductId,
                                                          ProductSoldMapper.MapFromExternal(productSold)))
            {
                return(NoContent());
            }

            return(BadRequest());
        }
Exemplo n.º 2
0
        public async Task <ActionResult <ProductSold> > PostProductSold(PublicApi.v1.DTO.ProductSold productSold)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (await _bll.ProductsSold.AddProductToSale(productSold.ProductId,
                                                         ProductSoldMapper.MapFromExternal(productSold)))
            {
                await _bll.SaveChangesAsync();

                productSold = PublicApi.v1.Mappers.ProductSoldMapper.MapFromBLL(
                    _bll.ProductsSold.GetUpdatesAfterUOWSaveChanges(
                        PublicApi.v1.Mappers.ProductSoldMapper.MapFromExternal(productSold)));

                return(CreatedAtAction("GetProductSold",
                                       new { version = HttpContext.GetRequestedApiVersion().ToString(), id = productSold.Id }, productSold));
            }

            return(BadRequest());
        }