Beispiel #1
0
        public async Task <IActionResult> ChangePersonalInformation()
        {
            var user = await GetCurrentUserAsync();

            if (user == null)
            {
                return(View("Error"));
            }

            var model = new ChangePersonalInformationViewModel
            {
                Birthday = user.Birthday,
                Sex      = user.Sex,
            };

            return(View(model));
        }
Beispiel #2
0
        public async Task <IActionResult> ChangePersonalInformation(ChangePersonalInformationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await GetCurrentUserAsync();

            if (user != null)
            {
                // Overwrites values in currently logged in user to match the new data
                user.Sex      = model.Sex;
                user.Birthday = model.Birthday;

                // Saves changes
                _context.Update(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index), new { Message = ManageMessageId.ChangePersonalInformationSuccess }));
            }
            return(RedirectToAction(nameof(Index), new { Message = ManageMessageId.Error }));
        }