Пример #1
0
        public ActionResult Update()
        {
            var user = this.UserService.GetById(Identity.Id);

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

            var privilege = new UserPrivilege();

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

            var value = new UserPreferenceUpdate(user.Preference);

            value.Initialize();

            return base.View(Views.Update, value);
        }
Пример #2
0
        public ActionResult Update(UserPreferenceUpdate value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var user = this.UserService.GetById(Identity.Id);

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

            var privilege = new UserPrivilege();

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

            value.Initialize();
            value.Validate();

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

                this.UserService.UpdatePreference(user.Preference);

                value.SuccessMessage(Messages.UserAccountPreferenceUpdated);
            }
            else
            {
                value.CopyToModel(ModelState);
            }

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