public IHttpActionResult PostSaleUnit(SaleUnit saleUnit) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.SaleUnits.Add(saleUnit); try { db.SaveChanges(); } catch (DbUpdateException) { if (SaleUnitExists(saleUnit.ID)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = saleUnit.ID }, saleUnit)); }
public IHttpActionResult PutSaleUnit(int id, SaleUnit saleUnit) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != saleUnit.ID) { return(BadRequest()); } db.Entry(saleUnit).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!SaleUnitExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetSaleUnit(int id) { SaleUnit saleUnit = db.SaleUnits.Find(id); if (saleUnit == null) { return(NotFound()); } return(Ok(saleUnit)); }
public IHttpActionResult DeleteSaleUnit(int id) { SaleUnit saleUnit = db.SaleUnits.Find(id); if (saleUnit == null) { return(NotFound()); } db.SaleUnits.Remove(saleUnit); db.SaveChanges(); return(Ok(saleUnit)); }