public ActionResult Edit(Employee employee) { if (TryUpdateModel(employee)) { _employeeDb.Entry(employee).State = EntityState.Modified; _employeeDb.SaveChanges(); return(RedirectToAction("Index", new { id = employee.Id })); } return(View(employee)); }
public IHttpActionResult PutEmployee(int id, Employee employee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employee.Id) { 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 async Task ExecuteAsync(EmployeeEntity employee) { using (var dbContext = new EmployeeDb(_connectionString)) { //var model = await dbContext.Employee.AddAsync(employee); dbContext.Entry(employee).State = EntityState.Modified; await dbContext.SaveChangesAsync(); } }
public ActionResult Edit(Employee employee) { if (ModelState.IsValid) { db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employee)); }
// PUT api/HomeApi/5 public HttpResponseMessage PutEmployee(int id, Employee employee) { if (ModelState.IsValid && id == employee.EmployeeId) { db.Entry(employee).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }