public async Task <IActionResult> EditPersonalData(EditLoggedInTouristViewModel tourist) { if (!ModelState.IsValid) { return(View(tourist)); } string email = User.Identity.Name; var touristLoggedin = await _context.Tourist.SingleOrDefaultAsync(c => c.Email == email); if (touristLoggedin == null) { return(NotFound()); } touristLoggedin.Nome = tourist.Nome; try { _context.Update(touristLoggedin); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { //todo: show error message throw; } return(RedirectToAction(nameof(Index), "Home")); }
public async Task <IActionResult> EditPersonalData() { string email = User.Identity.Name; var tourist = await _context.Tourist.SingleOrDefaultAsync(t => t.Email == email); if (tourist == null) { return(NotFound()); } EditLoggedInTouristViewModel touristInfo = new EditLoggedInTouristViewModel { Nome = tourist.Nome, Email = tourist.Email }; return(View(touristInfo)); }