public ActionResult DeleteConfirmed(long id) { if (!((CustomPrincipal)User).CanDeleteAdminFeature("UserInterfaceSetting")) { return(RedirectToAction("Index", "Home")); } UserDefinePages userdefinepages = db.UserDefinePagess.Find(id); db.UserDefinePagess.Remove(userdefinepages); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,PageName,PageContent")] UserDefinePages userdefinepages) { if (!((CustomPrincipal)User).CanEditAdminFeature("UserInterfaceSetting")) { return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { db.Entry(userdefinepages).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(userdefinepages)); }
// GET: /UserDefinePages/Create public ActionResult UserDefinePage(Int64?page) { ApplicationContext dbfav = new ApplicationContext(new SystemUser()); var lstFavoriteItem = dbfav.FavoriteItems.Where(p => p.LastUpdatedByUser == ((CustomPrincipal)User).Name); if (lstFavoriteItem.Count() > 0) { ViewBag.FavoriteItem = lstFavoriteItem; } if (!((CustomPrincipal)User).CanViewAdminFeature("UserInterfaceSetting")) { return(RedirectToAction("Index", "Home")); } Int64 PageId = page ?? 0; if (page == null) { if (db.UserDefinePagess.Count() > 0) { PageId = db.UserDefinePagess.ToList()[0].Id; } } var model = new EditUserDefinePageViewModel(PageId); if (PageId == 0) { UserDefinePages obj = new UserDefinePages(); obj.Id = 0; obj.PageName = "Select Page"; List <UserDefinePages> newList = new List <UserDefinePages>(); newList.Add(obj); ViewBag.UserPages = new SelectList(newList, "Id", "PageName", PageId); } else { ViewBag.UserPages = new SelectList(db.UserDefinePagess, "Id", "PageName", PageId); } if (model.Roles.Where(r => r.Selected).Count() > 0) { var roles = model.Roles.Where(r => r.Selected).Select(s => s.RoleName).ToList(); ViewBag.RoleList = String.Join(",", roles); } return(View(model)); }
// GET: /UserDefinePages/Details/5 public ActionResult Details(long?id) { if (!((CustomPrincipal)User).CanViewAdminFeature("UserInterfaceSetting")) { return(RedirectToAction("Index", "Home")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } UserDefinePages userdefinepages = db.UserDefinePagess.Find(id); if (userdefinepages == null) { return(HttpNotFound()); } return(View(userdefinepages)); }
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)); }
// GET: /UserDefinePages/Create public ActionResult SaveUserDefinePage(EditUserDefinePageViewModel model) { if (!((CustomPrincipal)User).CanAddAdminFeature("UserInterfaceSetting")) { return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { //if (model.Roles.Count() > 0) //{ var list = db.UserDefinePagess.FirstOrDefault(q => q.Id == model.Id); UserDefinePages userpages = (list != null ? list : new UserDefinePages()); userpages.PageName = model.PageName; userpages.PageContent = model.PageContent; //.Replace(" turanto-row-edit", "").Replace("turanto-row-delete", "") //var userdefinepagesrole = new UserDefinePagesRoleContext(); //userdefinepagesrole.UserDefinePagesRoles.RemoveRange(userdefinepagesrole.UserDefinePagesRoles.Where(u => u.PageId == model.Id)); //userdefinepagesrole.SaveChanges(); //foreach (var ent in model.Roles) //{ // if (ent.Selected) // { // UserDefinePagesRole objUDPR = new UserDefinePagesRole(); // objUDPR.PageId = model.Id; // objUDPR.RoleName = ent.RoleName; // userdefinepagesrole.UserDefinePagesRoles.Add(objUDPR); // userdefinepagesrole.SaveChanges(); // } //} if (list == null) { db.UserDefinePagess.Add(userpages); } db.SaveChanges(); //} return(RedirectToAction("UserDefinePage", "UserDefinePages", new { page = model.Id })); } return(View()); }
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); }