Skip to content

Commit 2a35a4d

Browse files
igeligelMarvin Perez
authored andcommitted
Refactor API (AccountGo#73)
* Remove non used services and managers removed unused signinmanager and security service out of the AccountController * Use Object initializers and refactor string array * Delete unused else * Return the right audit dto and fix intendation use the right audit dto to return, use linq and object initializer to create the instance of auditlogsdto and fix general intendation with ctrl+k+d * Fix style and refactor initialization Improve if-else's and use object initializer * Refactor Administration controller Used var type for clear data types and refactored the initializing data method into several methods about the context. Also refactored those methods
1 parent b819a1f commit 2a35a4d

2 files changed

Lines changed: 604 additions & 527 deletions

File tree

src/Api/Controllers/AccountController.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Api.Data;
1+
using Api.Data;
22
using Microsoft.AspNetCore.Identity;
33
using Microsoft.AspNetCore.Mvc;
44
using Services.Administration;
@@ -10,9 +10,7 @@ namespace Api.Controllers
1010
public class AccountController : BaseController
1111
{
1212
private readonly UserManager<ApplicationUser> _userManager;
13-
private readonly SignInManager<ApplicationUser> _signInManager;
1413
private readonly IAdministrationService _administrationService;
15-
private readonly ISecurityService _securityService;
1614

1715
public AccountController(
1816
UserManager<ApplicationUser> userManager,
@@ -22,9 +20,7 @@ ISecurityService securityService
2220
)
2321
{
2422
_userManager = userManager;
25-
_signInManager = signInManager;
2623
_administrationService = administrationService;
27-
_securityService = securityService;
2824
}
2925

3026
[HttpPost]
@@ -76,7 +72,6 @@ public async System.Threading.Tasks.Task<IActionResult> SignIn([FromBody]dynamic
7672
[Route("[action]")]
7773
public async System.Threading.Tasks.Task<IActionResult> AddNewUser([FromBody]dynamic registerViewModel)
7874
{
79-
string[] errors = null;
8075
try
8176
{
8277
if (registerViewModel == null)
@@ -93,24 +88,24 @@ public async System.Threading.Tasks.Task<IActionResult> AddNewUser([FromBody]dyn
9388
var result = await _userManager.CreateAsync(user, password);
9489
if (result.Succeeded)
9590
{
96-
Core.Domain.Security.User newUser = new Core.Domain.Security.User();
97-
newUser.EmailAddress = username;
98-
newUser.UserName = username;
99-
newUser.Firstname = firstName;
100-
newUser.Lastname = lastName;
91+
Core.Domain.Security.User newUser =
92+
new Core.Domain.Security.User
93+
{
94+
EmailAddress = username,
95+
UserName = username,
96+
Firstname = firstName,
97+
Lastname = lastName
98+
};
10199

102100
_administrationService.SaveUser(newUser);
103101

104102
return new ObjectResult(result);
105103
}
106-
else
107-
{
108-
return new BadRequestObjectResult(result);
109-
}
104+
return new BadRequestObjectResult(result);
110105
}
111106
catch(System.Exception ex)
112107
{
113-
errors = new string[1] { ex.InnerException != null ? ex.InnerException.Message : ex.Message };
108+
var errors = new[] { ex.InnerException != null ? ex.InnerException.Message : ex.Message };
114109
return new BadRequestObjectResult(errors);
115110
}
116111
}

0 commit comments

Comments
 (0)