public ActionResult Form(int?id) { if (Session["UserID"] == null) { return(RedirectToAction("Login", "Profile")); } HighlightStore HighlightStore; string action = "New Data"; if (id == null) { HighlightStore = new HighlightStore(); HighlightStore.CREATED_AT = ClassFunction.GetServerTime(); } else { action = "Update Data"; HighlightStore = db.HighlightStores.Find(id); } if (HighlightStore == null) { return(HttpNotFound()); } ViewBag.action = action; return(View(HighlightStore)); }
public bool IsInputValid(HighlightStore HighlightStore) { bool isValid = true; if (!ModelState.IsValid) { isValid = false; } return(isValid); }
public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HighlightStore qL_mstcurr = db.HighlightStores.Find(id); if (qL_mstcurr == null) { return(HttpNotFound()); } return(View(qL_mstcurr)); }
public ActionResult Form(HighlightStore HighlightStore, string action) { if (Session["UserID"] == null) { return(RedirectToAction("Login", "Profile")); } HighlightStore.CREATED_AT = ClassFunction.GetServerTime(); sSql = "select top 1 max(ID) + 1 from HighlightStore"; 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 HighlightStore (TITLE, SUBTITLE, CREATED_AT, UPDATED_AT) VALUES('" + HighlightStore.TITLE + "', '" + HighlightStore.SUBTITLE + "', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)"; db.Database.ExecuteSqlCommand(sSql); db.SaveChanges(); } else { sSql = "UPDATE HighlightStore SET TITLE='" + HighlightStore.TITLE + "', SUBTITLE='" + HighlightStore.SUBTITLE + "', CREATED_AT=CURRENT_TIMESTAMP, UPDATED_AT=CURRENT_TIMESTAMP WHERE ID=" + HighlightStore.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(HighlightStore)); }
public ActionResult DeleteConfirmed(int id) { if (Session["UserID"] == null) { return(RedirectToAction("Login", "Profile")); } HighlightStore list = db.HighlightStores.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 HighlightStore 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)); }