Пример #1
0
        public ActionResult Profile(ProfileViewModel model)
        {
            DateTime? birthdate = null;
            if (model.Day.HasValue || model.Month.HasValue || model.Year.HasValue)
            {
                if (!(model.Day.HasValue && model.Month.HasValue && model.Year.HasValue))
                    ModelState.AddModelError("Birthdate", "Enter the month, day and year of your birthdate.");
                else
                {
                    try
                    {
                        birthdate = new DateTime(model.Year.Value, model.Month.Value, model.Day.Value);
                    }
                    catch
                    {
                        ModelState.AddModelError("Birthdate", "Enter a valid month, day and year.");
                    }
                }
            }

            if (model.ThemeID.HasValue)
            {
                var themes = _themeServices.GetVisibleThemes();
                if (themes.FirstOrDefault(item => item.ThemeID == model.ThemeID) == null)
                    ModelState.AddModelError("ThemeID", "Invalid theme");
            }

            if (model.DefaultRankRole.HasValue)
            {
                var roles = _roleServices.GetUserRoleRanks(CurrentUser.UserID);
                if (roles.FirstOrDefault(item => item.RoleID == model.DefaultRankRole) == null)
                    ModelState.AddModelError("DefaultRankRole", "Invalid role");
            }

            if (IsModelValidAndPersistErrors())
            {
                SetSuccess("Profile updated");
                _userServices.UpdateProfile(
                    CurrentUser.UserID,
                    model.AlwaysShowSignature,
                    model.AlwaysSubscribeToThread,
                    model.Location,
                    model.ThemeID,
                    model.DefaultRankRole,
                    model.AIM,
                    model.ICQ,
                    model.MSN,
                    model.Website,
                    birthdate);
            }

            return RedirectToSelf();
        }
Пример #2
0
        public ActionResult Profile()
        {
            SetBreadCrumb("Modify Profile");

            var profile = CurrentUser.UserProfile;

            // WTB Automapper 5k gold
            var model = new ProfileViewModel()
            {
                AIM = profile.AIM,
                AlwaysShowSignature = profile.AlwaysShowSignature,
                AlwaysSubscribeToThread = profile.AlwaysSubscribeToThread,
                Birthdate = profile.Birthdate,
                CanSelectTheme = !SiteConfig.OverrideUserTheme.ToBool(),
                Day = profile.Birthdate.HasValue ? profile.Birthdate.Value.Day : new Nullable<int>(),
                Month = profile.Birthdate.HasValue ? profile.Birthdate.Value.Month : new Nullable<int>(),
                Year = profile.Birthdate.HasValue ? profile.Birthdate.Value.Year : new Nullable<int>(),
                DefaultRankRole = profile.DefaultRole,
                ICQ = profile.ICQ,
                Location = profile.Location,
                MSN = profile.MSN,
                RankRoles = _roleServices.GetUserRoleRanks(CurrentUser.UserID),
                ThemeID = profile.ThemeID,
                Themes = _themeServices.GetVisibleThemes(),
                Website = profile.Website,
            };

            return View(model);
        }