Example #1
0
        public ActionResult Save(AT_Pages peg)
        {
            string msg = "";

            try
            {
                Session_CRM sess = (Session_CRM)Session["CRM_Session"];
                if (peg.PageID > 0)
                {
                    db.AT_Pages.Attach(peg);
                    db.UpdateExcept <AT_Pages>(peg);
                }
                else
                {
                    db.Entry(peg).State = System.Data.Entity.EntityState.Added;
                }
                db.SaveChanges();
                msg = "Page saved successfully!";
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            ViewBag.msg = msg;
            db          = new HRMSEntities();
            return(PartialView("_Index", db.AT_Pages.ToList()));
        }
Example #2
0
        public ActionResult _AgentSave(AT_Users usr)
        {
            string      msg  = "";
            Session_CRM sess = (Session_CRM)Session["CRM_Session"];

            try
            {
                //  var UserType = db.AT_UserType.Where(x => x.UserType == "Agent").Select(x => x.TypeID).FirstOrDefault();
                //usr.TypeID = UserType;
                // usr.ClientID = sess.User.ClientID;
                //  AT_Agent det = usr.Agent;
                usr.Password = CRM_Common.Encrypt(usr.Password);
                if (usr.UserID > 0)
                {
                    usr.UpdateBy   = sess.User.UserID;
                    usr.UpdateDate = DateTime.Now;

                    db.AT_Users.Attach(usr);
                    db.UpdateExcept <AT_Users>(usr, x => x.CreateBy, x => x.CreateDate);
                    db.SaveChanges();
                }
                else
                {
                    usr.CreateBy        = sess.User.UserID;
                    usr.CreateDate      = DateTime.Now;
                    db.Entry(usr).State = System.Data.Entity.EntityState.Added;
                    db.SaveChanges();
                }
                msg = "User saved successfully!";
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException.ToString().Contains("UNIQUE"))
                {
                    msg = "Conflict";
                }
                else
                {
                    msg = ex.Message;
                }
            }
            ViewBag.msg = msg;
            db          = new HRMSEntities();
            ViewBag.msg = msg;
            return(PartialView("_AgentIndex", db.AT_Users.Where(a => a.IsDeleted != true).ToList()));
        }
        public ActionResult Save(AT_Permission per)
        {
            string msg = "";

            try
            {
                Session_CRM sess = (Session_CRM)Session["CRM_Session"];

                if (per.PermissionID > 0)
                {
                    db.AT_Permission.Attach(per);
                    db.UpdateExcept <AT_Permission>(per);
                }
                else
                {
                    db.Entry(per).State = System.Data.Entity.EntityState.Added;
                }
                db.SaveChanges();

                db.AT_PermissionActionJunc.Where(x => x.PermissionID == per.PermissionID).ToList().ForEach(tol => db.AT_PermissionActionJunc.Remove(tol));
                db.SaveChanges();
                string[] act = per.Actions.Split(',');
                for (int i = 0; i < act.Length; i++)
                {
                    AT_PermissionActionJunc PA = new AT_PermissionActionJunc();
                    PA.PermissionID    = per.PermissionID;
                    PA.Action          = act[i].ToString();
                    db.Entry(PA).State = System.Data.Entity.EntityState.Added;
                    db.SaveChanges();
                }
                GenerateClass();
                msg = "Permission saved successfully!";
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            ViewBag.msg = msg;
            db          = new HRMSEntities();
            return(PartialView("_Index", db.AT_Permission.ToList()));
        }