From 8059ed50b1ec90813ee600271ced1f6e2b4bd776 Mon Sep 17 00:00:00 2001 From: Loretta Date: Sat, 29 Jun 2024 22:27:33 +0200 Subject: [PATCH] EfCore Tracking fix; Implement FilterText to TiamGrid/DataSource; Implement multiple Context[Id]s params to SignalRClient; improvements, fixes, etc... --- TIAM.Core/TIAM.Core.csproj | 1 + TIAM.Database/DataLayers/Admins/AdminDal.cs | 20 +++++- TIAM.Database/DbContexts/DbContextBase.cs | 5 +- TIAM.Database/TIAM.Database.csproj | 1 + TIAM.Services/SignalRTags.cs | 2 + .../User/SysAdmins/ManageTransfers.razor | 37 ++++++---- .../TransferToDriverGridComponent.razor | 2 +- .../Shared/Components/Grids/TiamGrid.cs | 30 +++++++- .../Shared/Components/Grids/TransferGrid.cs | 2 +- .../Controllers/TransferDataAPIController.cs | 20 +++++- TIAMWebApp/Server/Program.cs | 3 +- .../Server/Services/DevAdminSignalRhub.cs | 70 ++++++++++++++----- TIAMWebApp/Server/TIAMWebApp.Server.csproj | 3 +- .../Services/ServiceProviderDataService.cs | 8 +-- .../SignalRClientTest.cs | 59 +++++++++++++--- .../SignalRDataSourceTest.cs | 3 +- 16 files changed, 214 insertions(+), 52 deletions(-) diff --git a/TIAM.Core/TIAM.Core.csproj b/TIAM.Core/TIAM.Core.csproj index 80a5e673..0b829b7b 100644 --- a/TIAM.Core/TIAM.Core.csproj +++ b/TIAM.Core/TIAM.Core.csproj @@ -11,6 +11,7 @@ + diff --git a/TIAM.Database/DataLayers/Admins/AdminDal.cs b/TIAM.Database/DataLayers/Admins/AdminDal.cs index 2045cfc0..f3b815f3 100644 --- a/TIAM.Database/DataLayers/Admins/AdminDal.cs +++ b/TIAM.Database/DataLayers/Admins/AdminDal.cs @@ -1,4 +1,5 @@ -using AyCode.Core.Extensions; +using System.Linq.Expressions; +using AyCode.Core.Extensions; using AyCode.Core.Server.Loggers; using AyCode.Database.DbSets.Messages; using AyCode.Database.DbSets.Users; @@ -23,6 +24,9 @@ using TIAM.Entities.Transfers; using TIAM.Entities.Users; using TIAM.Models.Dtos.Products; using AyCode.Database.DbSets.Profiles; +using DevExpress.Data.Filtering; +using DevExpress.Data.Linq; +using DevExpress.Data.Linq.Helpers; using TIAM.Database.DbSets.Drivers; namespace TIAM.Database.DataLayers.Admins @@ -47,6 +51,8 @@ namespace TIAM.Database.DataLayers.Admins #region Transfer + public Task> GetTransfersByFilterAsync(CriteriaOperator criteriaOperator) => SessionAsync(ctx => (ctx.GetTransfers().AppendWhere(new CriteriaToExpressionConverter(), criteriaOperator) as IQueryable)!.ToList()); + public Task> GetTransfersAsync() => SessionAsync(ctx => ctx.GetTransfers().OrderBy(x => x.TransferStatusType).ThenByDescending(x => x.OrderId).ToList()); public Task GetTransfersJsonAsync() => SessionAsync(ctx => ctx.GetTransfers().OrderBy(x => x.TransferStatusType).ThenByDescending(x => x.OrderId).ToJson()); public Task GetTransfersByUserIdJsonAsync(Guid userId) => SessionAsync(ctx => ctx.GetTransfers().Where(x => x.UserId == userId).OrderBy(x => x.TransferStatusType).ThenByDescending(x => x.OrderId).ToJson()); @@ -55,7 +61,17 @@ namespace TIAM.Database.DataLayers.Admins public string? GetTransferJsonById(Guid transferId) => Session(ctx => ctx.GetTransferById(transferId)?.ToJson()); public Task AddTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.AddTransfer(transfer)); - public Task UpdateTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.UpdateTransfer(transfer)); + public Task UpdateTransferAsync(Transfer transfer) => TransactionAsync(ctx => + { + //foreach (var entityEntry in ctx.ChangeTracker.Entries()) + //{ + // if (entityEntry.Entity is not Transfer) + // entityEntry.State = EntityState.Unchanged; + //} + + //transfer.TransferToDrivers = null!; + return ctx.UpdateTransfer(transfer); + }); public Task UpdateTransferAsync(Transfer transfer, TransferToDriver transferToDriver) => UpdateTransferAsync(transfer, [transferToDriver]); public Task UpdateTransferAsync(Transfer transfer, List transferToDrivers) diff --git a/TIAM.Database/DbContexts/DbContextBase.cs b/TIAM.Database/DbContexts/DbContextBase.cs index ebd7f15c..890f9165 100644 --- a/TIAM.Database/DbContexts/DbContextBase.cs +++ b/TIAM.Database/DbContexts/DbContextBase.cs @@ -1,5 +1,6 @@ using AyCode.Database.DbContexts; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; namespace TIAM.Database.DbContexts { @@ -22,9 +23,11 @@ namespace TIAM.Database.DbContexts { base.OnConfiguring(optionsBuilder); - optionsBuilder.UseLazyLoadingProxies(true); + optionsBuilder.UseLazyLoadingProxies(false); optionsBuilder.EnableDetailedErrors(true); + optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTrackingWithIdentityResolution); + //optionsBuilder.UseSqlServer(Configuration.GetConnectionString("DeveloperDbConnection")); //var connString = "Data Source=185.51.190.197;Initial Catalog=TIAM_DEV;Trusted_Connection=false;Encrypt=false;TrustServerCertificate=True;Connect Timeout=200;User ID=Anata_Development_Team;Password=v6f_?xNfg9N1;MultipleActiveResultSets=true"; //optionsBuilder.UseSqlServer(connString); diff --git a/TIAM.Database/TIAM.Database.csproj b/TIAM.Database/TIAM.Database.csproj index 289aa5f0..86d68894 100644 --- a/TIAM.Database/TIAM.Database.csproj +++ b/TIAM.Database/TIAM.Database.csproj @@ -7,6 +7,7 @@ + diff --git a/TIAM.Services/SignalRTags.cs b/TIAM.Services/SignalRTags.cs index d0265c46..8f6c79cc 100644 --- a/TIAM.Services/SignalRTags.cs +++ b/TIAM.Services/SignalRTags.cs @@ -11,6 +11,8 @@ public class SignalRTags : AcSignalRTags public const int GetTransfersByProductId = 5; public const int GetTransfersByCompanyId = 6; + public const int GetTransfersByFilterText = 301; + public const int UpdateTransfer = 7; public const int AddTransfer = 8; public const int RemoveTransfer = 9; diff --git a/TIAMSharedUI/Pages/User/SysAdmins/ManageTransfers.razor b/TIAMSharedUI/Pages/User/SysAdmins/ManageTransfers.razor index ee196f41..969edaad 100644 --- a/TIAMSharedUI/Pages/User/SysAdmins/ManageTransfers.razor +++ b/TIAMSharedUI/Pages/User/SysAdmins/ManageTransfers.razor @@ -82,6 +82,8 @@
- @@ -235,11 +237,9 @@ private bool _popupVisible; private TransferGrid _gridTransfer; + private DxTagBox _filterTag; - List SelectedCategories { get; set; } - = Statuses.Where(x => x.StatusValue != (byte)TransferStatusType.Finished && x.StatusValue != (byte)TransferStatusType.UserCanceled && x.StatusValue != (byte)TransferStatusType.AdminDenied).ToList(); - public List IgnoreList = [ "ReceiverEmailAddress", @@ -251,7 +251,7 @@ "ContextId", ]; - public static List Statuses { get; set; } = + private static List Statuses = [ new(Convert.ToByte(TransferStatusType.OrderSubmitted), "Order submitted"), new(Convert.ToByte(TransferStatusType.OrderConfirmed), "Order confirmed"), @@ -264,6 +264,9 @@ new(Convert.ToByte(TransferStatusType.AdminDenied), "Admin cancelled") ]; + private static List _selectedCategories = Statuses.Where(x => x.StatusValue != (byte)TransferStatusType.Finished && x.StatusValue != (byte)TransferStatusType.UserCanceled && x.StatusValue != (byte)TransferStatusType.AdminDenied).ToList(); + private string? _filterText = GetFilterText(_selectedCategories.Select(x => (TransferStatusType)x.StatusValue).ToList()); + private MessageWizardModel _messageWizardModel = new(); public List AppointmentModels { get; set; } = null!; @@ -375,24 +378,34 @@ transferEditModel.ContactEmail = "your@email.address"; } + private static string? GetFilterText(ICollection selectedTransferStatuses) + => selectedTransferStatuses.Count == 0 ? null : CriteriaOperator.FromLambda(t => selectedTransferStatuses.Contains(t.TransferStatusType)).ToString(); + void TagBox_ValuesChanged(IEnumerable newSelectedCategories) { - SelectedCategories = newSelectedCategories.ToList(); - var filterCriteria = SelectedCategories.Any() - ? new InOperator("TransferStatusType", SelectedCategories.Select(c => c.StatusValue)) - : null; + string? filterText = null; + InOperator? filterCriteria = null; + _selectedCategories = newSelectedCategories.ToList(); + + if (_selectedCategories.Count > 0) + { + filterCriteria = new InOperator("TransferStatusType", _selectedCategories.Select(c => c.StatusValue)); + filterText = GetFilterText(_selectedCategories.Select(x => (TransferStatusType)x.StatusValue).ToList()); + } + + _filterText = filterText; _gridTransfer.SetFieldFilterCriteria("TransferStatusType", filterCriteria); } - + private void DataSourceChanged(IList transfers) { _logger.Info("DataSourceChanged called"); InitializeAppointments(transfers); - if (SelectedCategories.Count > 0) - TagBox_ValuesChanged(SelectedCategories); + if (_selectedCategories.Count > 0) + TagBox_ValuesChanged(_selectedCategories); // if(!SelectedCategories.Any()) // SelectedCategories = [Statuses.FirstOrDefault(x => x.StatusValue == (byte)TransferStatusType.Finished)!]; diff --git a/TIAMSharedUI/Pages/User/SysAdmins/TransferToDriverGridComponent.razor b/TIAMSharedUI/Pages/User/SysAdmins/TransferToDriverGridComponent.razor index 15f479c4..366d9d23 100644 --- a/TIAMSharedUI/Pages/User/SysAdmins/TransferToDriverGridComponent.razor +++ b/TIAMSharedUI/Pages/User/SysAdmins/TransferToDriverGridComponent.razor @@ -147,7 +147,7 @@ _logger.Info($"DetailGridData: {ParentData.TransferToDrivers.Count}"); - _cars.AddRange((await AdminSignalRClient.GetAllAsync>(SignalRTags.GetAllCarsByProductId, TiamConstClient.TransferProductId))!); + _cars.AddRange((await AdminSignalRClient.GetAllAsync>(SignalRTags.GetAllCarsByProductId, [TiamConstClient.TransferProductId]))!); // AdminSignalRClient.GetAllAsync>(SignalRTags.GetAllCars, response => // { // _cars.AddRange(response.ResponseData!); diff --git a/TIAMSharedUI/Shared/Components/Grids/TiamGrid.cs b/TIAMSharedUI/Shared/Components/Grids/TiamGrid.cs index bff22c58..b504101d 100644 --- a/TIAMSharedUI/Shared/Components/Grids/TiamGrid.cs +++ b/TIAMSharedUI/Shared/Components/Grids/TiamGrid.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.Data.Common; using AyCode.Blazor.Components.Services; using AyCode.Core; using AyCode.Core.Enums; @@ -9,6 +10,8 @@ using AyCode.Services.SignalRs; using AyCode.Utils.Extensions; using DevExpress.Blazor; using Microsoft.AspNetCore.Components; +using TIAM.Core.Enums; +using TIAM.Entities.Transfers; using TIAM.Services; using TIAMWebApp.Shared.Application.Services; using TIAMWebApp.Shared.Application.Utility; @@ -29,6 +32,25 @@ namespace TIAMSharedUI.Shared.Components.Grids [Parameter] public LoggerClient Logger { get; set; } [Parameter] public string GridName { get; set; } [Parameter] public Guid[]? ContextIds { get; set; } + + private string? _filterText = null; + + [Parameter] + public string? FilterText + { + get => _filterText; + set + { + _filterText = value; + + if (_dataSource != null! && _dataSource.FilterText != value) + { + _dataSource.FilterText = value; + LoadDataSourceAsync().Forget(); + } + } + } + [Parameter] public AcSignalRClientBase SignalRClient { get; set; } [Parameter] public int GetAllMessageTag { get; set; } @@ -83,6 +105,7 @@ namespace TIAMSharedUI.Shared.Components.Grids var crudTags = new SignalRCrudTags(GetAllMessageTag, GetItemMessageTag, AddMessageTag, UpdateMessageTag, RemoveMessageTag); _dataSource = new SignalRDataSource(SignalRClient, crudTags, ContextIds); + _dataSource.FilterText = FilterText; Data = _dataSource; @@ -111,7 +134,7 @@ namespace TIAMSharedUI.Shared.Components.Grids private Task OnDataSourceLoaded() { - Logger.Debug($"{_gridLogName} OnDataSourceLoaded"); + Logger.Debug($"{_gridLogName} OnDataSourceLoaded; Count: {_dataSource.Count}"); Reload(); //_dataSource.LoadItem(_dataSource.First().Id).Forget(); @@ -303,6 +326,11 @@ namespace TIAMSharedUI.Shared.Components.Grids return _dataSource.Remove(dataItem, true); } + + public Task LoadDataSourceAsync() + { + return _dataSource.LoadDataSourceAsync(false); + } } public class GridDataItemChangingEventArgs : GridDataItemChangedEventArgs where TDataItem : class, IId diff --git a/TIAMSharedUI/Shared/Components/Grids/TransferGrid.cs b/TIAMSharedUI/Shared/Components/Grids/TransferGrid.cs index 908341d4..d09b6794 100644 --- a/TIAMSharedUI/Shared/Components/Grids/TransferGrid.cs +++ b/TIAMSharedUI/Shared/Components/Grids/TransferGrid.cs @@ -8,7 +8,7 @@ public class TransferGrid : TiamGrid { public TransferGrid() : base() { - GetAllMessageTag = SignalRTags.GetTransfers; + GetAllMessageTag = SignalRTags.GetTransfersByFilterText;//SignalRTags.GetTransfers; AddMessageTag = SignalRTags.AddTransfer; UpdateMessageTag = SignalRTags.UpdateTransfer; RemoveMessageTag = SignalRTags.RemoveTransfer; diff --git a/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs b/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs index 1b0f7c12..62a8e96d 100644 --- a/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs +++ b/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs @@ -1,3 +1,4 @@ +using System.Linq.Expressions; using System.Text.Json; using AyCode.Core.Loggers; using AyCode.Services.SignalRs; @@ -22,6 +23,12 @@ using AyCode.Core.Extensions; using TIAM.Entities.Users; using TIAMSharedUI.Shared.Components.Grids; using AyCode.Core.Helpers; +using System.Linq; +using DevExpress.Data.Filtering; +using DevExpress.Data.Linq; +using DevExpress.Data.Linq.Helpers; +using System; +using TIAM.Database.DbSets.Transfers; namespace TIAMWebApp.Server.Controllers { @@ -540,12 +547,12 @@ namespace TIAMWebApp.Server.Controllers [HttpGet] [Route(APIUrls.GetTransfersRouteName)] [SignalR(SignalRTags.GetTransfers)] - public async Task GetTransfers() + public async Task> GetTransfers() { //var token = _authService.GetAuthTokenFromRequest(Request); //_logger.Detail(token); - var result = await _adminDal.GetTransfersJsonAsync(); + var result = await _adminDal.GetTransfersAsync(); return result; } @@ -559,6 +566,15 @@ namespace TIAMWebApp.Server.Controllers return result; } + [SignalR(SignalRTags.GetTransfersByFilterText)] + public async Task> GetTransfersByFilterText(Guid userId, string criteriaOperatorText) + { + if (criteriaOperatorText.IsNullOrWhiteSpace()) return await GetTransfers(); + + var results = await _adminDal.GetTransfersByFilterAsync(CriteriaOperator.Parse(criteriaOperatorText)); + return results; + } + [AllowAnonymous] [HttpPost] [Route(APIUrls.GetTransferByIdRouteName)] diff --git a/TIAMWebApp/Server/Program.cs b/TIAMWebApp/Server/Program.cs index 632d0df8..dde2497f 100644 --- a/TIAMWebApp/Server/Program.cs +++ b/TIAMWebApp/Server/Program.cs @@ -18,6 +18,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.ResponseCompression; using System.IO.Compression; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; +using Microsoft.EntityFrameworkCore; var builder = WebApplication.CreateBuilder(args); @@ -44,7 +45,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddSignalR(options => options.MaximumReceiveMessageSize = 256 * 1024);//.AddMessagePackProtocol(options => options.SerializerOptions = MessagePackSerializerOptions.Standard.WithSecurity(MessagePackSecurity.UntrustedData)); +builder.Services.AddSignalR(options => options.MaximumReceiveMessageSize = 102400 * 1024);//.AddMessagePackProtocol(options => options.SerializerOptions = MessagePackSerializerOptions.Standard.WithSecurity(MessagePackSecurity.UntrustedData)); builder.Services.AddCors(options => { diff --git a/TIAMWebApp/Server/Services/DevAdminSignalRhub.cs b/TIAMWebApp/Server/Services/DevAdminSignalRhub.cs index 4c3f1b73..563ee137 100644 --- a/TIAMWebApp/Server/Services/DevAdminSignalRhub.cs +++ b/TIAMWebApp/Server/Services/DevAdminSignalRhub.cs @@ -13,11 +13,16 @@ using TIAM.Entities.ServiceProviders; using System.Runtime.CompilerServices; using MessagePack; using TIAM.Entities.Addresses; -using TIAM.Entities.Profiles; using Microsoft.AspNetCore.Hosting; using System.Collections.Generic; +using System.ComponentModel; +using System.Linq.Expressions; +using AutoMapper; +using DevExpress.Pdf.Native.BouncyCastle.Security; using TIAM.Entities.Emails; using TIAM.Services.Server; +using Profile = TIAM.Entities.Profiles.Profile; +using Serialize.Linq.Serializers; namespace TIAMWebApp.Server.Services; @@ -37,7 +42,7 @@ public static class ExtensionMethods public class MethodInfoModel where TAttribute : TagAttribute { - public Type? ParameterType { get; init; } = null; + public ParameterInfo[]? ParamInfos { get; init; } = null; public TAttribute Attribute { get; init; } public MethodInfo MethodInfo { get; init; } @@ -51,8 +56,7 @@ public class MethodInfoModel where TAttribute : TagAttribute //if (parameters.Length > 1) // throw new Exception("MethodInfoModel; parameters.Length > 1"); - if (parameters.Length > 0) - ParameterType = parameters[0].ParameterType; + ParamInfos = parameters; } } @@ -148,27 +152,59 @@ public class DevAdminSignalRHub : Hub, IAcSignalRHubServe logText = $"Found dynamic method for the tag! tag: {messageTag}; method: {methodsByDeclaringObject.InstanceObject.GetType().Name}.{methodInfoModel.MethodInfo.Name}"; - if (methodInfoModel.ParameterType != null) + if (methodInfoModel.ParamInfos is { Length: > 0 }) { - _logger.Debug($"{logText}({methodInfoModel.ParameterType.Name})"); + _logger.Debug($"{logText}({string.Join(", ", methodInfoModel.ParamInfos.Select(x => x.Name))})"); - //paramValues = new object[1]; + paramValues = new object[methodInfoModel.ParamInfos.Length]; - if (methodInfoModel.ParameterType == typeof(Guid) || methodInfoModel.ParameterType == typeof(Guid?)) + var firstParamType = methodInfoModel.ParamInfos[0].ParameterType; + if (methodInfoModel.ParamInfos.Length > 1 || firstParamType == typeof(string) || firstParamType == typeof(Guid) || firstParamType == typeof(Guid?)) { var msg = message!.MessagePackTo>(); - paramValues = new object[msg.PostData.Ids.Count]; - for (var i = 0; i < msg.PostData.Ids.Count; i++) { - var id = msg.PostData.Ids[i]; - if (id.IsNullOrEmpty()) throw new NullReferenceException($"PostData.Id.IsNullOrEmpty(); Ids: {msg.PostData.Ids}"); + //var obj = (string)msg.PostData.Ids[i]; + //if (msg.PostData.Ids[i] is Guid id) + //{ + // if (id.IsNullOrEmpty()) throw new NullReferenceException($"PostData.Id.IsNullOrEmpty(); Ids: {msg.PostData.Ids}"); + // paramValues[i] = id; + //} + //else if (Guid.TryParse(obj, out id)) + //{ + // if (id.IsNullOrEmpty()) throw new NullReferenceException($"PostData.Id.IsNullOrEmpty(); Ids: {msg.PostData.Ids}"); + // paramValues[i] = id; + //} + //else if (Enum.TryParse(methodInfoModel.ParameterType, obj, out var enumObj)) + //{ + // paramValues[i] = enumObj; + //} + //else paramValues[i] = Convert.ChangeType(obj, methodInfoModel.ParameterType); + + var obj = msg.PostData.Ids[i]; + //var config = new MapperConfiguration(cfg => + //{ + // cfg.CreateMap(obj.GetType(), methodInfoModel.ParameterType); + //}); + + //var mapper = new Mapper(config); + //paramValues[i] = mapper.Map(obj, methodInfoModel.ParameterType); + + //paramValues[i] = obj; + + var a = Array.CreateInstance(methodInfoModel.ParamInfos[i].ParameterType, 1); + + if (methodInfoModel.ParamInfos[i].ParameterType == typeof(Expression)) + { + var serializer = new ExpressionSerializer(new JsonSerializer()); + paramValues[i] = serializer.DeserializeText((string)(obj.JsonTo(a.GetType()) as Array)?.GetValue(0)!); + } + else paramValues[i] = (obj.JsonTo(a.GetType()) as Array)?.GetValue(0)!; - paramValues[i] = msg.PostData.Ids[i]; } } - else paramValues = [message!.MessagePackTo>(MessagePackSerializerOptions.Standard).PostDataJson.JsonTo(methodInfoModel.ParameterType)!]; + else paramValues[0] = message!.MessagePackTo>(MessagePackSerializerOptions.Standard).PostDataJson.JsonTo(firstParamType)!; } else _logger.Debug($"{logText}()"); @@ -182,7 +218,8 @@ public class DevAdminSignalRHub : Hub, IAcSignalRHubServe switch (messageTag) { case SignalRTags.GetAddress: - var id = message!.MessagePackTo>().PostData.Ids[0]; + //var id = Guid.Parse((string)message!.MessagePackTo>().PostData.Ids[0]); + var id = message!.MessagePackTo>().PostData.Ids[0].JsonTo()![0]; var address = await _adminDal.GetAddressByIdAsync(id); await ResponseToCaller(messageTag, new SignalResponseJsonMessage(SignalResponseStatus.Success, address), requestId); @@ -190,7 +227,8 @@ public class DevAdminSignalRHub : Hub, IAcSignalRHubServe return; case SignalRTags.GetAddressesByContextId: - id = message!.MessagePackTo>().PostData.Ids[0]; + //id = Guid.Parse((string)message!.MessagePackTo>().PostData.Ids[0]); + id = message!.MessagePackTo>().PostData.Ids[0].JsonTo()![0]; address = await _adminDal.GetAddressByIdAsync(id); await ResponseToCaller(messageTag, new SignalResponseJsonMessage(SignalResponseStatus.Success, new List
{ address! }), requestId); diff --git a/TIAMWebApp/Server/TIAMWebApp.Server.csproj b/TIAMWebApp/Server/TIAMWebApp.Server.csproj index a308fd34..a18eebbd 100644 --- a/TIAMWebApp/Server/TIAMWebApp.Server.csproj +++ b/TIAMWebApp/Server/TIAMWebApp.Server.csproj @@ -10,7 +10,8 @@ - + + diff --git a/TIAMWebApp/Shared/Services/ServiceProviderDataService.cs b/TIAMWebApp/Shared/Services/ServiceProviderDataService.cs index c09d6cbe..57bce8f9 100644 --- a/TIAMWebApp/Shared/Services/ServiceProviderDataService.cs +++ b/TIAMWebApp/Shared/Services/ServiceProviderDataService.cs @@ -123,13 +123,13 @@ namespace TIAMWebApp.Shared.Application.Services callback.Invoke(response.ResponseData); return Task.CompletedTask; - }, id); + }, [id]); } //17. public async Task?> GetPropertiesByOwnerIdAsync(Guid id) { - var companyPropertiesByOwner = await _adminSignalRClient.GetByIdAsync>(SignalRTags.GetPropertiesByOwnerId, id); + var companyPropertiesByOwner = await _adminSignalRClient.GetByIdAsync>(SignalRTags.GetPropertiesByOwnerId, [id]); if (companyPropertiesByOwner != null) _logger.DetailConditional($"companyPropertiesByOwner: {string.Join("; ", companyPropertiesByOwner.Values)}"); return companyPropertiesByOwner; @@ -157,7 +157,7 @@ namespace TIAMWebApp.Shared.Application.Services //18. public async Task GetServiceProviderByIdAsync(Guid id) { - var company = await _adminSignalRClient.GetByIdAsync(SignalRTags.GetCompany, id); + var company = await _adminSignalRClient.GetByIdAsync(SignalRTags.GetCompany, [id]); if (company != null) _logger.DetailConditional($"company: {company.Name}"); return company; @@ -249,7 +249,7 @@ namespace TIAMWebApp.Shared.Application.Services public async Task GetProductByIdAsync(Guid id) { - var result = await _adminSignalRClient.GetByIdAsync(SignalRTags.GetProductById); + var result = await _adminSignalRClient.GetByIdAsync(SignalRTags.GetProductById, [id]); //var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetProductById}"; //var response = await http.GetFromJsonAsync(url, typeof(Product)); diff --git a/Tiam.Services.Client.Tests/SignalRClientTest.cs b/Tiam.Services.Client.Tests/SignalRClientTest.cs index 803a1890..5050e23b 100644 --- a/Tiam.Services.Client.Tests/SignalRClientTest.cs +++ b/Tiam.Services.Client.Tests/SignalRClientTest.cs @@ -4,6 +4,10 @@ using AyCode.Core.Loggers; using AyCode.Services.Loggers; using AyCode.Services.SignalRs; using Azure; +using DevExpress.Data.Filtering; +using DevExpress.Data.Linq; +using DevExpress.Data.Linq.Helpers; +using TIAM.Core.Enums; using TIAM.Core.Loggers; using TIAM.Database.Test; using TIAM.Entities.ServiceProviders; @@ -35,7 +39,7 @@ namespace Tiam.Services.Client.Tests public async Task GetCompanyTest_ReturnCompany_WhenHasCompany(string companyIdString) { var companyId = Guid.Parse(companyIdString); - var company = await _signalRClient.GetByIdAsync(SignalRTags.GetCompany, companyId); + var company = await _signalRClient.GetByIdAsync(SignalRTags.GetCompany, [companyId]); Assert.IsNotNull(company); } @@ -55,7 +59,7 @@ namespace Tiam.Services.Client.Tests company = response.ResponseData; return Task.CompletedTask; - }, companyId); + }, [companyId]); await TaskHelper.WaitToAsync(() => company != null, 5000, 50); @@ -115,7 +119,7 @@ namespace Tiam.Services.Client.Tests transferDest = await _signalRClient.PostDataAsync(SignalRTags.CreateTransferDestination, transferDest); Assert.IsNotNull(transferDest); - transferDest = await _signalRClient.GetByIdAsync(SignalRTags.GetTransferDestinationById, transferDestId); + transferDest = await _signalRClient.GetByIdAsync(SignalRTags.GetTransferDestinationById,[transferDestId]); Assert.IsNotNull(transferDest); Assert.IsNotNull(transferDest.Address); @@ -136,7 +140,7 @@ namespace Tiam.Services.Client.Tests await _signalRClient.PostDataAsync(SignalRTags.RemoveTransferDestination, transferDest); //mielõbb kitöröljük, h ne maradjon szemét a db-ben - J. - transferDest = await _signalRClient.GetByIdAsync(SignalRTags.GetTransferDestinationById, transferDestId); + transferDest = await _signalRClient.GetByIdAsync(SignalRTags.GetTransferDestinationById, [transferDestId]); Assert.IsNull(transferDest); //a korábbi törlés miatt NULL kell legyen - J. } @@ -155,7 +159,7 @@ namespace Tiam.Services.Client.Tests transferDestinationToProduct = await _signalRClient.PostDataAsync(SignalRTags.CreateTransferDestinationToProduct, transferDestinationToProduct); Assert.IsNotNull(transferDestinationToProduct); - transferDestinationToProduct = await _signalRClient.GetByIdAsync(SignalRTags.GetTransferDestinationToProductById, transferDestinationToProductId); + transferDestinationToProduct = await _signalRClient.GetByIdAsync(SignalRTags.GetTransferDestinationToProductById, [transferDestinationToProductId]); Assert.IsNotNull(transferDestinationToProduct); Assert.IsNotNull(transferDestinationToProduct.TransferDestination); @@ -169,20 +173,59 @@ namespace Tiam.Services.Client.Tests Assert.IsTrue((int)transferDestinationToProduct.Price == 20000); Assert.IsTrue(transferDestinationToProduct.Id == transferDestinationToProductId, "transferDestinationToProduct.Id != transferDestinationToProductId"); - var transferDestinationToProducts = await _signalRClient.GetByIdAsync>(SignalRTags.GetTransferDestinationToProductsByTransferDestinationId, transferDestId); + var transferDestinationToProducts = await _signalRClient.GetByIdAsync>(SignalRTags.GetTransferDestinationToProductsByTransferDestinationId, [transferDestId]); Assert.IsNotNull(transferDestinationToProducts); Assert.IsTrue(transferDestinationToProducts.Count > 0); Assert.IsTrue(transferDestinationToProducts.All(x=>x.TransferDestinationId == transferDestId)); - transferDestinationToProducts = await _signalRClient.GetByIdAsync>(SignalRTags.GetTransferDestinationToProductsByProductId, productId); + transferDestinationToProducts = await _signalRClient.GetByIdAsync>(SignalRTags.GetTransferDestinationToProductsByProductId, [productId]); Assert.IsNotNull(transferDestinationToProducts); Assert.IsTrue(transferDestinationToProducts.Count > 0); Assert.IsTrue(transferDestinationToProducts.All(x=>x.ProductId == productId)); await _signalRClient.PostDataAsync(SignalRTags.RemoveTransferDestinationToProduct, transferDestinationToProduct); //mielõbb kitöröljük, h ne maradjon szemét a db-ben - J. - transferDestinationToProduct = await _signalRClient.GetByIdAsync(SignalRTags.GetTransferDestinationToProductById, transferDestinationToProductId); + transferDestinationToProduct = await _signalRClient.GetByIdAsync(SignalRTags.GetTransferDestinationToProductById, [transferDestinationToProductId]); Assert.IsNull(transferDestinationToProduct); //a korábbi törlés miatt NULL kell legyen - J. } + + [DataTestMethod] + public async Task FilterExpressionTest_WhenTransfersFiletered() + { + var userId = Guid.Parse("540271F6-C604-4C16-8160-D5A7CAFEDF00"); + + var statuses = new List() { TransferStatusType.OrderConfirmed, TransferStatusType.AssignedToDriver, TransferStatusType.Finished }; + var converter = new CriteriaToExpressionConverter(); + var criteriaString = CriteriaOperator.FromLambda(x => x.UserId == userId && statuses.Contains(x.TransferStatusType)).ToString(); + + //var criteria = CriteriaOperator.Parse(criteriaString); + + //_signalRDataSource.AsQueryable().Expression. + //var filteredData = new List().AsQueryable().AppendWhere(converter, criteria) as IQueryable; + + var transfers = await _signalRClient.GetAllAsync>(SignalRTags.GetTransfersByFilterText, [Guid.NewGuid(), criteriaString]); + //var transfers = await _signalRClient.GetAllAsync>(SignalRTags.GetTransfersByExpression, [userId, filteredData!.Expression]); + + Assert.IsNotNull(transfers); + Assert.IsTrue(transfers.Count > 0); + Assert.IsTrue(transfers.All(x=>statuses.Contains(x.TransferStatusType))); + + //var converter = new CriteriaToExpressionConverter(); + ////CriteriaOperator critOps = CriteriaOperator.Parse(tdashboard.EmployeeFilter); + //var criteriaString = CriteriaOperator.FromLambda(x => x.LuggageCount == 1).ToString(); + + ////var json = criteria.AsQueryable().Expression.ToJson(); + ////criteria = JsonConvert.DeserializeObject(json); + //var criteria = CriteriaOperator.Parse(criteriaString); + + ////_signalRDataSource.AsQueryable().Expression. + //var filteredData = _signalRDataSource.AsQueryable().AppendWhere(converter, criteria) as IQueryable; + + //Assert.IsNotNull(filteredData); + //var filteredTransfers = _signalRDataSource.AsQueryable().Provider.CreateQuery(filteredData.Expression).ToList(); + + //Assert.IsNotNull(filteredTransfers); + //Assert.IsTrue(filteredTransfers.All(x => x.LuggageCount == 1)); + } } } \ No newline at end of file diff --git a/Tiam.Services.Client.Tests/SignalRDataSourceTest.cs b/Tiam.Services.Client.Tests/SignalRDataSourceTest.cs index 3821c7a4..8d2eb21c 100644 --- a/Tiam.Services.Client.Tests/SignalRDataSourceTest.cs +++ b/Tiam.Services.Client.Tests/SignalRDataSourceTest.cs @@ -75,7 +75,7 @@ namespace Tiam.Services.Client.Tests await _signalRDataSource.SaveItem(transferId, TrackingState.Update); Assert.IsTrue(transfer.LuggageCount == luggageCount); - var dbTransfer = await _signalRDataSource.SignalRClient.GetByIdAsync(SignalRTags.GetTransfer, transferId); + var dbTransfer = await _signalRDataSource.SignalRClient.GetByIdAsync(SignalRTags.GetTransfer, [transferId]); Assert.IsNotNull(dbTransfer); Assert.IsTrue(dbTransfer.LuggageCount == luggageCount); @@ -92,7 +92,6 @@ namespace Tiam.Services.Client.Tests //var json = criteria.AsQueryable().Expression.ToJson(); //criteria = JsonConvert.DeserializeObject(json); var criteria = CriteriaOperator.Parse(criteriaString); - //_signalRDataSource.AsQueryable().Expression. var filteredData = _signalRDataSource.AsQueryable().AppendWhere(converter, criteria) as IQueryable;