Ejemplo n.º 1
0
        public async Task <IActionResult> EditPersonal()
        {
            ViewData["Genres"] = GetGenres();
            //finds user info and sends it to view
            var user = await GetCurrentUserAsync();

            var person = new UserPersonalInputModel {
                FirstName    = user.FirstName,
                LastName     = user.LastName,
                Gender       = user.Gender,
                Birthday     = user.Birthday,
                FavoriteBook = user.FavoriteBook
            };

            var image = user.ImageUrl;

            ViewData["Image"]  = image;
            ViewData["Genres"] = GetGenres();

            return(View(person));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> EditPersonal(UserPersonalInputModel model)
        {
            ViewData["Genres"] = GetGenres();
            //if model is valid overwrite with new info and redirect to profile page
            if (ModelState.IsValid)
            {
                var user = await GetCurrentUserAsync();

                user.FirstName    = model.FirstName;
                user.LastName     = model.LastName;
                user.Gender       = model.Gender;
                user.ImageUrl     = model.ImageUrl;
                user.Birthday     = model.Birthday;
                user.FavoriteBook = model.FavoriteBook;

                await _userManager.UpdateAsync(user);

                return(RedirectToAction("Home", "Profile"));
            }
            //if model is invalid refresh page
            return(RedirectToAction("EditPersonal"));
        }