public async Task <IActionResult> CaptureUserDetails(UserDetailsViewModels userDetailsViewModels) { if (ModelState.IsValid) { var addUserDetails = await userManager.GetUserAsync(HttpContext.User); if (addUserDetails == null) { ViewBag.ErrorMessage = $"User with Id = {addUserDetails} cannot be found"; return(RedirectToAction("Index", "Home")); } addUserDetails.PhoneNumber = userDetailsViewModels.PhoneNumber; addUserDetails.SurName = userDetailsViewModels.FamilyName; addUserDetails.Name = userDetailsViewModels.Name; addUserDetails.BooksBought = userDetailsViewModels.Books; addUserDetails.Adress = userDetailsViewModels.Adress; addUserDetails.City = userDetailsViewModels.City; addUserDetails.Country = userDetailsViewModels.Country; addUserDetails.Age = userDetailsViewModels.Age; var user = await userManager.UpdateAsync(addUserDetails); if (user.Succeeded) { return(RedirectToAction("ShowUserDetails", "UserDetails")); } foreach (var error in user.Errors) { ModelState.AddModelError("", error.Description); // add errors to ModelStats } } return(View(userDetailsViewModels)); }
public async Task <IActionResult> ShowUserDetails() { if (signInManager.IsSignedIn(User)) { //check if has the user values entered all the fields, if not redirect to CaptureDetails //must return the values from the database in here //example homecontroller var userData = await userManager.GetUserAsync(HttpContext.User); if (string.IsNullOrEmpty(userData.SurName) || string.IsNullOrEmpty(userData.Name) || string.IsNullOrEmpty(userData.PhoneNumber) || string.IsNullOrEmpty(userData.Adress) || ((userData.Age == 0) || (userData.City == 0) || (userData.Country == 0))) { return(RedirectToAction("CaptureUserDetails", "UserDetails")); } UserDetailsViewModels userDetailsViewModels = new UserDetailsViewModels() { PhoneNumber = userData.PhoneNumber, Books = userData.BooksBought, City = userData.City, Country = userData.Country, Email = userData.Email, Age = userData.Age, FamilyName = userData.SurName, Name = userData.Name, Adress = userData.Adress }; return(View(userDetailsViewModels)); } else { RedirectToAction("LogIn", "Account"); } return(View()); }