improvements, fixes...

This commit is contained in:
jozsef.b@aycode.com 2023-12-19 00:19:08 +01:00
parent 20d728f28a
commit 733fdd2484
19 changed files with 117 additions and 80 deletions

View File

@ -54,7 +54,7 @@ namespace TIAM.Database.Test
[TestMethod] [TestMethod]
[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")] [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); var userId = Guid.Parse(userIdString);
@ -64,12 +64,13 @@ namespace TIAM.Database.Test
NullValueHandling = NullValueHandling.Ignore NullValueHandling = NullValueHandling.Ignore
}; };
var userModel = Dal.GetUserModelDtoById(userId); var userModel = await Dal.GetUserModelDtoByIdAsync(userId).ConfigureAwait(false);
var serializedUserModel = JsonConvert.SerializeObject(userModel, options); var serializedUserModel = JsonConvert.SerializeObject(userModel, options);
userModel = JsonConvert.DeserializeObject<UserModelDto>(serializedUserModel); userModel = JsonConvert.DeserializeObject<UserModelDto>(serializedUserModel);
Assert.IsNotNull(userModel); Assert.IsNotNull(userModel);
Assert.IsNotNull(userModel.UserDto);
Assert.IsNotNull(userModel.Profile); Assert.IsNotNull(userModel.Profile);
Assert.IsTrue(userModel.Products.Count > 0); Assert.IsTrue(userModel.Products.Count > 0);

View File

@ -32,8 +32,9 @@ namespace TIAM.Database.DataLayers.Users
return Context.Users.ToListAsync(); return Context.Users.ToListAsync();
} }
public UserModelDto? GetUserModelDtoById(Guid userId) => Session(x => x.GetUserModelDtoById(userId)); public Task<UserModelDto?> GetUserModelDtoByIdAsync(Guid userId) => SessionAsync(x => x.GetUserModelDtoById(userId));
public UserModelDto? GetUserModelDtoByEmail(string email) => Session(x => x.GetUserModelDtoByEmail(email)); public Task<UserModelDto?> GetUserModelDtoByEmailAsync(string email) => SessionAsync(x => x.GetUserModelDtoByEmail(email));
public Task<List<UserModelDto>> GetAllUsersModelDtoAsync() => SessionAsync(x => x.GetAllUsersModelDto().ToList());
public Task<User?> GetUserByPhoneNumberAsync(string phoneNumber) public Task<User?> GetUserByPhoneNumberAsync(string phoneNumber)
{ {

View File

@ -26,4 +26,8 @@ public static class UserDbSetExtensions
public static UserModelDto? GetUserModelDtoByEmail(this IUserDbSet ctx, string email) public static UserModelDto? GetUserModelDtoByEmail(this IUserDbSet ctx, string email)
=> ctx.GetUsersByEmail(email).Select(x => new UserModelDto(x, x.Profile, x.UserProductMappings, x.Products)).FirstOrDefault(); => ctx.GetUsersByEmail(email).Select(x => new UserModelDto(x, x.Profile, x.UserProductMappings, x.Products)).FirstOrDefault();
public static IQueryable<UserModelDto> GetAllUsersModelDto(this IUserDbSet ctx)
=> ctx.Users.Select(x => new UserModelDto(x, x.Profile, x.UserProductMappings, x.Products));
} }

View File

@ -3,6 +3,7 @@ using System.Text;
using AyCode.Interfaces.StorageHandlers; using AyCode.Interfaces.StorageHandlers;
using Newtonsoft.Json; using Newtonsoft.Json;
using TIAM.Entities.Users; using TIAM.Entities.Users;
using TIAM.Models.Dtos.Users;
using TIAMWebApp.Shared.Application.Interfaces; using TIAMWebApp.Shared.Application.Interfaces;
using TIAMWebApp.Shared.Application.Models; using TIAMWebApp.Shared.Application.Models;
using TIAMWebApp.Shared.Application.Models.ClientSide; using TIAMWebApp.Shared.Application.Models.ClientSide;
@ -49,7 +50,7 @@ namespace TIAMMobileApp.Services
{ {
var hasProperties = await _serviceProviderDataService.GetPropertiesByOwnerIdAsync(dbUser.Id); 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; return user;
} }
@ -117,14 +118,14 @@ namespace TIAMMobileApp.Services
return (isSuccess, result); return (isSuccess, result);
} }
public async Task<IEnumerable<User>?> GetUsersAsync() public async Task<IEnumerable<UserModelDto>?> GetUsersAsync()
{ {
return await http.GetFromJsonAsync<IEnumerable<User>>(APIUrls.GetUsers); return await http.GetFromJsonAsync<IEnumerable<UserModelDto>>(APIUrls.GetUsers);
} }
public async Task<User?> GetUserByEmailAsync(string email) public async Task<UserModelDto?> GetUserByEmailAsync(string email)
{ {
return await http.GetFromJsonAsync<User?>(APIUrls.GetUserByEmail); return await http.GetFromJsonAsync<UserModelDto?>(APIUrls.GetUserByEmail);
} }
public async Task<User?> GetUserByIdAsync(Guid Id) public async Task<User?> GetUserByIdAsync(Guid Id)
{ {

View File

@ -85,7 +85,7 @@ Loading....
string _email = jsontoken.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.Email).Value; string _email = jsontoken.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.Email).Value;
var user = await UserDataService.IsLoggedInAsync(Guid.Parse(_userId)); var user = await UserDataService.IsLoggedInAsync(Guid.Parse(_userId));
sessionService.User = user; 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; sessionService.IsAuthenticated = true;
NavManager.NavigateTo("/index"); NavManager.NavigateTo("/index");
} }

View File

@ -66,7 +66,7 @@
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
Email = sessionService.User.Email; Email = sessionService.User.DisplayName;
await base.OnInitializedAsync(); await base.OnInitializedAsync();
} }

View File

@ -25,7 +25,7 @@
</div> </div>
<p class="tm-8 cw-480 mt-2"> <p class="tm-8 cw-480 mt-2">
<h3> @Localizer.GetString("DestinationName")</h3> <h3> @Localizer.GetString("DestinationName")</h3>
@FormSubmitResult @_formSubmitResult
</p> </p>
@code { @code {

View File

@ -16,7 +16,7 @@ namespace TIAMSharedUI.Pages.Components
public partial class InputWizard : ComponentBase public partial class InputWizard : ComponentBase
{ {
[Inject] [Inject]
LogToBrowserConsole logToBrowserConsole { get; set; } public required LogToBrowserConsole LogToBrowserConsole { get; set; }
public Dictionary<int, Guid> FormSteps { get; set; } = new Dictionary<int, Guid>(); public Dictionary<int, Guid> FormSteps { get; set; } = new Dictionary<int, Guid>();
public int CurrentStep { get; set; } = 0; public int CurrentStep { get; set; } = 0;
@ -28,37 +28,37 @@ namespace TIAMSharedUI.Pages.Components
public object Data { get; set; } = new object(); public object Data { get; set; } = new object();
[Parameter] [Parameter]
public EventCallback<object> onSubmit { get; set; } public EventCallback<object> OnSubmit { get; set; }
string PhoneMask { get; set; } = "(999)000-0000"; string _phoneMask = "(999)000-0000";
string FormSubmitResult = ""; string _formSubmitResult = "";
private string spinnerClass = ""; private string _spinnerClass = "";
async Task HandleValidSubmit() async Task HandleValidSubmit()
{ {
spinnerClass = "spinner-border spinner-border-sm"; _spinnerClass = "spinner-border spinner-border-sm";
await Task.Delay(500); await Task.Delay(500);
FormSubmitResult = "You have been registred successully."; _formSubmitResult = "You have been registred successully.";
spinnerClass = ""; _spinnerClass = "";
await onSubmit.InvokeAsync(Data); await OnSubmit.InvokeAsync(Data);
} }
void HandleInvalidSubmit() void HandleInvalidSubmit()
{ {
FormSubmitResult = "Please correct all errors"; _formSubmitResult = "Please correct all errors";
} }
public void OnNext(MouseEventArgs args) public void OnNext(MouseEventArgs args)
{ {
logToBrowserConsole.LogToBC("OnNext called"); LogToBrowserConsole.LogToBC("OnNext called");
CurrentStep++; CurrentStep++;
} }
public void OnPrevious(MouseEventArgs args) public void OnPrevious(MouseEventArgs args)
{ {
logToBrowserConsole.LogToBC("OnPrev called"); LogToBrowserConsole.LogToBC("OnPrev called");
CurrentStep--; CurrentStep--;
} }
@ -66,7 +66,7 @@ namespace TIAMSharedUI.Pages.Components
{ {
var _type = Data.GetType(); var _type = Data.GetType();
logToBrowserConsole.LogToBC("Hellooooo " + _type.AssemblyQualifiedName); LogToBrowserConsole.LogToBC("Hellooooo " + _type.AssemblyQualifiedName);
var propertyList = _type.GetProperties(); var propertyList = _type.GetProperties();
//var propertyList = typeof(TestUserData).GetProperties(); //var propertyList = typeof(TestUserData).GetProperties();
@ -100,7 +100,7 @@ namespace TIAMSharedUI.Pages.Components
var access = Expression.Property(Expression.Constant(Data), property.Name); var access = Expression.Property(Expression.Constant(Data), property.Name);
var lambda = Expression.Lambda(typeof(Func<>).MakeGenericType(property.PropertyType), access); 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.OpenElement(i++, "div");//open div
layoutItemBuilder.AddAttribute(i++, "id", _stepID.ToString()); layoutItemBuilder.AddAttribute(i++, "id", _stepID.ToString());
@ -116,7 +116,7 @@ namespace TIAMSharedUI.Pages.Components
layoutItemBuilder.AddAttribute(i++, "ColSpanMd", 12); layoutItemBuilder.AddAttribute(i++, "ColSpanMd", 12);
//layoutItemBuilder.AddAttribute(i++, "CssClass", "form-field"); //layoutItemBuilder.AddAttribute(i++, "CssClass", "form-field");
layoutItemBuilder.AddAttribute(i++, "Template", (RenderFragment<Object>)((context) => ((editor) => layoutItemBuilder.AddAttribute(i++, "Template", (RenderFragment<object>)((context) => ((editor) =>
{ {
var j = 0; var j = 0;
switch (attrList.DataType) switch (attrList.DataType)
@ -125,11 +125,11 @@ namespace TIAMSharedUI.Pages.Components
case DataType.Text: case DataType.Text:
{ {
editor.OpenComponent<DxTextBox>(j++); editor.OpenComponent<DxTextBox>(j++);
logToBrowserConsole.LogToBC($"{property.Name}, {property.PropertyType}"); LogToBrowserConsole.LogToBC($"{property.Name}, {property.PropertyType}");
editor.AddAttribute(j++, "Text", property.GetValue(Data)); editor.AddAttribute(j++, "Text", property.GetValue(Data));
editor.AddAttribute(j++, "TextExpression", lambda); editor.AddAttribute(j++, "TextExpression", lambda);
editor.AddAttribute(j++, "CssClass", "form-field"); editor.AddAttribute(j++, "CssClass", "form-field");
editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create<System.String>(this, str => { property.SetValue(Data, str); })); editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create<string>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent(); editor.CloseComponent();
break; break;
} }
@ -141,17 +141,17 @@ namespace TIAMSharedUI.Pages.Components
editor.AddAttribute(j++, "NullText", "Password"); editor.AddAttribute(j++, "NullText", "Password");
editor.AddAttribute(j++, "Text", property.GetValue(Data)); editor.AddAttribute(j++, "Text", property.GetValue(Data));
editor.AddAttribute(j++, "TextExpression", lambda); editor.AddAttribute(j++, "TextExpression", lambda);
editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create<System.String>(this, str => { property.SetValue(Data, str); })); editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create<string>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent(); editor.CloseComponent();
break; break;
} }
case DataType.PhoneNumber: case DataType.PhoneNumber:
{ {
editor.OpenComponent<DxMaskedInput<String>>(j++); editor.OpenComponent<DxMaskedInput<string>>(j++);
editor.AddAttribute(j++, "Value", property.GetValue(Data)); 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++, "ValueExpression", lambda);
editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create<System.String>(this, str => { property.SetValue(Data, str); })); editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create<string>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent(); editor.CloseComponent();
break; break;
} }
@ -160,7 +160,7 @@ namespace TIAMSharedUI.Pages.Components
editor.OpenComponent<DxDateEdit<DateTime>>(j); editor.OpenComponent<DxDateEdit<DateTime>>(j);
editor.AddAttribute(j++, "Date", property.GetValue(Data)); editor.AddAttribute(j++, "Date", property.GetValue(Data));
editor.AddAttribute(j++, "DateExpression", lambda); editor.AddAttribute(j++, "DateExpression", lambda);
editor.AddAttribute(j++, "DateChanged", EventCallback.Factory.Create<System.DateTime>(this, str => { property.SetValue(Data, str); })); editor.AddAttribute(j++, "DateChanged", EventCallback.Factory.Create<DateTime>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent(); editor.CloseComponent();
break; break;
@ -177,7 +177,7 @@ namespace TIAMSharedUI.Pages.Components
editor.AddAttribute(j++, "Mask", "n6"); editor.AddAttribute(j++, "Mask", "n6");
editor.AddAttribute(j++, "ValueExpression", lambda); editor.AddAttribute(j++, "ValueExpression", lambda);
editor.AddAttribute(j++, "CssClass", "form-field"); editor.AddAttribute(j++, "CssClass", "form-field");
editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create<System.Double>(this, str => { property.SetValue(Data, str); })); editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create<double>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent(); editor.CloseComponent();
break; break;
} }
@ -191,18 +191,18 @@ namespace TIAMSharedUI.Pages.Components
editor.AddAttribute(j++, "Mask", "n0"); editor.AddAttribute(j++, "Mask", "n0");
editor.AddAttribute(j++, "ValueExpression", lambda); editor.AddAttribute(j++, "ValueExpression", lambda);
editor.AddAttribute(j++, "CssClass", "form-field"); editor.AddAttribute(j++, "CssClass", "form-field");
editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create<System.Int32>(this, str => { property.SetValue(Data, str); })); editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create<int>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent(); editor.CloseComponent();
break; break;
} }
else if (property.PropertyType == typeof(string) && property.Name == "Occupation") else if (property.PropertyType == typeof(string) && property.Name == "Occupation")
{ {
editor.OpenComponent<DxComboBox<String, String>>(j); editor.OpenComponent<DxComboBox<string, string>>(j);
editor.AddAttribute(j++, "Data", AdditionalData.Occupations); editor.AddAttribute(j++, "Data", AdditionalData.Occupations);
editor.AddAttribute(j++, "Value", property.GetValue(Data)); editor.AddAttribute(j++, "Value", property.GetValue(Data));
editor.AddAttribute(j++, "ValueExpression", lambda); editor.AddAttribute(j++, "ValueExpression", lambda);
editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create<System.String>(this, str => { property.SetValue(Data, str); })); editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create<string>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent(); editor.CloseComponent();
break; break;
} }
@ -211,6 +211,8 @@ namespace TIAMSharedUI.Pages.Components
} }
break;
} }
case DataType.MultilineText: case DataType.MultilineText:
{ {
@ -218,7 +220,7 @@ namespace TIAMSharedUI.Pages.Components
editor.AddAttribute(j++, "Text", property.GetValue(Data)); editor.AddAttribute(j++, "Text", property.GetValue(Data));
editor.AddAttribute(j++, "TextExpression", lambda); editor.AddAttribute(j++, "TextExpression", lambda);
editor.AddAttribute(j++, "CssClass", "form-field"); editor.AddAttribute(j++, "CssClass", "form-field");
editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create<System.String>(this, str => { property.SetValue(Data, str); })); editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create<string>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent(); editor.CloseComponent();
break; break;
@ -258,14 +260,14 @@ namespace TIAMSharedUI.Pages.Components
layoutItemBuilder.CloseElement(); layoutItemBuilder.CloseElement();
logToBrowserConsole.LogToBC($"loop {j}, {propertyList.Length}"); LogToBrowserConsole.LogToBC($"loop {j}, {propertyList.Length}");
j++; j++;
} }
layoutItemBuilder.OpenComponent<DxFormLayoutItem>(i++); layoutItemBuilder.OpenComponent<DxFormLayoutItem>(i++);
layoutItemBuilder.AddAttribute(i++, "Template", (RenderFragment<Object>)((context) => ((editor) => layoutItemBuilder.AddAttribute(i++, "Template", (RenderFragment<object>)((context) => ((editor) =>
{ {
logToBrowserConsole.LogToBC($"Submit button {CurrentStep}, {propertyList.Length}"); LogToBrowserConsole.LogToBC($"Submit button {CurrentStep}, {propertyList.Length}");
editor.OpenComponent<DxButton>(i++); editor.OpenComponent<DxButton>(i++);
editor.AddAttribute(i++, "SubmitFormOnClick", true); editor.AddAttribute(i++, "SubmitFormOnClick", true);
editor.AddAttribute(i++, "Text", "Submit"); editor.AddAttribute(i++, "Text", "Submit");
@ -279,7 +281,7 @@ namespace TIAMSharedUI.Pages.Components
editor.AddAttribute(i++, "Visible", false); editor.AddAttribute(i++, "Visible", false);
} }
editor.OpenElement(i++, "span"); editor.OpenElement(i++, "span");
editor.AddAttribute(i++, "class", spinnerClass); editor.AddAttribute(i++, "class", _spinnerClass);
editor.CloseElement(); editor.CloseElement();
editor.CloseComponent(); editor.CloseComponent();
}))); })));

View File

@ -66,7 +66,7 @@
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
Email = sessionService.User.Email; Email = sessionService.User.DisplayName;
await base.OnInitializedAsync(); await base.OnInitializedAsync();
} }

View File

@ -1,4 +1,5 @@
@if (Users == null) @using AyCode.Utils.Extensions
@if (Users == null)
{ {
<p> <p>
<em>Loading ...</em> <em>Loading ...</em>
@ -11,7 +12,9 @@ else
@foreach (var dest in Users) @foreach (var dest in Users)
{ {
<p>@dest.EmailAddress</p> <p>
@(dest.Profile == null ? dest.UserDto.Id.ToString() : dest.Profile.Name)
</p>
} }
</div> </div>

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using TIAM.Entities.Users; using TIAM.Entities.Users;
using TIAM.Models.Dtos.Users;
using TIAMWebApp.Shared.Application.Interfaces; using TIAMWebApp.Shared.Application.Interfaces;
using TIAMWebApp.Shared.Application.Models; using TIAMWebApp.Shared.Application.Models;
@ -19,7 +20,7 @@ namespace TIAMSharedUI.Pages
get; get;
set; set;
} }
public List<TIAM.Entities.Users.User>? Users public required List<UserModelDto> Users
{ {
get; get;
set; set;

View File

@ -10,7 +10,7 @@
<hr/> <hr/>
<DbTestComponent></DbTestComponent> <DbTestComponent></DbTestComponent>
<InputWizard Data=@myModel onSubmit="SubmitForm"></InputWizard> <InputWizard Data=@myModel OnSubmit="SubmitForm"></InputWizard>
</div> </div>
@code { @code {

View File

@ -20,6 +20,8 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Aycode.Blazor\AyCode.Blazor.Components\AyCode.Blazor.Components.csproj" /> <ProjectReference Include="..\..\Aycode.Blazor\AyCode.Blazor.Components\AyCode.Blazor.Components.csproj" />
<ProjectReference Include="..\..\Aycode.Blazor\AyCode.Blazor.Models\AyCode.Blazor.Models.csproj" /> <ProjectReference Include="..\..\Aycode.Blazor\AyCode.Blazor.Models\AyCode.Blazor.Models.csproj" />
<ProjectReference Include="..\TIAM.Entities\TIAM.Entities.csproj" />
<ProjectReference Include="..\TIAM.Models\TIAM.Models.csproj" />
<ProjectReference Include="..\TIAMResources\TIAM.Resources.csproj" /> <ProjectReference Include="..\TIAMResources\TIAM.Resources.csproj" />
<ProjectReference Include="..\TIAMWebApp\Shared\TIAMWebApp.Shared.Application.csproj" /> <ProjectReference Include="..\TIAMWebApp\Shared\TIAMWebApp.Shared.Application.csproj" />
</ItemGroup> </ItemGroup>
@ -34,6 +36,15 @@
<Reference Include="AyCode.Interfaces"> <Reference Include="AyCode.Interfaces">
<HintPath>..\..\AyCode.Core\AyCode.Services.Server\bin\Debug\net8.0\AyCode.Interfaces.dll</HintPath> <HintPath>..\..\AyCode.Core\AyCode.Services.Server\bin\Debug\net8.0\AyCode.Interfaces.dll</HintPath>
</Reference> </Reference>
<Reference Include="AyCode.Models">
<HintPath>..\..\AyCode.Core\AyCode.Services.Server\bin\Debug\net8.0\AyCode.Models.dll</HintPath>
</Reference>
<Reference Include="AyCode.Services">
<HintPath>..\..\AyCode.Core\AyCode.Services.Server\bin\Debug\net8.0\AyCode.Services.dll</HintPath>
</Reference>
<Reference Include="AyCode.Utils">
<HintPath>..\..\AyCode.Core\AyCode.Services.Server\bin\Debug\net8.0\AyCode.Utils.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -12,6 +12,7 @@ using TIAMWebApp.Shared.Application.Models.PageModels;
using TIAMWebApp.Shared.Application.Utility; using TIAMWebApp.Shared.Application.Utility;
using AyCode.Interfaces.StorageHandlers; using AyCode.Interfaces.StorageHandlers;
using AyCode.Core.Logger; using AyCode.Core.Logger;
using TIAM.Models.Dtos.Users;
namespace TIAMWebApp.Client.Services namespace TIAMWebApp.Client.Services
@ -37,26 +38,26 @@ namespace TIAMWebApp.Client.Services
public async Task<UserSessionModel> IsLoggedInAsync(Guid id) public async Task<UserSessionModel> IsLoggedInAsync(Guid id)
{ {
UserSessionModel User = null; UserSessionModel user = null;
//api call to get user //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) if (a != null)
logToBrowserConsole.LogToBC($"{a.Name}"); logToBrowserConsole.LogToBC($"{a.Name}");
//get user's properties //get user's properties
var hasProperties = await serviceProviderDataService.GetPropertiesByOwnerIdAsync(dbUser.Id); var hasProperties = await serviceProviderDataService.GetPropertiesByOwnerIdAsync(userModelDto.Id);
if (hasProperties != null) if (hasProperties != null)
logToBrowserConsole.LogToBC($"{hasProperties.Count} properties found"); logToBrowserConsole.LogToBC($"{hasProperties.Count} properties found");
//create user session model //create user session model
User = new UserSessionModel(dbUser.Id, UserType.User, dbUser.EmailAddress, hasProperties, 1); user = new UserSessionModel(userModelDto.Id, UserType.User, userModelDto.Profile?.Name, hasProperties, 1);
return User; return user;
} }
else else
{ {
@ -130,24 +131,24 @@ namespace TIAMWebApp.Client.Services
return (isSuccess, result); return (isSuccess, result);
} }
public async Task<IEnumerable<User>?> GetUsersAsync() public async Task<IEnumerable<UserModelDto>?> GetUsersAsync()
{ {
return await http.GetFromJsonAsync<IEnumerable<User>>(APIUrls.GetUsers); return await http.GetFromJsonAsync<IEnumerable<UserModelDto>>(APIUrls.GetUsers);
} }
public async Task<User?> GetUserByEmailAsync(string email) public async Task<UserModelDto?> GetUserByEmailAsync(string email)
{ {
var url = $"{Setting.BaseUrl}/{APIUrls.GetUserByEmail}"; var url = $"{Setting.BaseUrl}/{APIUrls.GetUserByEmail}";
return await http.GetFromJsonAsync<User?>(url); return await http.GetFromJsonAsync<UserModelDto?>(url);
} }
public async Task<User?> GetUserByIdAsync(Guid Id) public async Task<UserModelDto?> GetUserByIdAsync(Guid id)
{ {
var url = $"{Setting.BaseUrl}/{APIUrls.GetUserById}"; var url = $"{Setting.BaseUrl}/{APIUrls.GetUserById}";
logToBrowserConsole.LogToBC("GetUserByIdAsync url: " + url + ", " + Id.ToString()); logToBrowserConsole.LogToBC("GetUserByIdAsync url: " + url + ", " + id.ToString());
var response = await http.PostAsJsonAsync(url, Id); var response = await http.PostAsJsonAsync(url, id);
var result = await response.Content.ReadAsStringAsync(); var result = await response.Content.ReadAsStringAsync();
var user = JsonConvert.DeserializeObject<User>(result); var user = JsonConvert.DeserializeObject<UserModelDto>(result);
return user; return user;
} }

View File

@ -20,6 +20,7 @@ using Microsoft.EntityFrameworkCore;
using TIAM.Database.DataLayers.Users; using TIAM.Database.DataLayers.Users;
using AyCode.Utils.Helpers; using AyCode.Utils.Helpers;
using TIAM.Entities.Users; using TIAM.Entities.Users;
using TIAM.Models.Dtos.Users;
using TIAMWebApp.Server.ModelsTIAMWebApp.Shared.Application.Models; using TIAMWebApp.Server.ModelsTIAMWebApp.Shared.Application.Models;
using TIAMWebApp.Shared.Application.Utility; using TIAMWebApp.Shared.Application.Utility;
@ -322,34 +323,33 @@ namespace TIAMWebApp.Server.Controllers
[AllowAnonymous] [AllowAnonymous]
[HttpGet] [HttpGet]
[Route("GetUsers")] [Route("GetUsers")]
public Task<List<User>> GetUsers() public Task<List<UserModelDto>> GetUsers()
{ {
//var users = await _userDal.Ctx.Users.ToListAsync();//.GetUsersAsync(); //var users = await _userDal.Ctx.Users.ToListAsync();//.GetUsersAsync();
//return users; //return users;
return _userDal.GetUsersAsync(); return _userDal.GetAllUsersModelDtoAsync();
} }
[AllowAnonymous] [AllowAnonymous]
[HttpGet] [HttpGet]
[Route("GetUserByEmail")] [Route("GetUserByEmail")]
public async Task<User?> GetUserByEmail(string email) public Task<UserModelDto?> GetUserByEmail(string email)
{ {
return await _userDal.GetUserByEmailAsync(email); return _userDal.GetUserModelDtoByEmailAsync(email);
} }
[AllowAnonymous] [AllowAnonymous]
[HttpPost] [HttpPost]
[Route("GetUserById")] [Route("GetUserById")]
public User? GetUserById([FromBody] Guid id) public Task<UserModelDto?> GetUserById([FromBody] Guid id)
{ {
Logger.Info($"GetUserById called with id: {id}"); Logger.Info($"GetUserById called with id: {id}");
var result = _userDal.GetUserById(id); var result = _userDal.GetUserModelDtoByIdAsync(id);
var b = result.UserProductMappings.FirstOrDefault(x => x.Id != null);
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; return result;
} }

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using TIAM.Entities.Users; using TIAM.Entities.Users;
using TIAM.Models.Dtos.Users;
using TIAMWebApp.Shared.Application.Models; using TIAMWebApp.Shared.Application.Models;
using TIAMWebApp.Shared.Application.Models.PageModels; using TIAMWebApp.Shared.Application.Models.PageModels;
@ -21,8 +22,8 @@ namespace TIAMWebApp.Shared.Application.Interfaces
//public Task<Dictionary<int, string>> GetUserRolesAsync(UserModel userModel); //public Task<Dictionary<int, string>> GetUserRolesAsync(UserModel userModel);
public Task<IEnumerable<User>?> GetUsersAsync(); public Task<IEnumerable<UserModelDto>?> GetUsersAsync();
public Task<User?> GetUserByEmailAsync(string email); public Task<UserModelDto?> GetUserByEmailAsync(string email);
Task<bool> RefreshToken(); Task<bool> RefreshToken();
} }
} }

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.IdentityModel.Tokens;
using TIAM.Entities.Users; using TIAM.Entities.Users;
namespace TIAMWebApp.Shared.Application.Models namespace TIAMWebApp.Shared.Application.Models
@ -7,17 +8,18 @@ namespace TIAMWebApp.Shared.Application.Models
{ {
public Guid UserId { get; set; } public Guid UserId { get; set; }
public UserType UserType { 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<Guid, string>? HasProperties { get; set; } public Dictionary<Guid, string>? HasProperties { get; set; }
public int UserRoles { get; set; } public int UserRoles { get; set; }
public Dictionary<int, string> UserRolesDictionary { get; set; } public Dictionary<int, string> UserRolesDictionary { get; set; }
public UserSessionModel(Guid userId, UserType userType, string email, Dictionary<Guid, string>? hasProperties, int userRoles) public UserSessionModel(Guid userId, UserType userType, string? userName, Dictionary<Guid, string>? hasProperties, int userRoles)
{ {
UserId = userId; UserId = userId;
UserType = userType; UserType = userType;
Email = email; UserName = userName;
HasProperties = hasProperties; HasProperties = hasProperties;
//UserRoles = userRoles; //UserRoles = userRoles;
//UserRolesDictionary = new Dictionary<int, string>(); //UserRolesDictionary = new Dictionary<int, string>();

View File

@ -27,6 +27,7 @@
<ProjectReference Include="..\..\TIAM.Entities.Server\TIAM.Entities.Server.csproj" /> <ProjectReference Include="..\..\TIAM.Entities.Server\TIAM.Entities.Server.csproj" />
<ProjectReference Include="..\..\TIAM.Entities\TIAM.Entities.csproj" /> <ProjectReference Include="..\..\TIAM.Entities\TIAM.Entities.csproj" />
<ProjectReference Include="..\..\TIAM.Models\TIAM.Models.csproj" /> <ProjectReference Include="..\..\TIAM.Models\TIAM.Models.csproj" />
<ProjectReference Include="..\..\TIAMResources\TIAM.Resources.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -33,9 +33,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AyCode.Blazor.Models", "..\
EndProject 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}" 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 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 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution 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}.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.ActiveCfg = Release|Any CPU
{A36322E8-F485-455E-84AA-B911948B6702}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE