[HttpPost("create")]//http://localhost:5000/StatesProduct/create public async Task <ActionResult <StateProductModel> > CreateStateProduct(StateProductModel stateProduct) { try { dBContext.StatesProducts.Add(stateProduct); await dBContext.SaveChangesAsync(); return(Ok(stateProduct)); } catch (Exception e) { return(StatusCode(410)); } }
[HttpPut("update/{id}")]//http://localhost:5000/StatesProduct/update/2 public async Task <IActionResult> UpdateStateProduct(StateProductModel stateProduct, long id) { try { if (id != stateProduct.IdStateProduct) { return(BadRequest()); } dBContext.Entry(stateProduct).State = EntityState.Modified; await dBContext.SaveChangesAsync(); return(NoContent()); } catch (Exception e) { bool stateProductExist = dBContext.StatesProducts.Any(e => e.IdStateProduct == id); if (!stateProductExist) { return(NotFound()); } return(StatusCode(410)); } }