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()); }
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)); }
public EditUserDefinePageViewModel(Int64 Id) : this() { var Db = new ApplicationDbContext(); var allRoles = Db.Roles; foreach (var role in allRoles) { var rvm = new SelectUserRoleEditorViewModel(role); this.Roles.Add(rvm); } if (Id == 0) { return; } var db = new UserDefinePagesContext(); var userpages = db.UserDefinePagess.Where(u => u.Id == Id).ToList()[0]; this.Id = userpages.Id; this.PageName = userpages.PageName; this.PageContent = userpages.PageContent; var userdefinepagesrole = new UserDefinePagesRoleContext(); var pagesroles = userdefinepagesrole.UserDefinePagesRoles.Where(u => u.PageId == userpages.Id); var disableroles = userdefinepagesrole.UserDefinePagesRoles.Where(u => u.PageId != userpages.Id); foreach (var userRole in pagesroles) { var checkUserRole = this.Roles.Find(r => r.RoleName == userRole.RoleName); checkUserRole.Selected = true; } foreach (var userRole in disableroles) { var checkUserRole = this.Roles.Find(r => r.RoleName == userRole.RoleName); if (checkUserRole != null) { checkUserRole.isdisabled = true; } } }
public CreateUserDefinePageViewModel(UserDefinePages userpages) : this() { this.PageName = userpages.PageName; this.PageContent = userpages.PageContent; var Db = new ApplicationDbContext(); var allRoles = Db.Roles; //foreach (var role in allRoles) //{ // var rvm = new SelectUserRoleEditorViewModel(role); // this.Roles.Add(rvm); //} var userdefinepagesrole = new UserDefinePagesRoleContext(); var disableroles = userdefinepagesrole.UserDefinePagesRoles.Where(u => u.PageId != userpages.Id); //foreach (var userRole in disableroles) //{ // var checkUserRole = this.Roles.Find(r => r.RoleName == userRole.RoleName); // checkUserRole.isdisabled = true; //} var roleslist = disableroles.Select(a => a.RoleName).ToList(); this.RoleList = new SelectList(allRoles.Where(r => !roleslist.Any(dr => dr == r.Name)).ToList(), "Name", "Name", null); }