Esempio n. 1
0
        public ActionResult Create()
        {
            var user = this.UserService.Create();
            var privilege = new UserPrivilege();

            return privilege.CanCreate(user) ? View(Views.Create, new UserAdminCreate()) : NotAuthorized();
        }
Esempio n. 2
0
        public ActionResult Create(UserAdminCreate value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var user = this.UserService.Create();
            var privilege = new UserPrivilege();

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

            value.Validate();

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

                this.UserService.Insert(user, value.Preference);

                var model = new UserAdminUpdate(user);

                model.SuccessMessage(Messages.UserCreated.FormatInvariant(user.Name));

                return base.View(Views.Update, model);
            }

            value.CopyToModel(ModelState);

            return base.View(Views.Create, value);
        }