Exemplo n.º 1
0
        public ActionResult Create(Section entry)
        {
            bool hasPermissions = sectionRpstry.GetPermission(sectionName, loggedUser.UserId, canCreate);

            if (hasPermissions)
            {
                try
                {
                    entry.dateCreated  = DateTime.Now;
                    entry.dateModified = DateTime.Now;
                    entry.priority     = rpstry.GetMaxPriority() + 1;
                    rpstry.Add(entry);
                    rpstry.Save();

                    #region Manage Permissions
                    var allPermissions = Request.Form.AllKeys.Where(n => n.StartsWith("permission_"));
                    rpstry.DeleteAllBySection(entry.id);
                    rpstry.Save();
                    foreach (var item in allPermissions)
                    {
                        int      roleId             = Convert.ToInt32(item.ToString().Replace("permission_", ""));
                        string[] permissiontypesIds = Request.Form.GetValues(item.ToString());
                        rpstry.ManagePermissions(entry.id, roleId, permissiontypesIds);
                    }
                    #endregion

                    return(RedirectToAction("Index", new { thisid = entry.id }));
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", "");
                    return(View(entry));
                }
            }
            else
            {
                return(View("Error", "You do not have permissions to access this section."));
            }
        }