From 733fdd24847c5c97b4ee7ad6f3b8fa7b11eb955d Mon Sep 17 00:00:00 2001 From: "jozsef.b@aycode.com" <9Rj@D}fVwBaN> Date: Tue, 19 Dec 2023 00:19:08 +0100 Subject: [PATCH] improvements, fixes... --- TIAM.Database.Test/UserDalTests.cs | 5 +- TIAM.Database/DataLayers/Users/UserDal.cs | 5 +- .../DbSets/Users/UserDbSetExtensions.cs | 4 ++ .../Services/UserDataServiceMobile.cs | 11 ++-- TIAMSharedUI/Pages/AppLaunch.razor | 2 +- .../Pages/Components/AuctionStep1.razor | 2 +- .../Pages/Components/InputWizard.razor | 2 +- .../Pages/Components/InputWizard.razor.cs | 64 ++++++++++--------- .../Pages/Components/TransferStep1.razor | 2 +- TIAMSharedUI/Pages/DbTestComponent.razor | 7 +- TIAMSharedUI/Pages/DbTestComponent.razor.cs | 3 +- TIAMSharedUI/Pages/TestPage.razor | 2 +- TIAMSharedUI/TIAMSharedUI.csproj | 11 ++++ .../Client/Services/UserDataServiceWeb.cs | 31 ++++----- .../Server/Controllers/UserAPIController.cs | 20 +++--- .../Shared/Interfaces/IUserDataService.cs | 5 +- TIAMWebApp/Shared/Models/UserSessionModel.cs | 8 ++- .../TIAMWebApp.Shared.Application.csproj | 1 + TourIAmProject.sln | 12 +++- 19 files changed, 117 insertions(+), 80 deletions(-) diff --git a/TIAM.Database.Test/UserDalTests.cs b/TIAM.Database.Test/UserDalTests.cs index a35e0586..708f55a2 100644 --- a/TIAM.Database.Test/UserDalTests.cs +++ b/TIAM.Database.Test/UserDalTests.cs @@ -54,7 +54,7 @@ namespace TIAM.Database.Test [TestMethod] [DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")] - public void SerializeUserModelDto_ReturnDeserializedUser_WhenUserAndRelationsExists(string userIdString) + public async Task SerializeUserModelDto_ReturnDeserializedUser_WhenUserAndRelationsExists(string userIdString) { var userId = Guid.Parse(userIdString); @@ -64,12 +64,13 @@ namespace TIAM.Database.Test NullValueHandling = NullValueHandling.Ignore }; - var userModel = Dal.GetUserModelDtoById(userId); + var userModel = await Dal.GetUserModelDtoByIdAsync(userId).ConfigureAwait(false); var serializedUserModel = JsonConvert.SerializeObject(userModel, options); userModel = JsonConvert.DeserializeObject(serializedUserModel); Assert.IsNotNull(userModel); + Assert.IsNotNull(userModel.UserDto); Assert.IsNotNull(userModel.Profile); Assert.IsTrue(userModel.Products.Count > 0); diff --git a/TIAM.Database/DataLayers/Users/UserDal.cs b/TIAM.Database/DataLayers/Users/UserDal.cs index d9b73663..79ae65f7 100644 --- a/TIAM.Database/DataLayers/Users/UserDal.cs +++ b/TIAM.Database/DataLayers/Users/UserDal.cs @@ -32,8 +32,9 @@ namespace TIAM.Database.DataLayers.Users return Context.Users.ToListAsync(); } - public UserModelDto? GetUserModelDtoById(Guid userId) => Session(x => x.GetUserModelDtoById(userId)); - public UserModelDto? GetUserModelDtoByEmail(string email) => Session(x => x.GetUserModelDtoByEmail(email)); + public Task GetUserModelDtoByIdAsync(Guid userId) => SessionAsync(x => x.GetUserModelDtoById(userId)); + public Task GetUserModelDtoByEmailAsync(string email) => SessionAsync(x => x.GetUserModelDtoByEmail(email)); + public Task> GetAllUsersModelDtoAsync() => SessionAsync(x => x.GetAllUsersModelDto().ToList()); public Task GetUserByPhoneNumberAsync(string phoneNumber) { diff --git a/TIAM.Database/DbSets/Users/UserDbSetExtensions.cs b/TIAM.Database/DbSets/Users/UserDbSetExtensions.cs index 92f7eb40..fd903e6b 100644 --- a/TIAM.Database/DbSets/Users/UserDbSetExtensions.cs +++ b/TIAM.Database/DbSets/Users/UserDbSetExtensions.cs @@ -26,4 +26,8 @@ public static class UserDbSetExtensions public static UserModelDto? GetUserModelDtoByEmail(this IUserDbSet ctx, string email) => ctx.GetUsersByEmail(email).Select(x => new UserModelDto(x, x.Profile, x.UserProductMappings, x.Products)).FirstOrDefault(); + + public static IQueryable GetAllUsersModelDto(this IUserDbSet ctx) + => ctx.Users.Select(x => new UserModelDto(x, x.Profile, x.UserProductMappings, x.Products)); + } \ No newline at end of file diff --git a/TIAMMobileApp/Services/UserDataServiceMobile.cs b/TIAMMobileApp/Services/UserDataServiceMobile.cs index 0ea8f405..9fd69ed4 100644 --- a/TIAMMobileApp/Services/UserDataServiceMobile.cs +++ b/TIAMMobileApp/Services/UserDataServiceMobile.cs @@ -3,6 +3,7 @@ using System.Text; using AyCode.Interfaces.StorageHandlers; using Newtonsoft.Json; using TIAM.Entities.Users; +using TIAM.Models.Dtos.Users; using TIAMWebApp.Shared.Application.Interfaces; using TIAMWebApp.Shared.Application.Models; using TIAMWebApp.Shared.Application.Models.ClientSide; @@ -49,7 +50,7 @@ namespace TIAMMobileApp.Services { var hasProperties = await _serviceProviderDataService.GetPropertiesByOwnerIdAsync(dbUser.Id); - var user = new UserSessionModel(dbUser.Id, UserType.User, dbUser.EmailAddress, hasProperties, 1); + var user = new UserSessionModel(dbUser.Id, UserType.User, dbUser.Profile?.Name, hasProperties, 1); return user; } @@ -117,14 +118,14 @@ namespace TIAMMobileApp.Services return (isSuccess, result); } - public async Task?> GetUsersAsync() + public async Task?> GetUsersAsync() { - return await http.GetFromJsonAsync>(APIUrls.GetUsers); + return await http.GetFromJsonAsync>(APIUrls.GetUsers); } - public async Task GetUserByEmailAsync(string email) + public async Task GetUserByEmailAsync(string email) { - return await http.GetFromJsonAsync(APIUrls.GetUserByEmail); + return await http.GetFromJsonAsync(APIUrls.GetUserByEmail); } public async Task GetUserByIdAsync(Guid Id) { diff --git a/TIAMSharedUI/Pages/AppLaunch.razor b/TIAMSharedUI/Pages/AppLaunch.razor index edddb85c..412c987e 100644 --- a/TIAMSharedUI/Pages/AppLaunch.razor +++ b/TIAMSharedUI/Pages/AppLaunch.razor @@ -85,7 +85,7 @@ Loading.... string _email = jsontoken.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.Email).Value; var user = await UserDataService.IsLoggedInAsync(Guid.Parse(_userId)); sessionService.User = user; - logToBrowserConsole.LogToBC($"Saved user in db is: {user.Email}, setting autenthicated state"); + logToBrowserConsole.LogToBC($"Saved user in db is: {user.DisplayName}, setting autenthicated state"); sessionService.IsAuthenticated = true; NavManager.NavigateTo("/index"); } diff --git a/TIAMSharedUI/Pages/Components/AuctionStep1.razor b/TIAMSharedUI/Pages/Components/AuctionStep1.razor index 09807b1b..cd8fb15e 100644 --- a/TIAMSharedUI/Pages/Components/AuctionStep1.razor +++ b/TIAMSharedUI/Pages/Components/AuctionStep1.razor @@ -66,7 +66,7 @@ protected override async Task OnInitializedAsync() { - Email = sessionService.User.Email; + Email = sessionService.User.DisplayName; await base.OnInitializedAsync(); } diff --git a/TIAMSharedUI/Pages/Components/InputWizard.razor b/TIAMSharedUI/Pages/Components/InputWizard.razor index 3a4b9408..0eac3f89 100644 --- a/TIAMSharedUI/Pages/Components/InputWizard.razor +++ b/TIAMSharedUI/Pages/Components/InputWizard.razor @@ -25,7 +25,7 @@

@Localizer.GetString("DestinationName")

- @FormSubmitResult + @_formSubmitResult

@code { diff --git a/TIAMSharedUI/Pages/Components/InputWizard.razor.cs b/TIAMSharedUI/Pages/Components/InputWizard.razor.cs index 0fccbc97..8646c63b 100644 --- a/TIAMSharedUI/Pages/Components/InputWizard.razor.cs +++ b/TIAMSharedUI/Pages/Components/InputWizard.razor.cs @@ -16,7 +16,7 @@ namespace TIAMSharedUI.Pages.Components public partial class InputWizard : ComponentBase { [Inject] - LogToBrowserConsole logToBrowserConsole { get; set; } + public required LogToBrowserConsole LogToBrowserConsole { get; set; } public Dictionary FormSteps { get; set; } = new Dictionary(); public int CurrentStep { get; set; } = 0; @@ -28,37 +28,37 @@ namespace TIAMSharedUI.Pages.Components public object Data { get; set; } = new object(); [Parameter] - public EventCallback onSubmit { get; set; } + public EventCallback OnSubmit { get; set; } - string PhoneMask { get; set; } = "(999)000-0000"; - string FormSubmitResult = ""; - private string spinnerClass = ""; + string _phoneMask = "(999)000-0000"; + string _formSubmitResult = ""; + private string _spinnerClass = ""; async Task HandleValidSubmit() { - spinnerClass = "spinner-border spinner-border-sm"; + _spinnerClass = "spinner-border spinner-border-sm"; await Task.Delay(500); - FormSubmitResult = "You have been registred successully."; - spinnerClass = ""; + _formSubmitResult = "You have been registred successully."; + _spinnerClass = ""; - await onSubmit.InvokeAsync(Data); + await OnSubmit.InvokeAsync(Data); } void HandleInvalidSubmit() { - FormSubmitResult = "Please correct all errors"; + _formSubmitResult = "Please correct all errors"; } public void OnNext(MouseEventArgs args) { - logToBrowserConsole.LogToBC("OnNext called"); + LogToBrowserConsole.LogToBC("OnNext called"); CurrentStep++; } public void OnPrevious(MouseEventArgs args) { - logToBrowserConsole.LogToBC("OnPrev called"); + LogToBrowserConsole.LogToBC("OnPrev called"); CurrentStep--; } @@ -66,7 +66,7 @@ namespace TIAMSharedUI.Pages.Components { var _type = Data.GetType(); - logToBrowserConsole.LogToBC("Hellooooo " + _type.AssemblyQualifiedName); + LogToBrowserConsole.LogToBC("Hellooooo " + _type.AssemblyQualifiedName); var propertyList = _type.GetProperties(); //var propertyList = typeof(TestUserData).GetProperties(); @@ -100,7 +100,7 @@ namespace TIAMSharedUI.Pages.Components var access = Expression.Property(Expression.Constant(Data), property.Name); var lambda = Expression.Lambda(typeof(Func<>).MakeGenericType(property.PropertyType), access); - logToBrowserConsole.LogToBC(lambda.ToString()); + LogToBrowserConsole.LogToBC(lambda.ToString()); layoutItemBuilder.OpenElement(i++, "div");//open div layoutItemBuilder.AddAttribute(i++, "id", _stepID.ToString()); @@ -116,7 +116,7 @@ namespace TIAMSharedUI.Pages.Components layoutItemBuilder.AddAttribute(i++, "ColSpanMd", 12); //layoutItemBuilder.AddAttribute(i++, "CssClass", "form-field"); - layoutItemBuilder.AddAttribute(i++, "Template", (RenderFragment)((context) => ((editor) => + layoutItemBuilder.AddAttribute(i++, "Template", (RenderFragment)((context) => ((editor) => { var j = 0; switch (attrList.DataType) @@ -125,11 +125,11 @@ namespace TIAMSharedUI.Pages.Components case DataType.Text: { editor.OpenComponent(j++); - logToBrowserConsole.LogToBC($"{property.Name}, {property.PropertyType}"); + LogToBrowserConsole.LogToBC($"{property.Name}, {property.PropertyType}"); editor.AddAttribute(j++, "Text", property.GetValue(Data)); editor.AddAttribute(j++, "TextExpression", lambda); editor.AddAttribute(j++, "CssClass", "form-field"); - editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); editor.CloseComponent(); break; } @@ -141,17 +141,17 @@ namespace TIAMSharedUI.Pages.Components editor.AddAttribute(j++, "NullText", "Password"); editor.AddAttribute(j++, "Text", property.GetValue(Data)); editor.AddAttribute(j++, "TextExpression", lambda); - editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); editor.CloseComponent(); break; } case DataType.PhoneNumber: { - editor.OpenComponent>(j++); + editor.OpenComponent>(j++); editor.AddAttribute(j++, "Value", property.GetValue(Data)); - editor.AddAttribute(j++, "Mask", PhoneMask); + editor.AddAttribute(j++, "Mask", _phoneMask); editor.AddAttribute(j++, "ValueExpression", lambda); - editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); editor.CloseComponent(); break; } @@ -160,7 +160,7 @@ namespace TIAMSharedUI.Pages.Components editor.OpenComponent>(j); editor.AddAttribute(j++, "Date", property.GetValue(Data)); editor.AddAttribute(j++, "DateExpression", lambda); - editor.AddAttribute(j++, "DateChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.AddAttribute(j++, "DateChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); editor.CloseComponent(); break; @@ -177,7 +177,7 @@ namespace TIAMSharedUI.Pages.Components editor.AddAttribute(j++, "Mask", "n6"); editor.AddAttribute(j++, "ValueExpression", lambda); editor.AddAttribute(j++, "CssClass", "form-field"); - editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); editor.CloseComponent(); break; } @@ -191,18 +191,18 @@ namespace TIAMSharedUI.Pages.Components editor.AddAttribute(j++, "Mask", "n0"); editor.AddAttribute(j++, "ValueExpression", lambda); editor.AddAttribute(j++, "CssClass", "form-field"); - editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); editor.CloseComponent(); break; } else if (property.PropertyType == typeof(string) && property.Name == "Occupation") { - editor.OpenComponent>(j); + editor.OpenComponent>(j); editor.AddAttribute(j++, "Data", AdditionalData.Occupations); editor.AddAttribute(j++, "Value", property.GetValue(Data)); editor.AddAttribute(j++, "ValueExpression", lambda); - editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); editor.CloseComponent(); break; } @@ -211,6 +211,8 @@ namespace TIAMSharedUI.Pages.Components } + break; + } case DataType.MultilineText: { @@ -218,7 +220,7 @@ namespace TIAMSharedUI.Pages.Components editor.AddAttribute(j++, "Text", property.GetValue(Data)); editor.AddAttribute(j++, "TextExpression", lambda); editor.AddAttribute(j++, "CssClass", "form-field"); - editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); editor.CloseComponent(); break; @@ -258,14 +260,14 @@ namespace TIAMSharedUI.Pages.Components layoutItemBuilder.CloseElement(); - logToBrowserConsole.LogToBC($"loop {j}, {propertyList.Length}"); + LogToBrowserConsole.LogToBC($"loop {j}, {propertyList.Length}"); j++; } layoutItemBuilder.OpenComponent(i++); - layoutItemBuilder.AddAttribute(i++, "Template", (RenderFragment)((context) => ((editor) => + layoutItemBuilder.AddAttribute(i++, "Template", (RenderFragment)((context) => ((editor) => { - logToBrowserConsole.LogToBC($"Submit button {CurrentStep}, {propertyList.Length}"); + LogToBrowserConsole.LogToBC($"Submit button {CurrentStep}, {propertyList.Length}"); editor.OpenComponent(i++); editor.AddAttribute(i++, "SubmitFormOnClick", true); editor.AddAttribute(i++, "Text", "Submit"); @@ -279,7 +281,7 @@ namespace TIAMSharedUI.Pages.Components editor.AddAttribute(i++, "Visible", false); } editor.OpenElement(i++, "span"); - editor.AddAttribute(i++, "class", spinnerClass); + editor.AddAttribute(i++, "class", _spinnerClass); editor.CloseElement(); editor.CloseComponent(); }))); diff --git a/TIAMSharedUI/Pages/Components/TransferStep1.razor b/TIAMSharedUI/Pages/Components/TransferStep1.razor index 09807b1b..cd8fb15e 100644 --- a/TIAMSharedUI/Pages/Components/TransferStep1.razor +++ b/TIAMSharedUI/Pages/Components/TransferStep1.razor @@ -66,7 +66,7 @@ protected override async Task OnInitializedAsync() { - Email = sessionService.User.Email; + Email = sessionService.User.DisplayName; await base.OnInitializedAsync(); } diff --git a/TIAMSharedUI/Pages/DbTestComponent.razor b/TIAMSharedUI/Pages/DbTestComponent.razor index 9ea6bff6..94cca67d 100644 --- a/TIAMSharedUI/Pages/DbTestComponent.razor +++ b/TIAMSharedUI/Pages/DbTestComponent.razor @@ -1,4 +1,5 @@ -@if (Users == null) +@using AyCode.Utils.Extensions +@if (Users == null) {

Loading ... @@ -11,7 +12,9 @@ else @foreach (var dest in Users) { -

@dest.EmailAddress

+

+ @(dest.Profile == null ? dest.UserDto.Id.ToString() : dest.Profile.Name) +

} diff --git a/TIAMSharedUI/Pages/DbTestComponent.razor.cs b/TIAMSharedUI/Pages/DbTestComponent.razor.cs index f1180454..feb8d243 100644 --- a/TIAMSharedUI/Pages/DbTestComponent.razor.cs +++ b/TIAMSharedUI/Pages/DbTestComponent.razor.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using TIAM.Entities.Users; +using TIAM.Models.Dtos.Users; using TIAMWebApp.Shared.Application.Interfaces; using TIAMWebApp.Shared.Application.Models; @@ -19,7 +20,7 @@ namespace TIAMSharedUI.Pages get; set; } - public List? Users + public required List Users { get; set; diff --git a/TIAMSharedUI/Pages/TestPage.razor b/TIAMSharedUI/Pages/TestPage.razor index 63b065b3..2000b03b 100644 --- a/TIAMSharedUI/Pages/TestPage.razor +++ b/TIAMSharedUI/Pages/TestPage.razor @@ -10,7 +10,7 @@
- + @code { diff --git a/TIAMSharedUI/TIAMSharedUI.csproj b/TIAMSharedUI/TIAMSharedUI.csproj index 169c629b..7373f118 100644 --- a/TIAMSharedUI/TIAMSharedUI.csproj +++ b/TIAMSharedUI/TIAMSharedUI.csproj @@ -20,6 +20,8 @@ + + @@ -34,6 +36,15 @@ ..\..\AyCode.Core\AyCode.Services.Server\bin\Debug\net8.0\AyCode.Interfaces.dll + + ..\..\AyCode.Core\AyCode.Services.Server\bin\Debug\net8.0\AyCode.Models.dll + + + ..\..\AyCode.Core\AyCode.Services.Server\bin\Debug\net8.0\AyCode.Services.dll + + + ..\..\AyCode.Core\AyCode.Services.Server\bin\Debug\net8.0\AyCode.Utils.dll + diff --git a/TIAMWebApp/Client/Services/UserDataServiceWeb.cs b/TIAMWebApp/Client/Services/UserDataServiceWeb.cs index 6172f38d..0738fc56 100644 --- a/TIAMWebApp/Client/Services/UserDataServiceWeb.cs +++ b/TIAMWebApp/Client/Services/UserDataServiceWeb.cs @@ -12,6 +12,7 @@ using TIAMWebApp.Shared.Application.Models.PageModels; using TIAMWebApp.Shared.Application.Utility; using AyCode.Interfaces.StorageHandlers; using AyCode.Core.Logger; +using TIAM.Models.Dtos.Users; namespace TIAMWebApp.Client.Services @@ -37,26 +38,26 @@ namespace TIAMWebApp.Client.Services public async Task IsLoggedInAsync(Guid id) { - UserSessionModel User = null; + UserSessionModel user = null; //api call to get user - var dbUser = await GetUserByIdAsync(id); + var userModelDto = await GetUserByIdAsync(id); - if (dbUser != null) + if (userModelDto != null) { - var a = dbUser.UserProductMappings.FirstOrDefault().Product; + var a = userModelDto.UserProductMappings.FirstOrDefault()?.Product; if (a != null) logToBrowserConsole.LogToBC($"{a.Name}"); //get user's properties - var hasProperties = await serviceProviderDataService.GetPropertiesByOwnerIdAsync(dbUser.Id); + var hasProperties = await serviceProviderDataService.GetPropertiesByOwnerIdAsync(userModelDto.Id); if (hasProperties != null) logToBrowserConsole.LogToBC($"{hasProperties.Count} properties found"); //create user session model - User = new UserSessionModel(dbUser.Id, UserType.User, dbUser.EmailAddress, hasProperties, 1); - return User; + user = new UserSessionModel(userModelDto.Id, UserType.User, userModelDto.Profile?.Name, hasProperties, 1); + return user; } else { @@ -130,24 +131,24 @@ namespace TIAMWebApp.Client.Services return (isSuccess, result); } - public async Task?> GetUsersAsync() + public async Task?> GetUsersAsync() { - return await http.GetFromJsonAsync>(APIUrls.GetUsers); + return await http.GetFromJsonAsync>(APIUrls.GetUsers); } - public async Task GetUserByEmailAsync(string email) + public async Task GetUserByEmailAsync(string email) { var url = $"{Setting.BaseUrl}/{APIUrls.GetUserByEmail}"; - return await http.GetFromJsonAsync(url); + return await http.GetFromJsonAsync(url); } - public async Task GetUserByIdAsync(Guid Id) + public async Task GetUserByIdAsync(Guid id) { var url = $"{Setting.BaseUrl}/{APIUrls.GetUserById}"; - logToBrowserConsole.LogToBC("GetUserByIdAsync url: " + url + ", " + Id.ToString()); - var response = await http.PostAsJsonAsync(url, Id); + logToBrowserConsole.LogToBC("GetUserByIdAsync url: " + url + ", " + id.ToString()); + var response = await http.PostAsJsonAsync(url, id); var result = await response.Content.ReadAsStringAsync(); - var user = JsonConvert.DeserializeObject(result); + var user = JsonConvert.DeserializeObject(result); return user; } diff --git a/TIAMWebApp/Server/Controllers/UserAPIController.cs b/TIAMWebApp/Server/Controllers/UserAPIController.cs index 4bf168a0..d5f764d4 100644 --- a/TIAMWebApp/Server/Controllers/UserAPIController.cs +++ b/TIAMWebApp/Server/Controllers/UserAPIController.cs @@ -20,6 +20,7 @@ using Microsoft.EntityFrameworkCore; using TIAM.Database.DataLayers.Users; using AyCode.Utils.Helpers; using TIAM.Entities.Users; +using TIAM.Models.Dtos.Users; using TIAMWebApp.Server.ModelsTIAMWebApp.Shared.Application.Models; using TIAMWebApp.Shared.Application.Utility; @@ -322,34 +323,33 @@ namespace TIAMWebApp.Server.Controllers [AllowAnonymous] [HttpGet] [Route("GetUsers")] - public Task> GetUsers() + public Task> GetUsers() { //var users = await _userDal.Ctx.Users.ToListAsync();//.GetUsersAsync(); //return users; - return _userDal.GetUsersAsync(); + return _userDal.GetAllUsersModelDtoAsync(); } [AllowAnonymous] [HttpGet] [Route("GetUserByEmail")] - public async Task GetUserByEmail(string email) + public Task GetUserByEmail(string email) { - return await _userDal.GetUserByEmailAsync(email); + return _userDal.GetUserModelDtoByEmailAsync(email); } [AllowAnonymous] [HttpPost] [Route("GetUserById")] - public User? GetUserById([FromBody] Guid id) + public Task GetUserById([FromBody] Guid id) { Logger.Info($"GetUserById called with id: {id}"); - var result = _userDal.GetUserById(id); - var b = result.UserProductMappings.FirstOrDefault(x => x.Id != null); + var result = _userDal.GetUserModelDtoByIdAsync(id); - var a = JsonSerializer.Serialize(result); + //var b = result.UserProductMappings.FirstOrDefault(x => x.Id != null); + //var a = JsonSerializer.Serialize(result); + //Console.WriteLine($"GetUserById result: {a}"); - - Console.WriteLine($"GetUserById result: {a}"); return result; } diff --git a/TIAMWebApp/Shared/Interfaces/IUserDataService.cs b/TIAMWebApp/Shared/Interfaces/IUserDataService.cs index 21dea5ef..d756105c 100644 --- a/TIAMWebApp/Shared/Interfaces/IUserDataService.cs +++ b/TIAMWebApp/Shared/Interfaces/IUserDataService.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using TIAM.Entities.Users; +using TIAM.Models.Dtos.Users; using TIAMWebApp.Shared.Application.Models; using TIAMWebApp.Shared.Application.Models.PageModels; @@ -21,8 +22,8 @@ namespace TIAMWebApp.Shared.Application.Interfaces //public Task> GetUserRolesAsync(UserModel userModel); - public Task?> GetUsersAsync(); - public Task GetUserByEmailAsync(string email); + public Task?> GetUsersAsync(); + public Task GetUserByEmailAsync(string email); Task RefreshToken(); } } \ No newline at end of file diff --git a/TIAMWebApp/Shared/Models/UserSessionModel.cs b/TIAMWebApp/Shared/Models/UserSessionModel.cs index 528560e2..88f384ff 100644 --- a/TIAMWebApp/Shared/Models/UserSessionModel.cs +++ b/TIAMWebApp/Shared/Models/UserSessionModel.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Microsoft.IdentityModel.Tokens; using TIAM.Entities.Users; namespace TIAMWebApp.Shared.Application.Models @@ -7,17 +8,18 @@ namespace TIAMWebApp.Shared.Application.Models { public Guid UserId { get; set; } public UserType UserType { get; set; } - public string Email { get; set; } + public string? UserName { get; set; } + public string DisplayName => string.IsNullOrWhiteSpace(UserName) ? UserId.ToString() : UserName; public Dictionary? HasProperties { get; set; } public int UserRoles { get; set; } public Dictionary UserRolesDictionary { get; set; } - public UserSessionModel(Guid userId, UserType userType, string email, Dictionary? hasProperties, int userRoles) + public UserSessionModel(Guid userId, UserType userType, string? userName, Dictionary? hasProperties, int userRoles) { UserId = userId; UserType = userType; - Email = email; + UserName = userName; HasProperties = hasProperties; //UserRoles = userRoles; //UserRolesDictionary = new Dictionary(); diff --git a/TIAMWebApp/Shared/TIAMWebApp.Shared.Application.csproj b/TIAMWebApp/Shared/TIAMWebApp.Shared.Application.csproj index e50dd37b..854b012c 100644 --- a/TIAMWebApp/Shared/TIAMWebApp.Shared.Application.csproj +++ b/TIAMWebApp/Shared/TIAMWebApp.Shared.Application.csproj @@ -27,6 +27,7 @@ + diff --git a/TourIAmProject.sln b/TourIAmProject.sln index 9846adde..60c3d550 100644 --- a/TourIAmProject.sln +++ b/TourIAmProject.sln @@ -33,9 +33,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AyCode.Blazor.Models", "..\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AyCode.Blazor.Models.Server", "..\Aycode.Blazor\AyCode.Blazor.Models.Server\AyCode.Blazor.Models.Server.csproj", "{A36322E8-F485-455E-84AA-B911948B6702}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TIAM.Models", "TIAM.Models\TIAM.Models.csproj", "{6037FF79-88D2-457C-BA3A-9AC978873741}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TIAM.Models", "TIAM.Models\TIAM.Models.csproj", "{6037FF79-88D2-457C-BA3A-9AC978873741}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TIAM.Resources", "TIAMResources\TIAM.Resources.csproj", "{2A300982-AA2E-4E62-97F2-6EF4C97939B2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TIAM.Resources", "TIAMResources\TIAM.Resources.csproj", "{2A300982-AA2E-4E62-97F2-6EF4C97939B2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -105,6 +105,14 @@ Global {A36322E8-F485-455E-84AA-B911948B6702}.Debug|Any CPU.Build.0 = Debug|Any CPU {A36322E8-F485-455E-84AA-B911948B6702}.Release|Any CPU.ActiveCfg = Release|Any CPU {A36322E8-F485-455E-84AA-B911948B6702}.Release|Any CPU.Build.0 = Release|Any CPU + {6037FF79-88D2-457C-BA3A-9AC978873741}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6037FF79-88D2-457C-BA3A-9AC978873741}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6037FF79-88D2-457C-BA3A-9AC978873741}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6037FF79-88D2-457C-BA3A-9AC978873741}.Release|Any CPU.Build.0 = Release|Any CPU + {2A300982-AA2E-4E62-97F2-6EF4C97939B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2A300982-AA2E-4E62-97F2-6EF4C97939B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2A300982-AA2E-4E62-97F2-6EF4C97939B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2A300982-AA2E-4E62-97F2-6EF4C97939B2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE