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