public async Task <IActionResult> Create([FromBody] ProductViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Product product = new Product { code = model.code, name = model.name, brandId = model.brandId, categoryId = model.categoryId, description = model.description }; _context.Products.Add(product); try { await _context.SaveChangesAsync(); } catch { return(BadRequest()); } return(Ok()); }
public async Task <IActionResult> PutBrand([FromRoute] int id, [FromBody] Brand brand) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != brand.id) { return(BadRequest()); } _context.Entry(brand).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BrandExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProduct_Unit([FromRoute] int id, [FromBody] Product_Unit product_Unit) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != product_Unit.unitId) { return(BadRequest()); } _context.Entry(product_Unit).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Product_UnitExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }