public ActionResult Form(int?id)
        {
            if (Session["UserID"] == null)
            {
                return(RedirectToAction("Login", "Profile"));
            }

            HighlightNews HighlightNews;
            string        action = "New Data";

            if (id == null)
            {
                HighlightNews            = new HighlightNews();
                HighlightNews.CREATED_AT = ClassFunction.GetServerTime();
            }
            else
            {
                action        = "Update Data";
                HighlightNews = db.HighlightNews.Find(id);
            }

            if (HighlightNews == null)
            {
                return(HttpNotFound());
            }


            ViewBag.action = action;
            return(View(HighlightNews));
        }
        public bool IsInputValid(HighlightNews HighlightNews)
        {
            bool isValid = true;

            if (!ModelState.IsValid)
            {
                isValid = false;
            }
            return(isValid);
        }
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HighlightNews qL_mstcurr = db.HighlightNews.Find(id);

            if (qL_mstcurr == null)
            {
                return(HttpNotFound());
            }
            return(View(qL_mstcurr));
        }
        public ActionResult Form(HighlightNews HighlightNews, string action)
        {
            if (Session["UserID"] == null)
            {
                return(RedirectToAction("Login", "Profile"));
            }
            HighlightNews.CREATED_AT = ClassFunction.GetServerTime();
            sSql = "select top 1 max(ID) + 1 from HighlightNews";
            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 HighlightNews (TITLE, SUBTITLE, ISENABLE, CREATED_AT, UPDATED_AT) VALUES('" + HighlightNews.TITLE + "', '" + HighlightNews.SUBTITLE + "', '" + HighlightNews.ISENABLE + "', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)";
                            db.Database.ExecuteSqlCommand(sSql);

                            db.SaveChanges();
                        }
                        else
                        {
                            sSql = "UPDATE HighlightNews SET TITLE='" + HighlightNews.TITLE + "', SUBTITLE='" + HighlightNews.SUBTITLE + "', ISENABLE='" + HighlightNews.ISENABLE + "', CREATED_AT=CURRENT_TIMESTAMP, UPDATED_AT=CURRENT_TIMESTAMP WHERE ID=" + HighlightNews.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(HighlightNews));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            if (Session["UserID"] == null)
            {
                return(RedirectToAction("Login", "Profile"));
            }
            HighlightNews list       = db.HighlightNews.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 HighlightNews 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));
        }