Skip to content

Commit

Permalink
Merge pull request #98 from SiMENhol/Kommentarer-til-AdminController
Browse files Browse the repository at this point in the history
kommentarer til admin - sjekk de ut
  • Loading branch information
ToBeAss authored Nov 26, 2023
2 parents 8eacdcb + 3bce310 commit 1c3e21c
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Igland.MVC/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public AdminController(UserManager<IdentityUser> userManager, ILogger<AdminContr
_logger = logger;
}

/// <summary>
/// Creates a UserViewModel object with a list of all users and the specified user's information if provided.
/// </summary>
/// <param name="email">The email address of the user to retrieve information for.</param>
/// <returns>A UserViewModel object containing the list of users and the specified user's information.</returns>
private UserViewModel CreateUserViewModel(string? email)
{
var model = new UserViewModel { Users = userRepository.GetUsers() };
Expand All @@ -40,6 +45,9 @@ private UserViewModel CreateUserViewModel(string? email)
return model;
}

/// <summary>
/// Displays the administrator's homepage.
/// </summary>
[HttpGet]
public IActionResult Index(string? email)
{
Expand All @@ -48,6 +56,9 @@ public IActionResult Index(string? email)
return View(model);
}

/// <summary>
/// Displays an overview of all users in the system.
/// </summary>
[HttpGet]
public IActionResult Oversikt(string? email)
{
Expand All @@ -56,13 +67,19 @@ public IActionResult Oversikt(string? email)
return View(model);
}

/// <summary>
/// Displays the registration page for new users.
/// </summary>
[HttpGet]
public IActionResult Register(string returnUrl = null)

Check warning on line 74 in Igland.MVC/Controllers/AdminController.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
ViewData["ReturnUrl"] = returnUrl;
return View();
}

/// <summary>
/// Handles the registration process for a new user. Validates user input, creates a new user account, and redirects to the overview page upon successful registration. Otherwise, re-displays the registration page with error messages.
/// </summary>
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Register(RegisterViewModel model, string returnUrl = null)

Check warning on line 85 in Igland.MVC/Controllers/AdminController.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
Expand All @@ -82,7 +99,10 @@ public async Task<IActionResult> Register(RegisterViewModel model, string return
}
return View(model);
}


/// <summary>
/// Removes a user from the database based on the provided email address. Logs the action and redirects to the overview page upon successful deletion.
/// </summary>
[HttpPost]
public IActionResult Delete(string email)
{
Expand All @@ -91,6 +111,9 @@ public IActionResult Delete(string email)
return RedirectToAction("Oversikt");
}

/// <summary>
/// Promotes a user to the Administrator role by adding them to the corresponding role in the identity system.
/// </summary>
public async Task<IActionResult> MakeUserAdministrator(string userId)
{
var user = await _userManager.FindByIdAsync(userId);
Expand Down

0 comments on commit 1c3e21c

Please sign in to comment.