public IHttpActionResult PutEmployeeInfo(int id, EmployeeInfo employeeInfo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employeeInfo.Id) { return(BadRequest()); } db.Entry(employeeInfo).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!EmployeeInfoExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutTblUser(int id, TblUser tblUser) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tblUser.Id) { return(BadRequest()); } db.Entry(tblUser).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TblUserExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void DeleteEmployee(long id) { using (var db = new EmployeeDbEntities()) { var existingEmployee = db.Employees.Where(x => x.Id == id).FirstOrDefault(); if (existingEmployee != null) { db.Entry(existingEmployee).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); } } }
public void UpdateEmployee(long id, Employee employee) { using (var db = new EmployeeDbEntities()) { var existingEmployee = db.Employees.Where(x => x.Id == id).FirstOrDefault(); if (existingEmployee != null) { existingEmployee.Name = employee.Name; existingEmployee.Email = employee.Email; existingEmployee.Type = employee.Type; existingEmployee.DateOfJoining = employee.DateOfJoining; db.Entry(existingEmployee).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } }