public async Task <IActionResult> Edit(string email) { if (getSessionUserType() != UserType.Admin) { return(View("NotAuthorized")); } var user = await _context.User.FindAsync(email); if (user == null) { return(View("NotFound")); } ViewData["Type"] = EnumSelect.ToSelectList <UserType>(); return(View(user)); }
public async Task <IActionResult> Edit(string email, [Bind("Email,FullName,Phone,Password,Type")] User user) { if (getSessionUserType() != UserType.Admin) { return(View("NotAuthorized")); } if (email != user.Email) { return(View("NotFound")); } bool userTypeNotValid = _context.Trip.Count(t => t.GuideId == email) > 0 && user.Type == UserType.Tourist; if (userTypeNotValid) { ModelState.AddModelError("UserTypeError", "לא ניתן לשנות מדריך עם טיולים לטייל"); } if (ModelState.IsValid && !userTypeNotValid) { try { _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.Email)) { return(View("NotFound")); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Type"] = EnumSelect.ToSelectList <UserType>(); return(View(user)); }