예제 #1
0
        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"));
        }
예제 #2
0
 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));
 }
예제 #3
0
        // 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));
        }
예제 #4
0
        // 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));
        }
예제 #5
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());
        }
예제 #6
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));
        }
예제 #7
0
 // 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());
 }
예제 #8
0
        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);
        }