Esempio n. 1
0
        public ActionResult Create()
        {
            var role = this.UserRoleService.Create();
            var privilege = new UserRolePrivilege();

            return privilege.CanCreate(role) ? base.View(Views.Create, new UserRoleCreateOrUpdate()) : NotAuthorized();
        }
Esempio n. 2
0
        public ActionResult Create(UserRoleCreateOrUpdate value, IList<UserRoleRelationUpdateValue> privileges)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var role = this.UserRoleService.Create();
            var privilege = new UserRolePrivilege();

            if (!privilege.CanCreate(role))
            {
                return NotAuthorized();
            }

            value.Validate();

            if (value.IsValid)
            {
                value.ValueToModel(role);

                this.UserRoleService.InsertOrUpdate(role, privileges);

                value = new UserRoleCreateOrUpdate(role);
                value.SuccessMessage(Messages.UserRoleCreated.FormatInvariant(role.Title));
            }
            else
            {
                value.CopyToModel(ModelState);
            }

            return base.View(Views.Update, value);
        }
Esempio n. 3
0
        public ActionResult Index()
        {
            var roles = this.UserRoleService.GetAll();
            var role = roles.FirstOrDefault();
            var privilege = new UserRolePrivilege();

            return privilege.CanView(role) ? base.View(Views.Index, roles) : NotAuthorized();
        }
Esempio n. 4
0
        public ActionResult Update(int id)
        {
            var role = this.UserRoleService.GetById(id);

            if (role == null)
            {
                return base.HttpNotFound();
            }

            var privilege = new UserRolePrivilege();

            return privilege.CanUpdate(role) ? base.View(Views.Update, new UserRoleCreateOrUpdate(role)) : NotAuthorized();
        }
Esempio n. 5
0
        public ActionResult Delete(UserRoleDelete value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var role = this.UserRoleService.GetById(value.Id);

            if (role == null)
            {
                return base.HttpNotFound();
            }

            var privilege = new UserRolePrivilege();

            if (!privilege.CanDelete(role))
            {
                return NotAuthorized();
            }

            this.UserRoleService.Delete(role);

            return base.RedirectToRoute(UsersAdministrationRoutes.RoleIndex);
        }