//POST: delete from database logic
        public ActionResult Delete(string custid)
        {
            var userobject = Session["id"];

            if (userobject == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            else
            {
                custid = Request.QueryString["custid"];
                int ids = Convert.ToInt32(custid);
                using (db)
                {
                    mt_customer custDt = db.mt_customer.Where(x => x.CUST_ID == ids).FirstOrDefault <mt_customer>();
                    try
                    {
                        db.mt_customer.Remove(custDt);
                        db.SaveChanges();
                        return(Json(new { success = true, message = "Deleted successfully" }, JsonRequestBehavior.AllowGet));
                    }
                    catch (Exception e)
                    {
                        return(Json(new { success = false, message = e.InnerException.Message }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
        }
        //POST: Insert to database logic
        public ActionResult Insert(mt_customer custDt)
        {
            var userobject = Session["id"];

            if (userobject == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            else
            {
                var editmode = Request.QueryString["editmode"];
                var username = User.Identity.Name;
                if (string.IsNullOrEmpty(custDt.PHONE))
                {
                    custDt.PHONE = "";
                }
                if (string.IsNullOrEmpty(custDt.ADDRESS))
                {
                    custDt.ADDRESS = "";
                }
                if (string.IsNullOrEmpty(custDt.EMAIL))
                {
                    custDt.EMAIL = "";
                }
                custDt.ENTRY_DATE  = DateTime.Now;
                custDt.ENTRY_USER  = userobject.ToString();
                custDt.UPDATE_DATE = DateTime.Now;
                custDt.UPDATE_USER = userobject.ToString();
                var dtname = username;

                using (db)
                {
                    //dt = db.PEKAONLINE_ACTIONLIST.Where(x => x.LSR_NUMBER == actionListDt.LSR_NUMBER).FirstOrDefault<PEKAONLINE_ACTIONLIST>();
                    //if (dt == null)
                    //{

                    //    db.Dispose();
                    //}
                    //else
                    //{
                    //    db.Dispose();
                    //    return Json(new { success = false, message = "Duplicate Entry" }, JsonRequestBehavior.AllowGet);
                    //}
                    try
                    {
                        db.mt_customer.Add(custDt);
                        db.SaveChanges();
                        return(Json(new { success = true, message = "Saved successfully" }, JsonRequestBehavior.AllowGet));
                    }
                    catch (Exception e)
                    {
                        return(Json(new { success = false, message = e.InnerException.Message }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
        }
        //POST: Update to database logic
        public ActionResult Update(mt_customer custDt)
        {
            var userobject = Session["id"];

            if (userobject == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            else
            {
                var editmode = Request.QueryString["editmode"];
                var username = User.Identity.Name;

                custDt.UPDATE_DATE = DateTime.Now;
                custDt.UPDATE_USER = userobject.ToString();
                using (db)
                {
                    var id       = custDt.CUST_ID;
                    var dtfromdb = db.mt_customer.Find(id);
                    dtfromdb.CUST_NAME   = custDt.CUST_NAME;
                    dtfromdb.PHONE       = custDt.PHONE;
                    dtfromdb.ADDRESS     = custDt.ADDRESS;
                    dtfromdb.EMAIL       = custDt.EMAIL;
                    dtfromdb.UPDATE_DATE = custDt.UPDATE_DATE;
                    dtfromdb.UPDATE_USER = custDt.UPDATE_USER;
                    if (string.IsNullOrEmpty(custDt.PHONE))
                    {
                        dtfromdb.PHONE = "";
                    }
                    if (string.IsNullOrEmpty(custDt.ADDRESS))
                    {
                        dtfromdb.ADDRESS = "";
                    }
                    if (string.IsNullOrEmpty(custDt.EMAIL))
                    {
                        dtfromdb.EMAIL = "";
                    }
                    try
                    {
                        db.Entry(dtfromdb).State = EntityState.Modified;
                        db.SaveChanges();
                        return(Json(new { success = true, message = "Updated successfully" }, JsonRequestBehavior.AllowGet));
                    }
                    catch (Exception e)
                    {
                        return(Json(new { success = false, message = e.InnerException.Message }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
        }