Esempio n. 1
0
        public ActionResult ChangeName(User user)
        {
            string userID     = GetUserID();
            User   oldInfo    = userSql.GetUserByID(userID);
            bool   nameExists = userSql.CheckForName(user.DisplayName);

            var displayName = ModelState["DisplayName"];

            if (displayName == null || displayName.Errors.Any())
            {
                TempData["change-error"] = "Invalid Input: Your name hasn't been changed.";
                return(View("ChangeUserInfo", oldInfo));
            }
            else if (nameExists)
            {
                if (user.DisplayName != oldInfo.DisplayName)
                {
                    TempData["change-error"] = "Sorry, that name is already in use by a different user.";
                }
                return(View("ChangeUserInfo", oldInfo));
            }
            userSql.UpdateName(user.DisplayName, userID);
            user = userSql.GetUserByID(userID);

            TempData["change-success"] = "Name changed successfully";
            return(RedirectToAction("ChangeInfoInit", user));
        }