diff --git a/0_Framework/Application/SecretKeys.cs b/0_Framework/Application/SecretKeys.cs new file mode 100644 index 00000000..02a9934d --- /dev/null +++ b/0_Framework/Application/SecretKeys.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _0_Framework.Application; + +public static class SecretKeys +{ + + public static string ProgramManagerInternalApi => "JOb09$Ic3NJd0siLCJtYWMiOiI2%dmODJmNDV"; +} \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Account/CreateAccount.cs b/AccountManagement.Application.Contracts/Account/CreateAccount.cs index da243966..e22a4f01 100644 --- a/AccountManagement.Application.Contracts/Account/CreateAccount.cs +++ b/AccountManagement.Application.Contracts/Account/CreateAccount.cs @@ -35,4 +35,9 @@ public class CreateAccount public string Email { get; set; } public string VerifyCode { get; set; } public string IsActiveString { get; set; } + + /// + /// آی کاربر در پروگرام منیجر فعالیت مبکند؟ + /// + public bool IsProgramManagerUser { get; set; } } \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Account/CreateProgramManagerUser.cs b/AccountManagement.Application.Contracts/Account/CreateProgramManagerUser.cs new file mode 100644 index 00000000..139651b1 --- /dev/null +++ b/AccountManagement.Application.Contracts/Account/CreateProgramManagerUser.cs @@ -0,0 +1,21 @@ +namespace AccountManagement.Application.Contracts.Account; + +public record CreateUserApiResponse +{ + public bool isSuccess { get; set; } + public string? errorMessage { get; set; } + + public ErrorType ErrorType { get; set; } +} +public record CreateProgramManagerUser(string FullName, string UserName, string Password, string Mobile, string? Email, long? AccountId); + + +public enum ErrorType +{ + None, + BadRequest, + NotFound, + Unauthorized, + Validation, + InternalServerError +} \ No newline at end of file diff --git a/AccountManagement.Application/AccountApplication.cs b/AccountManagement.Application/AccountApplication.cs index 74880b13..e38cb2a7 100644 --- a/AccountManagement.Application/AccountApplication.cs +++ b/AccountManagement.Application/AccountApplication.cs @@ -5,6 +5,7 @@ using AccountManagement.Application.Contracts.Account; using AccountManagement.Domain.AccountAgg; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -24,6 +25,7 @@ using AccountManagement.Domain.SubAccountAgg; using AccountManagement.Domain.SubAccountPermissionSubtitle1Agg; using AccountManagement.Domain.SubAccountRoleAgg; using Company.Domain.WorkshopSubAccountAgg; +using Newtonsoft.Json; //using AccountManagement.Domain.RoleAgg; @@ -133,12 +135,43 @@ public class AccountApplication : IAccountApplication var password = _passwordHasher.Hash(command.Password); var roleName = _roleRepository.GetDetails(command.RoleId); var path = $"profilePhotos"; + var picturePath = ""; if (_fileUploader != null) { - var picturePath = _fileUploader.Upload(command.ProfilePhoto, path); - var account = new Account(command.Fullname, command.Username, password, command.Mobile, command.RoleId, - picturePath, roleName.Name,"true","false"); - _accountRepository.Create(account); + picturePath = _fileUploader.Upload(command.ProfilePhoto, path); + + } + var account = new Account(command.Fullname, command.Username, password, command.Mobile, command.RoleId, + picturePath, roleName.Name, "true", "false"); + _accountRepository.Create(account); + + + if (command.IsProgramManagerUser) + { + var parameters = new CreateProgramManagerUser(command.Fullname, command.Username, password, command.Mobile, + command.Email, account.id); + var key = SecretKeys.ProgramManagerInternalApi; + var client = new HttpClient(); + var request = new HttpRequestMessage(HttpMethod.Post, $"https://localhost:7032/api/user/{parameters}"); + request.Headers.Add("X-INTERNAL-KEY", key); + var response = client.SendAsync(request).GetAwaiter().GetResult(); + var success = response.IsSuccessStatusCode; + if (success) + { + var res = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); + var result = JsonConvert.DeserializeObject(res); + + if (!result.isSuccess) + { + return operation.Failed(result.errorMessage); + } + + //Console.WriteLine(result.Data.accountId + " " + result.Data.mobile); + } + else + { + return operation.Failed("خطا در ایجاد کاربر پروگرام منیجر"); + } } _accountRepository.SaveChanges(); diff --git a/ServiceHost/Areas/Admin/Pages/Accounts/Account/Create.cshtml b/ServiceHost/Areas/Admin/Pages/Accounts/Account/Create.cshtml index 113c9545..53054659 100644 --- a/ServiceHost/Areas/Admin/Pages/Accounts/Account/Create.cshtml +++ b/ServiceHost/Areas/Admin/Pages/Accounts/Account/Create.cshtml @@ -1,6 +1,53 @@ @model AccountManagement.Application.Contracts.Account.CreateAccount @{ + } - +
+ +
+ آیا کاربر در پروگرام منیجر هم فعالیت میکند؟ +   + +
+
diff --git a/ServiceHost/Pages/Index.cshtml.cs b/ServiceHost/Pages/Index.cshtml.cs index 7ede123f..20c52fa3 100644 --- a/ServiceHost/Pages/Index.cshtml.cs +++ b/ServiceHost/Pages/Index.cshtml.cs @@ -3,6 +3,8 @@ using Microsoft.AspNetCore.Mvc.RazorPages; using System.Security.Claims; using _0_Framework.Application; using AccountManagement.Application.Contracts.Account; +using CompanyManagment.App.Contracts.Holiday; +using Newtonsoft.Json; namespace ServiceHost.Pages { @@ -19,7 +21,19 @@ namespace ServiceHost.Pages public IActionResult OnGet() { - if(_authHelper.IsAuthenticated()) + //var client = new HttpClient(); + //var request = new HttpRequestMessage(HttpMethod.Get, $"https://localhost:7032/api/user/2"); + //request.Headers.Add("X-INTERNAL-KEY", "MY_SUPER_SECRET_3456"); + //var response = client.SendAsync(request).GetAwaiter().GetResult(); + //var success = response.IsSuccessStatusCode; + //if (success) + //{ + // var res = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); + // var result = JsonConvert.DeserializeObject(res); + + // Console.WriteLine(result.Data.accountId + " " + result.Data.mobile); + //} + if (_authHelper.IsAuthenticated()) return Redirect("/login"); return Page(); } @@ -30,4 +44,52 @@ namespace ServiceHost.Pages return RedirectToPage("/Index"); } } -} \ No newline at end of file +} + +public record SingleUserRespnsResult +{ + public bool isSuccess { get; set; } + public Data Data { get; set; } +} +public record Data + +{ + public long id { get; set; } + /// + /// نام و نام خانوادگی + /// + public string fullName { get; set; } + + /// + /// نام کاربری + /// + public string userName { get; set; } + + + + /// + /// مسیر عکس پروفایل + /// + public string profilePhotoPath { get; set; } + + /// + /// شماره موبایل + /// + public string mobile { get; set; } + + + /// + /// فعال/غیر فعال بودن یوزر + /// + public bool isActive { get; set; } + + /// + /// گذرواژه + /// + public string password { get; set; } + + /// + /// ای دی اکانت کاربر در گزارشگیر + /// + public long? accountId { get; set; } +}