improvements, fixes, etc...

This commit is contained in:
Loretta 2024-07-01 08:58:15 +02:00
parent add3685a59
commit ef016d24ac
11 changed files with 142 additions and 72 deletions

View File

@ -40,6 +40,7 @@ namespace TIAM.Database.DataLayers.Admins
}
#region Car
public Task<List<Car>> GetAllCarsAsync() => SessionAsync(ctx => ctx.Cars.OrderBy(x => x.Manufacture).ThenBy(x => x.CarModel).ToList());
public Task<List<Car>> GetAllCarsbyProductIdAsync(Guid productId) => SessionAsync(ctx => ctx.Cars.Where(x => x.UserProductMapping.ProductId == productId).OrderBy(x => x.Manufacture).ThenBy(x => x.CarModel).ToList());
public Car? GetCarById(Guid carId) => Session(ctx => ctx.Cars.FirstOrDefault(x => x.Id == carId));
@ -102,7 +103,8 @@ namespace TIAM.Database.DataLayers.Admins
//}
public Task<bool> UpdateTransferAsync(Transfer transfer, TransferToDriver transferToDriver) => UpdateTransferAsync(transfer, [transferToDriver]);
public Task<bool> UpdateTransferAsync(Transfer transfer, List<TransferToDriver> transferToDrivers)
public Task<bool> UpdateTransferAsync(Transfer transfer, List<TransferToDriver> transferToDrivers)
=> TransactionAsync(ctx =>
{
ctx.AddRange(transferToDrivers);
@ -113,27 +115,31 @@ namespace TIAM.Database.DataLayers.Admins
public Task<bool> RemoveTransferAsync(Transfer transfer) => RemoveTransferAsync(transfer.Id);
public Task<bool> RemoveTransferAsync(Guid transferId) => TransactionAsync(ctx => ctx.RemoveTransfer(transferId));
#endregion Transfer
#region TransferDestination
public List<TransferDestination> GetTransferDestinations() => Session(ctx=>ctx.GetTransferDestinations().ToList());
public TransferDestination? GetTransferDestinationById(Guid transferDestinationId) => Session(ctx=>ctx.GetTransferDestinationById(transferDestinationId));
public Task<TransferDestination?> GetTransferDestinationByIdAsync(Guid transferDestinationId) => SessionAsync(ctx=>ctx.GetTransferDestinationById(transferDestinationId));
public List<TransferDestination> GetTransferDestinations() => Session(ctx => ctx.GetTransferDestinations().ToList());
public TransferDestination? GetTransferDestinationById(Guid transferDestinationId) => Session(ctx => ctx.GetTransferDestinationById(transferDestinationId));
public Task<TransferDestination?> GetTransferDestinationByIdAsync(Guid transferDestinationId) => SessionAsync(ctx => ctx.GetTransferDestinationById(transferDestinationId));
public string? GetTransferDestinationJsonById(Guid transferDestinationId) => Session(ctx => ctx.GetTransferDestinationById(transferDestinationId)?.ToJson());
public Task<bool> AddTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.AddTransferDestination(transferDestination));
public Task<bool> UpdateTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.UpdateTransferDestination(transferDestination));
public Task<bool> RemoveTransferDestinationAsync(TransferDestination transferDestination, bool removeAddress) => RemoveTransferDestinationAsync(transferDestination.Id, removeAddress);
public Task<bool> RemoveTransferDestinationAsync(Guid transferDestinationId, bool removeAddress) => TransactionAsync(ctx => ctx.RemoveTransferDestination(transferDestinationId, removeAddress));
#endregion TransferDestination
#region TransferToDriver
public Task<TransferToDriver?> GetTransferToDriverByIdAsync(Guid transferToDriverId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetTransferToDriverById(transferToDriverId, autoInclude));
public Task<List<TransferToDriver>> GetTransferToDriversByTransferIdAsync(Guid transferId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetTransferToDriversByTransferId(transferId, autoInclude).ToList());
public Task<bool> AddTransferToDriverAsync(TransferToDriver transferToDriver) => TransactionAsync(ctx => ctx.AddTransferToDriver(transferToDriver));
public Task<TransferToDriver?> UpdateTransferToDriverAsync(TransferToDriver transferToDriver)
public Task<TransferToDriver?> UpdateTransferToDriverAsync(TransferToDriver transferToDriver)
=> UpdateSafeAsync(transferToDriver, (ctx, safeTransferToDriver) => ctx.UpdateTransferToDriver(safeTransferToDriver));
//public async Task<TransferToDriver?> UpdateTransferToDriverAsync(TransferToDriver transferToDriver)
//{
@ -156,46 +162,53 @@ namespace TIAM.Database.DataLayers.Admins
//}
public Task<bool> RemoveTransferToDriverAsync(TransferToDriver transferToDriver) => TransactionAsync(ctx => ctx.RemoveTransferToDriver(transferToDriver.Id));
#endregion TransferToDriver
#region Drivers
public Task<List<UserProductMapping>> GetAllDriversAsync(bool autoInclude = true) => SessionAsync(ctx => ctx.GetAllDrivers(autoInclude).ToList());
public Task<List<UserProductMapping>> GetAllDriversByProductIdAsync(Guid productId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetAllDriversByProductId(productId, autoInclude).ToList());
#endregion Drivers
#region TransferDestinationToProduct
public TransferDestinationToProduct? GetTransferDestinationToProductById(Guid transferDestinationToProductId) => Session(ctx=>ctx.GetTransferDestinationToProductById(transferDestinationToProductId));
public Task<TransferDestinationToProduct?> GetTransferDestinationToProductByIdAsync(Guid transferDestinationToProductId) => SessionAsync(ctx=>ctx.GetTransferDestinationToProductById(transferDestinationToProductId));
public TransferDestinationToProduct? GetTransferDestinationToProductById(Guid transferDestinationToProductId) => Session(ctx => ctx.GetTransferDestinationToProductById(transferDestinationToProductId));
public Task<TransferDestinationToProduct?> GetTransferDestinationToProductByIdAsync(Guid transferDestinationToProductId) => SessionAsync(ctx => ctx.GetTransferDestinationToProductById(transferDestinationToProductId));
public string? GetTransferDestinationToProductJsonById(Guid transferDestinationToProductId) => Session(ctx => ctx.GetTransferDestinationToProductById(transferDestinationToProductId)?.ToJson());
public TransferDestinationToProduct? GetTransferDestinationToProduct(Guid productId, Guid transferDestinationId) => Session(ctx=>ctx.GetTransferDestinationToProduct(productId, transferDestinationId));
public Task<List<TransferDestinationToProduct>> GetTransferDestinationToProducts() => SessionAsync(ctx=>ctx.GetTransferDestinationToProducts().ToList());
public Task<List<TransferDestinationToProduct>> GetTransferDestinationToProductsByProductId(Guid productId) => SessionAsync(ctx=>ctx.GetTransferDestinationToProductsByProductId(productId).ToList());
public Task<List<TransferDestinationToProduct>> GetTransferDestinationToProductsByTransferDestinationId(Guid transferDestinationId) => SessionAsync(ctx=>ctx.GetTransferDestinationToProductsByTransferDestinationId(transferDestinationId).ToList());
public TransferDestinationToProduct? GetTransferDestinationToProduct(Guid productId, Guid transferDestinationId) => Session(ctx => ctx.GetTransferDestinationToProduct(productId, transferDestinationId));
public Task<List<TransferDestinationToProduct>> GetTransferDestinationToProducts() => SessionAsync(ctx => ctx.GetTransferDestinationToProducts().ToList());
public Task<List<TransferDestinationToProduct>> GetTransferDestinationToProductsByProductId(Guid productId) => SessionAsync(ctx => ctx.GetTransferDestinationToProductsByProductId(productId).ToList());
public Task<List<TransferDestinationToProduct>> GetTransferDestinationToProductsByTransferDestinationId(Guid transferDestinationId) => SessionAsync(ctx => ctx.GetTransferDestinationToProductsByTransferDestinationId(transferDestinationId).ToList());
public string? GetTransferDestinationToProductJson(Guid productId, Guid transferDestinationId) => Session(ctx => ctx.GetTransferDestinationToProduct(productId, transferDestinationId)?.ToJson());
public Task<bool> AddTransferDestinationToProductAsync(TransferDestinationToProduct transferDestinationToProduct) => TransactionAsync(ctx => ctx.AddTransferDestinationToProduct(transferDestinationToProduct));
public Task<bool> UpdateTransferDestinationToProductAsync(TransferDestinationToProduct transferDestinationToProduct) => TransactionAsync(ctx => ctx.UpdateTransferDestinationToProduct(transferDestinationToProduct));
public Task<bool> RemoveTransferDestinationToProductAsync(TransferDestinationToProduct transferDestinationToProduct) => RemoveTransferDestinationToProductAsync(transferDestinationToProduct.Id);
public Task<bool> RemoveTransferDestinationToProductAsync(Guid transferDestinationToProductId) => TransactionAsync(ctx => ctx.RemoveTransferDestinationToProduct(transferDestinationToProductId));
#endregion TransferDestinationToProduct
public User? GetUserById(Guid userId, bool autoInclude = false) => Session(ctx => ctx.GetUserById(userId, autoInclude));
public User? GetUserByEmail(string email, bool autoInclude = false) => Session(ctx => ctx.GetUserByEmail(email, autoInclude));
public TUserModelDto? GetUserModelDtoById<TUserModelDto>(Guid userId, bool onlyConfirmed) where TUserModelDto : class, IUserModelDtoMinBase
public TUserModelDto? GetUserModelDtoById<TUserModelDto>(Guid userId, bool onlyConfirmed) where TUserModelDto : class, IUserModelDtoMinBase
=> Session(ctx => ctx.GetUserModelDtoById<TUserModelDto, User>(userId, onlyConfirmed));
public Task<TUserModelDto?> GetUserModelDtoByIdAsync<TUserModelDto>(Guid userId, bool onlyConfirmed) where TUserModelDto : class, IUserModelDtoMinBase
public Task<TUserModelDto?> GetUserModelDtoByIdAsync<TUserModelDto>(Guid userId, bool onlyConfirmed) where TUserModelDto : class, IUserModelDtoMinBase
=> SessionAsync(ctx => ctx.GetUserModelDtoById<TUserModelDto, User>(userId, onlyConfirmed));
public TUserModelDto? GetUserModelDtoByEmail<TUserModelDto>(string email, bool onlyConfirmed) where TUserModelDto : class, IUserModelDtoMinBase
public TUserModelDto? GetUserModelDtoByEmail<TUserModelDto>(string email, bool onlyConfirmed) where TUserModelDto : class, IUserModelDtoMinBase
=> Session(ctx => ctx.GetUserModelDtoByEmail<TUserModelDto, User>(email, onlyConfirmed));
public Task<TUserModelDto?> GetUserModelDtoByEmailAsync<TUserModelDto>(string email, bool onlyConfirmed) where TUserModelDto : class, IUserModelDtoMinBase
public Task<TUserModelDto?> GetUserModelDtoByEmailAsync<TUserModelDto>(string email, bool onlyConfirmed) where TUserModelDto : class, IUserModelDtoMinBase
=> SessionAsync(ctx => ctx.GetUserModelDtoByEmail<TUserModelDto, User>(email, onlyConfirmed));
public string? GetUserJsonById(Guid userId, bool onlyConfirmed) => Session(ctx => ctx.GetUserById(userId, onlyConfirmed)?.ToJson());
public string GetUsersJson() => Session(ctx => ctx.Users.ToJson());
public Task<bool> AddUserAsync(User user) => TransactionAsync(ctx => ctx.AddUser(user));
public Task<bool> UpdateUserAsync(User user) => TransactionAsync(ctx => ctx.UpdateUser(user));
public Task<bool> RemoveUserAsync(Guid userId) => TransactionAsync(ctx => ctx.RemoveUser(userId));
@ -234,7 +247,8 @@ namespace TIAM.Database.DataLayers.Admins
=> SessionAsync(x => x.GetPermissionContextsViewByContextId(contextId).ToList());
#region UserProductMapping
public Task<bool> AddUserProductMappingAsync(UserProductMapping userProductMapping)
public Task<bool> AddUserProductMappingAsync(UserProductMapping userProductMapping)
=> TransactionAsync(ctx => ctx.AddUserProductMapping(userProductMapping));
public async Task<UserProductMapping?> AddUserProductMappingAsync(Guid userProductMappingId, Guid userId, Guid productId, int permissions = 1, UserProductJsonDetailModel? userProductToCars = null)
@ -244,7 +258,7 @@ namespace TIAM.Database.DataLayers.Admins
var isSucces = await TransactionAsync(ctx =>
{
userProductMapping = ctx.AddUserProductMapping(userProductMappingId, userId, productId, permissions, userProductToCars);
return userProductMapping != null;
});
@ -253,14 +267,14 @@ namespace TIAM.Database.DataLayers.Admins
public Task<bool> UpdateUserProductMappingAsync(UserProductMapping userProductMapping) => TransactionAsync(ctx => ctx.UpdateUserProductMapping(userProductMapping));
public async Task<UserProductMapping?> UpdateUserProductMappingAsync(Guid userProductMappingId, int permissions = 1, UserProductJsonDetailModel? userProductToCars = null)
public async Task<UserProductMapping?> UpdateUserProductMappingAsync(Guid userProductMappingId, int permissions = 1, UserProductJsonDetailModel? userProductToCars = null)
{
UserProductMapping? userProductMapping = null;
var isSucces = await TransactionAsync(ctx =>
{
userProductMapping = ctx.UpdateUserProductMapping(userProductMappingId, permissions, userProductToCars);
return userProductMapping != null;
});
@ -273,39 +287,46 @@ namespace TIAM.Database.DataLayers.Admins
#endregion UserProductMapping
#region Address
public Task<Address?> GetAddressByIdAsync(Guid addressId) => SessionAsync(ctx => ctx.GetAddressById(addressId));
public Task<bool> UpdateAddressAsync(Address adress) => TransactionAsync(ctx => ctx.UpdateAddress(adress));
#endregion Address
#region Profile
public Task<Profile?> GetProfileByIdAsync(Guid profileId) => SessionAsync(ctx => ctx.GetProfileById(profileId));
public Task<bool> UpdateProfileAsync(Profile profile) => TransactionAsync(ctx => ctx.UpdateProfile(profile));
//public Task<bool> AddProfileAsync(Profile profile) => TransactionAsync(ctx => ctx.AddProfile(profile)); //Nem Add-olunk önmagában Profile-t! - J.
//public Task<bool> RemoveProfileAsync(Guid profileId) => TransactionAsync(ctx => ctx.RemoveProfile(profileId)); //Nem törlünk Profile-t! - J.
#endregion Profile
#region EmailMessage
public Task<EmailMessage?> GetEmailMessageByIdAsync(Guid emailMessageId) => SessionAsync(ctx => ctx.GetEmailMessageById(emailMessageId));
public Task<List<EmailMessage>> GetEmailMessagesByContextIdAsync(Guid contextId) => SessionAsync(ctx => ctx.GetEmailMessagesByContextId(contextId).OrderByDescending(x=>x.Created).ToList());
public Task<List<EmailMessage>> GetEmailMessagesBySenderIdAsync(Guid senderId) => SessionAsync(ctx => ctx.GetEmailMessagesBySenderId(senderId).OrderByDescending(x=>x.Created).ToList());
public Task<List<EmailMessage>> GetEmailMessagesBySenderEmailAddressAsync(string emailAddress) => SessionAsync(ctx => ctx.GetEmailMessagesBySenderEmailAddress(emailAddress).OrderByDescending(x=>x.Created).ToList());
public Task<List<EmailMessage>> GetEmailMessagesAsync(Guid userId, Guid userProductMappingId) => SessionAsync(ctx => ctx.GetEmailMessages<EmailMessage, EmailRecipient>(userId, userProductMappingId).OrderByDescending(x=>x.Created).ToList());
public Task<List<EmailMessage>> GetEmailMessagesAsync(Guid contextId, Guid userId, Guid userProductMappingId) => SessionAsync(ctx => ctx.GetEmailMessages<EmailMessage, EmailRecipient>(contextId, userId, userProductMappingId).OrderByDescending(x=>x.Created).ToList());
public Task<List<EmailMessage>> GetAllEmailMessagesAsync() => SessionAsync(ctx => ctx.GetAllEmailMessages<EmailMessage, EmailRecipient>().OrderByDescending(x=>x.Created).ToList());
public Task<List<EmailMessage>> GetEmailMessagesByContextIdAsync(Guid contextId) => SessionAsync(ctx => ctx.GetEmailMessagesByContextId(contextId).OrderByDescending(x => x.Created).ToList());
public Task<List<EmailMessage>> GetEmailMessagesBySenderIdAsync(Guid senderId) => SessionAsync(ctx => ctx.GetEmailMessagesBySenderId(senderId).OrderByDescending(x => x.Created).ToList());
public Task<List<EmailMessage>> GetEmailMessagesBySenderEmailAddressAsync(string emailAddress) => SessionAsync(ctx => ctx.GetEmailMessagesBySenderEmailAddress(emailAddress).OrderByDescending(x => x.Created).ToList());
public Task<List<EmailMessage>> GetEmailMessagesAsync(Guid userId, Guid userProductMappingId) => SessionAsync(ctx => ctx.GetEmailMessages<EmailMessage, EmailRecipient>(userId, userProductMappingId).OrderByDescending(x => x.Created).ToList());
public Task<List<EmailMessage>> GetEmailMessagesAsync(Guid contextId, Guid userId, Guid userProductMappingId) => SessionAsync(ctx => ctx.GetEmailMessages<EmailMessage, EmailRecipient>(contextId, userId, userProductMappingId).OrderByDescending(x => x.Created).ToList());
public Task<List<EmailMessage>> GetAllEmailMessagesAsync() => SessionAsync(ctx => ctx.GetAllEmailMessages<EmailMessage, EmailRecipient>().OrderByDescending(x => x.Created).ToList());
public Task<bool> AddEmailMessageAsync(EmailMessage emailMessage)
=> TransactionAsync(ctx => ctx.AddEmailMessage(emailMessage));
public Task<bool> UpdateEmailMessageAsync(EmailMessage emailMessage)
public Task<bool> UpdateEmailMessageAsync(EmailMessage emailMessage)
=> TransactionAsync(ctx => ctx.UpdateEmailMessage(emailMessage));
public Task<bool> RemoveEmailMessageAsync(Guid emailMessageId)
public Task<bool> RemoveEmailMessageAsync(Guid emailMessageId)
=> TransactionAsync(ctx => ctx.RemoveEmailMessage(emailMessageId));
#endregion EmailMessage
#region ServiceProviders
//15. (IServiceProviderDataService) Create service provider
public Task<bool> AddCompanyAsync(Company serviceProvider) => TransactionAsync(ctx => ctx.AddCompany<Company, Profile, Address>(serviceProvider));
@ -313,7 +334,7 @@ namespace TIAM.Database.DataLayers.Admins
public Task<string> GetCompaniesJsonAsync() => SessionAsync(ctx => ctx.Companies.ToJson());
public string GetCompaniesJson() => Session(ctx => ctx.Companies.ToJson());
public virtual Task<Company?> GetCompanyByIdAsync(Guid id) => SessionAsync(ctx => ctx.GetCompanyById(id));
public virtual Task<List<Company>> GetCompaniesByOwnerIdAsync(Guid id) => SessionAsync(ctx => ctx.GetCompaniesByOwnerId(id));
@ -326,10 +347,12 @@ namespace TIAM.Database.DataLayers.Admins
//14. (IserviceProviderDataService) Update service provider
public Task<bool> UpdateCompanyAsync(Company company) => TransactionAsync(ctx => ctx.UpdateCompany(company));
//13. (IserviceProviderDataService) delete service provider
public Task<bool> RemoveCompanyAsync(Guid companyId) => TransactionAsync(ctx => ctx.RemoveProductsByCompanyId(companyId) && ctx.RemoveCompany(companyId));
//public Task<bool> RemoveCompanyAsync(Company company) => RemoveCompanyAsync(company.Id);
#endregion
#region PermissionTypes
@ -364,6 +387,7 @@ namespace TIAM.Database.DataLayers.Admins
{
nextBitValue = Math.Pow(2, 0);
}
permissionsType.PermissionBit = (int)nextBitValue;
Context.PermissionsTypes.Add(permissionsType);
Context.SaveChanges();
@ -376,6 +400,7 @@ namespace TIAM.Database.DataLayers.Admins
}
}
return Task.FromResult(result);
}
@ -465,6 +490,7 @@ namespace TIAM.Database.DataLayers.Admins
{
GlobalLogger.Info($@"GetPermissionsOfUserProductMappingsAndGroupsAsyncByContextId: {row.ContextId}, {row.SubjectId}, {row.SubjectType}, {row.Name}, {row.PermissionsValue}");
}
return Task.FromResult(result);
}
@ -500,6 +526,7 @@ namespace TIAM.Database.DataLayers.Admins
transaction.Commit();
result = true;
}
return Task.FromResult(result);
}
@ -534,6 +561,7 @@ namespace TIAM.Database.DataLayers.Admins
result = false;
}
}
return Task.FromResult(result);
}
@ -635,9 +663,9 @@ namespace TIAM.Database.DataLayers.Admins
#region Logs
public Task<List<AcLogItem>> GetLogItemsAsync(int takeCount = 100) => SessionAsync(ctx => ctx.LogItems.Where(x=>x.LogLevel != LogLevel.Debug && x.LogLevel != LogLevel.Trace && x.LogLevel != LogLevel.Detail).Take(takeCount).ToList());
public Task<List<AcLogItem>> GetLogItemsAsync(int takeCount = 500) => SessionAsync(ctx => ctx.LogItems.Take(takeCount).ToList());
public Task<List<AcLogItem>> GetLogItemsByFilterAsync(CriteriaOperator criteriaOperator, int takeCount = 500) => SessionAsync(ctx => (ctx.LogItems.AppendWhere(new CriteriaToExpressionConverter(), criteriaOperator).Take(takeCount) as IQueryable<AcLogItem>)!.ToList());
#endregion
}
}

View File

@ -14,15 +14,15 @@ public static class TransferDbSetExtensions
public static bool UpdateTransfer(this ITransferDbSet ctx, Transfer transfer)
=> ctx.Transfers.Update(transfer).State == EntityState.Modified;
public static bool UpdateTransferStatus(this ITransferDbSet ctx, Guid transferId, TransferStatusType transferStatusType)
public static bool UpdateTransferStatus(this ITransferDbSet ctx, Guid transferId, TransferStatusType transferStatusType, bool onlyStatusLowerThanNew = true)
{
var transfer = ctx.Transfers.FirstOrDefault(x => x.Id == transferId);
return transfer != null && ctx.UpdateTransferStatus(transfer, transferStatusType);
}
public static bool UpdateTransferStatus(this ITransferDbSet ctx, Transfer transfer, TransferStatusType transferStatusType)
public static bool UpdateTransferStatus(this ITransferDbSet ctx, Transfer transfer, TransferStatusType transferStatusType, bool onlyStatusLowerThanNew = true)
{
if (transfer.TransferStatusType == transferStatusType) return true;
if (transfer.TransferStatusType == transferStatusType || (onlyStatusLowerThanNew && transfer.TransferStatusType > transferStatusType)) return true;
transfer.TransferStatusType = transferStatusType;
return ctx.Transfers.Update(transfer).State == EntityState.Modified;

View File

@ -2,6 +2,7 @@
using AyCode.Interfaces.TimeStampInfo;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using AyCode.Interfaces.Profiles.Dtos;
using TIAM.Core.Enums;
using TIAM.Entities.Products;
@ -30,7 +31,9 @@ public class Transfer: IEntityGuid, IAcFullName, ITimeStampInfo, IProductForeign
public string? PaymentId { get; set; }
//public virtual UserProductMapping? UserProductMapping { get; set; }
public virtual List<TransferToDriver> TransferToDrivers { get; set; }
[JsonIgnore]
[Newtonsoft.Json.JsonIgnore]
public virtual List<TransferToDriver> TransferToDrivers { get; set; } = [];
[Required] public TransferStatusType TransferStatusType { get; set; } = TransferStatusType.OrderSubmitted;

View File

@ -95,6 +95,6 @@ public class SignalRTags : AcSignalRTags
public const int GetTransferDestinationToProductsByProductId = 95;
public const int GetTransferDestinationToProductsByTransferDestinationId = 96;
public const int GetAllLogItems = 100;
public const int GetAllLogItemsByFilterText = 100;
}

View File

@ -14,6 +14,9 @@
@using AyCode.Services.Loggers
@using AyCode.Core
@using AyCode.Core.Extensions
@using Castle.Components.DictionaryAdapter
@using DevExpress.Data.Filtering
@using TIAM.Core.Enums
@inject IServiceProviderDataService ServiceProviderDataService
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
@inject AdminSignalRClient AdminSignalRClient
@ -25,10 +28,12 @@
<LogViewerGrid Logger="_logger"
@ref="_logViewerGrid"
SignalRClient="AdminSignalRClient"
FilterText="@_filterText"
ShowGroupPanel="true"
PageSize="25"
PageSize="20"
PagerPosition="GridPagerPosition.TopAndBottom"
PageSizeSelectorVisible="true"
PageSizeSelectorItems="@(new int[] { 25, 50, 100, 200, 300, 400, 500 })"
PageSizeSelectorItems="@(new int[] { 20, 50, 100, 200, 300, 400, 500 })"
PageSizeSelectorAllRowsItemVisible="true"
ValidationEnabled="false"
CustomizeElement="Grid_CustomizeElement"
@ -51,18 +56,26 @@
var a = ((LogItemViewerModel)context.DataItem);
}
<div>@($"{a.CategoryName}->{a.CallerName}")</div>
<div>@($"{a.Text}")</div><br/>
<div>@($"{a.Text}")</div><br />
<div style="font-weight: bold;">Exception:</div>
<div style="word-wrap: break-word;">@a.Exception</div>
</DetailRowTemplate>
<ToolbarTemplate>
<div>
<DxTagBox Data="@(Enum.GetValues<LogLevel>().ToList())" Values="@_selectedLogLevels"
NullText="Select status type..." ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto" aria-label="Select status type"
ValuesChanged="(IEnumerable<LogLevel> values) => TagBox_ValuesChanged(values)" />
</div>
</ToolbarTemplate>
</LogViewerGrid>
@code {
[Parameter] public GridDetailExpandButtonDisplayMode DetailExpandButtonDisplayMode { get; set; } = GridDetailExpandButtonDisplayMode.Never;
private LoggerClient<LogViewerGridComponent> _logger;
private LogViewerGrid _logViewerGrid;
private LoggerClient<LogViewerGridComponent> _logger;
private static List<LogLevel> _selectedLogLevels = [LogLevel.Error, LogLevel.Warning, LogLevel.Suggest];
private static string _filterText = GetFilterText(_selectedLogLevels);
protected override void OnInitialized()
{
@ -71,11 +84,31 @@
base.OnInitialized();
}
private static string GetFilterText(ICollection<LogLevel> selectedLogLevels)
=> selectedLogLevels.Count == 0 ? string.Empty : CriteriaOperator.FromLambda<LogItemViewerModel>(t => selectedLogLevels.Contains(t.LogLevel)).ToString();
void TagBox_ValuesChanged(IEnumerable<LogLevel> newSelectedLogLevels)
{
var filterText = string.Empty;
InOperator? filterCriteria = null;
_selectedLogLevels = newSelectedLogLevels.ToList();
if (_selectedLogLevels.Count > 0)
{
filterCriteria = new InOperator(nameof(LogLevel), _selectedLogLevels);
filterText = GetFilterText(_selectedLogLevels);
}
_filterText = filterText;
_logViewerGrid.SetFieldFilterCriteria(nameof(LogLevel), filterCriteria);
}
void Grid_CustomizeElement(GridCustomizeElementEventArgs e)
{
if (e.ElementType != GridElementType.DataRow) return;
var logLevelObject = e.Grid?.GetRowValue(e.VisibleIndex, "LogLevel");
var logLevelObject = e.Grid?.GetRowValue(e.VisibleIndex, nameof(LogLevel));
if (logLevelObject == null) return;
var levelObject = (LogLevel)logLevelObject;

View File

@ -199,8 +199,8 @@
<div>
<DxTagBox Data="@Statuses" Values="@_selectedCategories" @ref="_filterTag"
ValuesChanged="(IEnumerable<TransferStatusModel> values) => TagBox_ValuesChanged(values)"
ValueFieldName="StatusValue" TextFieldName="StatusName" NullText="Select category..."
ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto" aria-label="Select category" />
ValueFieldName="StatusValue" TextFieldName="StatusName" NullText="Select status type..."
ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto" aria-label="Select status type" />
</div>
</ToolbarTemplate>
</TransferGrid>
@ -254,21 +254,21 @@
"ContextId",
];
private static List<TransferStatusModel> Statuses =
private static readonly List<TransferStatusModel> Statuses =
[
new(Convert.ToByte(TransferStatusType.OrderSubmitted), "Order submitted"),
new(Convert.ToByte(TransferStatusType.OrderConfirmed), "Order confirmed"),
new(Convert.ToByte(TransferStatusType.AssignedToDriver), "Assigned to driver"),
new(Convert.ToByte(TransferStatusType.DriverConfirmed), "Driver confirmed"),
new(Convert.ToByte(TransferStatusType.DriverEnRoute), "Driver enroute"),
new(Convert.ToByte(TransferStatusType.PassengerPickup), "Passenger in car"),
new(Convert.ToByte(TransferStatusType.Finished), "Finished"),
new(Convert.ToByte(TransferStatusType.UserCanceled), "User cancelled"),
new(Convert.ToByte(TransferStatusType.AdminDenied), "Admin cancelled")
new(Convert.ToByte(TransferStatusType.OrderConfirmed), "Order confirmed"),
new(Convert.ToByte(TransferStatusType.AssignedToDriver), "Assigned to driver"),
new(Convert.ToByte(TransferStatusType.DriverConfirmed), "Driver confirmed"),
new(Convert.ToByte(TransferStatusType.DriverEnRoute), "Driver enroute"),
new(Convert.ToByte(TransferStatusType.PassengerPickup), "Passenger in car"),
new(Convert.ToByte(TransferStatusType.Finished), "Finished"),
new(Convert.ToByte(TransferStatusType.UserCanceled), "User cancelled"),
new(Convert.ToByte(TransferStatusType.AdminDenied), "Admin cancelled")
];
private static List<TransferStatusModel> _selectedCategories = Statuses.Where(x => /* x.StatusValue != (byte)TransferStatusType.OrderSubmitted && */ 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 string _filterText = GetFilterText(_selectedCategories.Select(x => (TransferStatusType)x.StatusValue).ToList());
private MessageWizardModel _messageWizardModel = new();
@ -392,12 +392,12 @@
transferEditModel.ContactEmail = "your@email.address";
}
private static string? GetFilterText(ICollection<TransferStatusType> selectedTransferStatuses)
=> selectedTransferStatuses.Count == 0 ? null : CriteriaOperator.FromLambda<Transfer>(t => selectedTransferStatuses.Contains(t.TransferStatusType)).ToString();
private static string GetFilterText(ICollection<TransferStatusType> selectedTransferStatuses)
=> selectedTransferStatuses.Count == 0 ? string.Empty : CriteriaOperator.FromLambda<Transfer>(t => selectedTransferStatuses.Contains(t.TransferStatusType)).ToString();
void TagBox_ValuesChanged(IEnumerable<TransferStatusModel> newSelectedCategories)
{
string? filterText = null;
var filterText = string.Empty;
InOperator? filterCriteria = null;
_selectedCategories = newSelectedCategories.ToList();

View File

@ -40,7 +40,7 @@
</CellDisplayTemplate>
</DxGridDataColumn>
<DxGridDataColumn FieldName="IsReaded" Caption="Readed" Width="70" CaptionAlignment="GridTextAlignment.Center" TextAlignment="GridTextAlignment.Center" />
<DxGridDataColumn FieldName="Created" DisplayFormat="g" Width="100" SortIndex="0" SortOrder="GridColumnSortOrder.Descending" CaptionAlignment="GridTextAlignment.Center" TextAlignment="GridTextAlignment.Center" />
<DxGridDataColumn FieldName="Created" DisplayFormat="g" Width="130" SortIndex="0" SortOrder="GridColumnSortOrder.Descending" CaptionAlignment="GridTextAlignment.Center" TextAlignment="GridTextAlignment.Center" />
</Columns>
<DetailRowTemplate>
@{

View File

@ -39,7 +39,7 @@
<DxGridDataColumn FieldName="Latitude" Width="40" />
<DxGridDataColumn FieldName="Longitude" Width="40" />
<DxGridDataColumn FieldName="IsReaded" Caption="Readed" Width="70" CaptionAlignment="GridTextAlignment.Center" TextAlignment="GridTextAlignment.Center" />
<DxGridDataColumn FieldName="Created" DisplayFormat="g" Width="100" SortIndex="0" SortOrder="GridColumnSortOrder.Descending" CaptionAlignment="GridTextAlignment.Center" TextAlignment="GridTextAlignment.Center" />
<DxGridDataColumn FieldName="Created" DisplayFormat="g" Width="130" SortIndex="0" SortOrder="GridColumnSortOrder.Descending" CaptionAlignment="GridTextAlignment.Center" TextAlignment="GridTextAlignment.Center" />
</Columns>
<DetailRowTemplate>

View File

@ -11,7 +11,7 @@ public class LogViewerGrid : TiamGrid<LogItemViewerModel>
{
public LogViewerGrid() : base()
{
GetAllMessageTag = SignalRTags.GetAllLogItems;
GetAllMessageTag = SignalRTags.GetAllLogItemsByFilterText;
}
protected override Task SetParametersAsyncCore(ParameterView parameters)

View File

@ -1,10 +1,14 @@
using AyCode.Core.Consts;
using AyCode.Entities;
using AyCode.Entities.Server.LogItems;
using AyCode.Services.SignalRs;
using AyCode.Utils.Extensions;
using DevExpress.Data.Filtering;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using TIAM.Database.DataLayers.Admins;
using TIAM.Entities.Transfers;
using TIAM.Services;
using TIAMWebApp.Server.Services;
using TIAMWebApp.Shared.Application.Models;
@ -52,16 +56,18 @@ namespace TIAMWebApp.Server.Controllers
[AllowAnonymous]
[HttpGet]
[Route(APIUrls.GetAllLogItemsRouteName)]
[SignalR(SignalRTags.GetAllLogItems)]
public async Task<List<LogItemViewerModel>> GetAllLogItems()//(int takeCount, string filterText)
[SignalR(SignalRTags.GetAllLogItemsByFilterText)]
public async Task<List<LogItemViewerModel>> GetAllLogItems(string? criteriaOperatorText) //(int takeCount, string filterText)
{
var logItemList = await adminDal.GetLogItemsAsync(1000);
var resultList = new List<LogItemViewerModel>(logItemList.Count);
//public Task<List<Transfer>> GetTransfersByFilterAsync(CriteriaOperator criteriaOperator) => SessionAsync(ctx => (ctx.GetTransfers().AppendWhere(new CriteriaToExpressionConverter(), criteriaOperator) as IQueryable<Transfer>)!.ToList());
List<AcLogItem> logItemList;
foreach (var logItem in logItemList)
{
resultList.Add(new LogItemViewerModel(Guid.NewGuid(), logItem, logItem.LogHeaderId));
}
if (criteriaOperatorText.IsNullOrWhiteSpace()) logItemList = await adminDal.GetLogItemsAsync(1000);
else logItemList = await adminDal.GetLogItemsByFilterAsync(CriteriaOperator.Parse(criteriaOperatorText),1000);
var resultList = new List<LogItemViewerModel>(logItemList.Count);
//logItemList[0].ToModelDto<LogItemViewerModel, AcLogItem>();
resultList.AddRange(logItemList.Select(logItem => new LogItemViewerModel(logItem, logItem.LogHeaderId)));
return resultList;
}

View File

@ -8,21 +8,21 @@ using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AyCode.Interfaces;
namespace TIAMWebApp.Shared.Application.Models.ClientSide.UI
{
//[Table("LogItem")]
public class LogItemViewerModel : AcLogItemClient, IId<Guid>
public class LogItemViewerModel : AcLogItemClient, IId<Guid>, IAcModelDtoBase
{
public Guid Id { get ; set; }
public Guid Id { get ; set; } = Guid.NewGuid();
public int LogHeaderId { get; set; }
public LogItemViewerModel()
{}
public LogItemViewerModel(Guid id, IAcLogItemClient logItemClient, int logHeaderId) {
public LogItemViewerModel(IAcLogItemClient logItemClient, int logHeaderId) {
Id = id;
TimeStampUtc = logItemClient.TimeStampUtc;
AppType = logItemClient.AppType;
LogLevel= logItemClient.LogLevel;