public ActionResult Delete(int id) { try { // TODO: Add delete logic here using (DoorEntities db = new DoorEntities()) { //User userData = db.Users.Where( x => x.user_id == id).FirstOrDefault<User>(); //userData.end_date = DateTime.Now; var userUpdate = new User() { user_id = id, end_date = DateTime.Now, last_change_by = "rithy2", last_change_on = DateTime.Now }; db.Users.Attach(userUpdate); db.Entry(userUpdate).Property(x => x.end_date).IsModified = true; db.Entry(userUpdate).Property(x => x.last_change_on).IsModified = true; db.Entry(userUpdate).Property(x => x.last_change_by).IsModified = true; //db.Users.Remove(userData); db.SaveChanges(); return(Json(new { success = true, message = "Delete user successfully" }, JsonRequestBehavior.AllowGet)); } //return RedirectToAction("Index"); } catch { return(View()); } }
// Update old data before edit or delete public void UpdateOldUserData(int id = 0) { User old_data = this.GetUser(id); db.Entry(old_data).State = EntityState.Modified; old_data.end_date = DateTime.Now; db.SaveChanges(); }