public ActionResult Create(DebitNoteProductModel debitProduct) { try { using (DoorEntities db = new DoorEntities()) { if (debitProduct.Debit_Note.id == 0) { Debit_Note usingData = this.convertDebit(debitProduct.Debit_Note, "create"); db.Debit_Note.Add(usingData); db.SaveChanges(); return(Json(new { success = true, message = "Save Successfully" }, JsonRequestBehavior.AllowGet)); } else { return(View()); } } } catch { return(View()); } }
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(); }
public ActionResult AddEditViewUsers(User userData) { //var existingUser = true; try { // TODO: Add insert logic here using (DoorEntities db = new DoorEntities()) { if (userData.user_id == 0) { db.Users.Add(userData); userData.beg_date = DateTime.Now; userData.end_date = Convert.ToDateTime("May 01 9999"); userData.create_by = "rithy"; userData.create_on = DateTime.Now; userData.last_change_by = "rithy"; userData.last_change_on = DateTime.Now; db.SaveChanges(); return(Json(new { success = true, message = "Save Successfully" }, JsonRequestBehavior.AllowGet)); } else { //db.Entry(userData).State = EntityState.Modified; // modify old data of end date to yesterday this.UpdateOldUserData(userData.user_id); db.Users.Add(userData); userData.beg_date = DateTime.Now; userData.last_change_by = "reach"; //temUserData.create_by; userData.last_change_on = DateTime.Now; db.SaveChanges(); return(Json(new { success = true, message = "Update Successfully" }, JsonRequestBehavior.AllowGet)); } } } catch { return(View()); } }