public async Task <IActionResult> PutProductsModel(int id, ProductsModel ProductsModel) { ProductsModel.IdProduct = id; _context.Entry(ProductsModel).State = EntityState.Modified; if (id != ProductsModel.IdProduct) { return(BadRequest()); } _context.Entry(ProductsModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductsModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutOrderModel(int id, OrderModel OrderModel) { if (id != OrderModel.IdOrder) { return(BadRequest()); } _context.Entry(OrderModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProduct([FromRoute] Guid id, [FromBody] Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != product.Id) { return(BadRequest("Product id is required")); } _context.Entry(product).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(Ok("Product updated " + product.Id)); }
public async Task <ActionResult <Product> > Create([FromBody] Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _productsDbContext.Products.AddAsync(product); await _productsDbContext.SaveChangesAsync(); return(Ok(product)); }
public async Task <ProductDto> AddProductAsync(ProductDto product) { try { product.ProductId = new Guid(); var addedProduct = await _context.Products.AddAsync(_mapper.Map <ProductEntity>(product)); await _context.SaveChangesAsync(); return(_mapper.Map <ProductDto>(addedProduct)); } catch (Exception ex) { throw ex; } }