Example #1
0
        public ActionResult Create(CreateUserDefinePageViewModel model, string SelectedRole)
        {
            if (!((CustomPrincipal)User).CanAddAdminFeature("UserInterfaceSetting"))
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (ModelState.IsValid)
            {
                UserDefinePages userpages = new UserDefinePages();
                userpages.PageName    = model.PageName;
                userpages.PageContent = model.PageContent; //.Replace(" turanto-row-edit", "").Replace("turanto-row-delete", "")

                db.UserDefinePagess.Add(userpages);
                db.SaveChanges();
                Int64 pageId = userpages.Id;

                var userdefinepagesrole = new UserDefinePagesRoleContext();
                //foreach (var ent in model.Roles)
                //{
                //    if (ent.Selected)
                //    {
                if (!string.IsNullOrEmpty(SelectedRole))
                {
                    UserDefinePagesRole objUDPR = new UserDefinePagesRole();
                    objUDPR.PageId   = pageId;
                    objUDPR.RoleName = SelectedRole;
                    userdefinepagesrole.UserDefinePagesRoles.Add(objUDPR);
                    userdefinepagesrole.SaveChanges();
                }
                //    }
                //}
                return(Json(new { success = true, page = pageId }));
            }
            else
            {
                var errors = new List <string>();
                foreach (var modelState in ViewData.ModelState.Values)
                {
                    errors.AddRange(modelState.Errors.Select(error => error.ErrorMessage));
                }
                return(Json(errors));
            }
            return(View());
        }
Example #2
0
        public ActionResult DeletePage(long id)
        {
            if (!((CustomPrincipal)User).CanDeleteAdminFeature("UserInterfaceSetting"))
            {
                return(RedirectToAction("Index", "Home"));
            }
            UserDefinePages userdefinepages     = db.UserDefinePagess.Find(id);
            var             userdefinepagesrole = new UserDefinePagesRoleContext();

            userdefinepagesrole.UserDefinePagesRoles.RemoveRange(userdefinepagesrole.UserDefinePagesRoles.Where(u => u.PageId == id));
            userdefinepagesrole.SaveChanges();
            db.Entry(userdefinepages).State = EntityState.Deleted;
            db.UserDefinePagess.Remove(userdefinepages);
            try
            {
                db.SaveChanges();
            }
            catch { }

            return(Json("Success", "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet));
        }