public IHttpActionResult PutEmployee(int id, Employee employee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employee.EmpId) { return(BadRequest()); } db.Entry(employee).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public Product AddProduct(Product prod) { using (var swarnacontext = new SwarnaContext()) { swarnacontext.Products.Add(prod); swarnacontext.SaveChanges(); return(prod); } }
public Product DeleteProduct(int id) { SwarnaContext swarnacontext = new SwarnaContext(); Product product = swarnacontext.Products.Find(id); if (product == null) { //return NotFound(); } swarnacontext.Products.Remove(product); swarnacontext.SaveChanges(); return(product); }
public void UpdateProduct(int id, Product product) { using (var swarnacontext = new SwarnaContext()) { swarnacontext.Entry(product).State = EntityState.Modified; try { swarnacontext.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { //return NotFound(); } else { throw; } } } }