From 0725e4f7cf4c6f723264b6d461b91c660d144cb7 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Sun, 30 Oct 2022 22:40:03 +0700 Subject: feat: Apiwork --- .../Internal/Account/CreateInitialAccountRoute.cs | 52 +++++++++++----------- 1 file changed, 25 insertions(+), 27 deletions(-) (limited to 'code/api/src/Endpoints/Internal/Account/CreateInitialAccountRoute.cs') diff --git a/code/api/src/Endpoints/Internal/Account/CreateInitialAccountRoute.cs b/code/api/src/Endpoints/Internal/Account/CreateInitialAccountRoute.cs index 13fbdf4..56ff9c6 100644 --- a/code/api/src/Endpoints/Internal/Account/CreateInitialAccountRoute.cs +++ b/code/api/src/Endpoints/Internal/Account/CreateInitialAccountRoute.cs @@ -1,34 +1,32 @@ namespace IOL.GreatOffice.Api.Endpoints.Internal.Account; -/// public class CreateInitialAccountRoute : RouteBaseAsync.WithoutRequest.WithActionResult { - private readonly AppDbContext _context; - private readonly UserService _userService; + private readonly MainAppDatabase _database; + private readonly UserService _userService; - /// - public CreateInitialAccountRoute(AppDbContext context, UserService userService) { - _context = context; - _userService = userService; - } + public CreateInitialAccountRoute(MainAppDatabase database, UserService userService) { + _database = database; + _userService = userService; + } - /// - /// Create an initial user account. - /// - /// - /// - [AllowAnonymous] - [HttpGet("~/_/account/create-initial")] - public override async Task HandleAsync(CancellationToken cancellationToken = default) { - if (_context.Users.Any()) { - return NotFound(); - } + /// + /// Create an initial user account. + /// + /// + /// + [AllowAnonymous] + [HttpGet("~/_/account/create-initial")] + public override async Task HandleAsync(CancellationToken cancellationToken = default) { + if (_database.Users.Any()) { + return NotFound(); + } - var user = new User("admin@ivarlovlie.no"); - user.HashAndSetPassword("ivar123"); - _context.Users.Add(user); - await _context.SaveChangesAsync(cancellationToken); - await _userService.LogInUser(HttpContext, user); - return Redirect("/"); - } -} + var user = new User("admin@ivarlovlie.no"); + user.HashAndSetPassword("ivar123"); + _database.Users.Add(user); + await _database.SaveChangesAsync(cancellationToken); + await _userService.LogInUser(HttpContext, user); + return Redirect("/"); + } +} \ No newline at end of file -- cgit v1.3