summaryrefslogtreecommitdiff
path: root/Logics/CreateUserAccountLogic.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Logics/CreateUserAccountLogic.cs')
-rw-r--r--Logics/CreateUserAccountLogic.cs39
1 files changed, 39 insertions, 0 deletions
diff --git a/Logics/CreateUserAccountLogic.cs b/Logics/CreateUserAccountLogic.cs
new file mode 100644
index 0000000..dd37837
--- /dev/null
+++ b/Logics/CreateUserAccountLogic.cs
@@ -0,0 +1,39 @@
+using AutoMapper;
+using Microsoft.AspNetCore.Identity;
+using BackendPIA.Services;
+using BackendPIA.Models;
+using BackendPIA.Forms;
+
+namespace BackendPIA.Logics{
+ public class CreateUserAccountLogic : BaseUserAccountLogic {
+ private readonly UserAccountForm _form;
+ private readonly IMapper _mapper;
+ private readonly IUserAccountService _user_account_service;
+ private readonly string _role;
+ private IEnumerable<IdentityError>? _errors;
+ public IEnumerable<IdentityError>? Errors { get => _errors; }
+
+ public CreateUserAccountLogic(ITokenGenerator token_generator, UserManager<UserAccount> manager, UserAccountForm form,
+ IMapper mapper, IUserAccountService service, string role) : base(token_generator, manager)
+ {
+ _form = form;
+ _mapper = mapper;
+ _user_account_service = service;
+ _role = role;
+ }
+
+ public async Task<bool> Call() {
+ UserAccount user = _mapper.Map<UserAccount>(_form);
+ var result = await _user_account_service.CreateUserAccount(user, _form.Password, _role);
+
+ if(result.Succeeded) {
+ await SetAuthenticationToken(user);
+
+ return true;
+ }
+
+ _errors = result.Errors;
+ return false;
+ }
+ }
+} \ No newline at end of file