public ActionResult Form(int?id) { if (Session["UserID"] == null) { return(RedirectToAction("Login", "Profile")); } BENEFIT BENEFIT; string action = "New Data"; if (id == null) { BENEFIT = new BENEFIT(); } else { action = "Update Data"; BENEFIT = db.BENEFIT.Find(id); } if (BENEFIT == null) { return(HttpNotFound()); } ViewBag.action = action; return(View(BENEFIT)); }
public bool IsInputValid(BENEFIT BENEFIT) { bool isValid = true; if (!ModelState.IsValid) { isValid = false; } return(isValid); }
public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BENEFIT qL_mstcurr = db.BENEFIT.Find(id); if (qL_mstcurr == null) { return(HttpNotFound()); } return(View(qL_mstcurr)); }
public ActionResult Form(BENEFIT BENEFIT, string action) { if (Session["UserID"] == null) { return(RedirectToAction("Login", "Profile")); } sSql = "select top 1 max(ID) + 1 from BENEFIT"; var mstoid = db.Database.SqlQuery <Decimal>(sSql).FirstOrDefault(); if (ModelState.IsValid) { using (var objTrans = db.Database.BeginTransaction()) { try { if (action == "New Data") { sSql = "INSERT INTO BENEFIT (TITLE, SUBTITLE, CREATED_AT, UPDATED_AT) VALUES('" + BENEFIT.ORDERNO + "', '" + BENEFIT.DESCRIPTION + "', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)"; db.Database.ExecuteSqlCommand(sSql); db.SaveChanges(); } else { sSql = "UPDATE BENEFIT SET TITLE='" + BENEFIT.ORDERNO + "', SUBTITLE='" + BENEFIT.DESCRIPTION + "', CREATED_AT=CURRENT_TIMESTAMP, UPDATED_AT=CURRENT_TIMESTAMP WHERE ID=" + BENEFIT.ID + ""; db.Database.ExecuteSqlCommand(sSql); db.SaveChanges(); } objTrans.Commit(); return(RedirectToAction("Index")); } catch (Exception ex) { objTrans.Rollback(); ModelState.AddModelError("", ex.ToString()); } } } ViewBag.action = action; return(View(BENEFIT)); }
public ActionResult DeleteConfirmed(int id) { if (Session["UserID"] == null) { return(RedirectToAction("Login", "Profile")); } BENEFIT list = db.BENEFIT.Find(id); var servertime = ClassFunction.GetServerTime(); string result = "success"; string msg = ""; if (list == null) { result = "failed"; msg = "Data can't be found!"; } if (result == "success") { using (var objTrans = db.Database.BeginTransaction()) { try { sSql = "DELETE FROM BENEFIT WHERE ID=" + list.ID; db.Database.ExecuteSqlCommand(sSql); db.SaveChanges(); objTrans.Commit(); } catch (Exception ex) { objTrans.Rollback(); result = "failed"; msg = ex.ToString(); } } } return(Json(new { result, msg }, JsonRequestBehavior.AllowGet)); }