This commit is contained in:
Adam 2024-06-30 15:49:50 +02:00
commit 4b2dbfb6ef
6 changed files with 155 additions and 121 deletions

View File

@ -251,7 +251,7 @@ namespace TIAM.Database.Test
product.Price = 30000;
product.UserProductMappings[0].Permissions = 2;
Assert.IsTrue(await Dal.UpdateProductAsync(product));
Assert.IsNotNull(await Dal.UpdateProductAsync(product));
product = await Dal.GetProductByIdAsync(productId);

View File

@ -63,41 +63,42 @@ namespace TIAM.Database.DataLayers.Admins
public Task<bool> AddTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.AddTransfer(transfer));
public async Task<Transfer?> UpdateTransferAsync(Transfer transfer)
{
Transfer? entity = null;
public Task<Transfer?> UpdateTransferAsync(Transfer transfer) => UpdateSafeAsync(transfer, (ctx, safeTransfer) => ctx.UpdateTransfer(safeTransfer));
//public async Task<Transfer?> UpdateTransferAsync(Transfer transfer)
//{
// Transfer? entity = null;
var result = await TransactionAsync(ctx =>
{
entity = ctx.Set<Transfer>().AsNoTracking().FirstOrDefault(e => e.Id == transfer.Id);
if (entity == null) return false;
// var result = await TransactionAsync(ctx =>
// {
// entity = ctx.Set<Transfer>().AsNoTracking().FirstOrDefault(e => e.Id == transfer.Id);
// if (entity == null) return false;
ctx.Entry(entity).State = EntityState.Detached;
ctx.Entry(entity).CurrentValues.SetValues(transfer);
// ctx.Entry(entity).State = EntityState.Detached;
// ctx.Entry(entity).CurrentValues.SetValues(transfer);
return ctx.UpdateTransfer(entity);
// return ctx.UpdateTransfer(entity);
//foreach (var entityEntry in ctx.ChangeTracker.Entries())
//{
// if (entityEntry.Entity is not Transfer)
// entityEntry.State = EntityState.Unchanged;
//}
// //foreach (var entityEntry in ctx.ChangeTracker.Entries())
// //{
// // if (entityEntry.Entity is not Transfer)
// // entityEntry.State = EntityState.Unchanged;
// //}
//var existingTransfer = ctx.Transfers.Local.SingleOrDefault(o => o.Id == transfer.Id);
//if (existingTransfer != null)
// ctx.Entry(existingTransfer).State = EntityState.Detached;
// //var existingTransfer = ctx.Transfers.Local.SingleOrDefault(o => o.Id == transfer.Id);
// //if (existingTransfer != null)
// // ctx.Entry(existingTransfer).State = EntityState.Detached;
//var existingUsers = ctx.Users.Local.Where(o => transfer.TransferToDrivers.Any(x => x.UserProductMapping.UserId == o.Id)).ToList();
//foreach (var existingUser in existingUsers)
// ctx.Entry(existingUser).State = EntityState.Detached;
// //var existingUsers = ctx.Users.Local.Where(o => transfer.TransferToDrivers.Any(x => x.UserProductMapping.UserId == o.Id)).ToList();
// //foreach (var existingUser in existingUsers)
// // ctx.Entry(existingUser).State = EntityState.Detached;
//transfer.TransferToDrivers = null!;
//return ctx.UpdateTransfer(transfer);
});
// //transfer.TransferToDrivers = null!;
return result ? entity : null;
}
// //return ctx.UpdateTransfer(transfer);
// });
// return result ? entity : null;
//}
public Task<bool> UpdateTransferAsync(Transfer transfer, TransferToDriver transferToDriver) => UpdateTransferAsync(transfer, [transferToDriver]);
public Task<bool> UpdateTransferAsync(Transfer transfer, List<TransferToDriver> transferToDrivers)
@ -130,25 +131,28 @@ namespace TIAM.Database.DataLayers.Admins
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 async Task<TransferToDriver?> UpdateTransferToDriverAsync(TransferToDriver transferToDriver)
{
var transferToDriverId = transferToDriver.Id;
TransferToDriver transferToDriver2 = null!;
var result = await TransactionAsync(ctx =>
{
transferToDriver2 = ctx.TransferToDrivers.FirstOrDefault(x => x.Id == transferToDriverId)!;
transferToDriver2.CarId = transferToDriver.CarId;
transferToDriver2.LicencePlate = transferToDriver.LicencePlate;
transferToDriver2.UserProductMappingId = transferToDriver.UserProductMappingId;
transferToDriver2.TransferId = transferToDriver.TransferId;
transferToDriver2.Price = transferToDriver.Price;
public Task<TransferToDriver?> UpdateTransferToDriverAsync(TransferToDriver transferToDriver)
=> UpdateSafeAsync(transferToDriver, (ctx, safeTransferToDriver) => ctx.UpdateTransferToDriver(safeTransferToDriver));
//public async Task<TransferToDriver?> UpdateTransferToDriverAsync(TransferToDriver transferToDriver)
//{
// var transferToDriverId = transferToDriver.Id;
// TransferToDriver transferToDriver2 = null!;
return ctx.TransferToDrivers.Update(transferToDriver2).State == EntityState.Modified;
});
// var result = await TransactionAsync(ctx =>
// {
// transferToDriver2 = ctx.TransferToDrivers.FirstOrDefault(x => x.Id == transferToDriverId)!;
// transferToDriver2.CarId = transferToDriver.CarId;
// transferToDriver2.LicencePlate = transferToDriver.LicencePlate;
// transferToDriver2.UserProductMappingId = transferToDriver.UserProductMappingId;
// transferToDriver2.TransferId = transferToDriver.TransferId;
// transferToDriver2.Price = transferToDriver.Price;
return result ? transferToDriver2 : null;
}
// return ctx.TransferToDrivers.Update(transferToDriver2).State == EntityState.Modified;
// });
// return result ? transferToDriver2 : null;
//}
public Task<bool> RemoveTransferToDriverAsync(TransferToDriver transferToDriver) => TransactionAsync(ctx => ctx.RemoveTransferToDriver(transferToDriver.Id));
#endregion TransferToDriver
@ -203,7 +207,7 @@ namespace TIAM.Database.DataLayers.Admins
public string GetProductsJsonByServiceProviderId(Guid serviceProviderId, bool includeUsers = true) => Session(ctx => ctx.GetProductsByCompanyId(serviceProviderId, includeUsers).ToJson());
public Task<bool> AddProductAsync(Product product) => TransactionAsync(ctx => ctx.AddProduct(product));
public Task<bool> UpdateProductAsync(Product product) => TransactionAsync(ctx => ctx.UpdateProduct(product));
public Task<Product?> UpdateProductAsync(Product product) => UpdateSafeAsync(product, (ctx, safeProduct) => ctx.UpdateProduct(safeProduct));
public Task<bool> RemoveProductAsync(Product product) => RemoveProductAsync(product.Id);
public Task<bool> RemoveProductAsync(Guid productId) => TransactionAsync(ctx => ctx.RemoveProduct(productId));

View File

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using TIAM.Core.Enums;
using TIAM.Entities.Transfers;
namespace TIAM.Database.DbSets.Transfers;
@ -13,6 +14,20 @@ 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)
{
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)
{
if (transfer.TransferStatusType == transferStatusType) return true;
transfer.TransferStatusType = transferStatusType;
return ctx.Transfers.Update(transfer).State == EntityState.Modified;
}
private static bool RemoveTransfer(this ITransferDbSet ctx, Transfer transfer)
{
ctx.TransferToDrivers.RemoveRange(ctx.TransferToDrivers.Where(x => x.TransferId == transfer.Id));

View File

@ -18,12 +18,18 @@ public static class TransferToDriverDbSetExtensions
public static bool AddTransferToDriver(this ITransferDbSet ctx, TransferToDriver transferToDriver)
{
var transfer = ctx.GetTransferById(transferToDriver.TransferId)!;
transfer.TransferStatusType = TransferStatusType.AssignedToDriver;
ctx.UpdateTransferStatus(transferToDriver.TransferId, TransferStatusType.AssignedToDriver);
return ctx.TransferToDrivers.Add(transferToDriver).State == EntityState.Added;
}
public static bool UpdateTransferToDriver(this ITransferDbSet ctx, TransferToDriver transferToDriver)
{
ctx.UpdateTransferStatus(transferToDriver.Transfer, TransferStatusType.AssignedToDriver);
return ctx.TransferToDrivers.Update(transferToDriver).State == EntityState.Modified;
}
private static bool RemoveTransferToDriver(this ITransferDbSet ctx, TransferToDriver transferToDriver)
{
//TODO: TransferStatusType change, ha nincs sofőr a törlés után! - J.

View File

@ -80,56 +80,58 @@
</div>
<TransferGrid @ref="_gridTransfer"
Logger="_logger"
SignalRClient="AdminSignalRClient"
FilterText="@_filterText"
OnDataSourceChanged="DataSourceChanged"
OnGridItemChanging="DataSourceItemChanging"
OnGridItemChanged="DataSourceItemChanged"
OnGridItemDeleting="DataItemDeleting"
OnGridEditModelSaving="DataItemSaving"
CustomizeElement="Grid_CustomizeElement"
CustomizeEditModel="Grid_CustomizeEditModel"
EditMode="GridEditMode.EditForm"
ColumnResizeMode="GridColumnResizeMode.NextColumn"
AllowSelectRowByClick="false"
PageSize="13"
ShowFilterRow="true">
Logger="_logger"
SignalRClient="AdminSignalRClient"
FilterText="@_filterText"
OnDataSourceChanged="DataSourceChanged"
OnGridItemChanging="DataSourceItemChanging"
OnGridItemChanged="DataSourceItemChanged"
OnGridItemDeleting="DataItemDeleting"
OnGridEditModelSaving="DataItemSaving"
CustomizeElement="Grid_CustomizeElement"
CustomizeEditModel="Grid_CustomizeEditModel"
EditMode="GridEditMode.EditForm"
ColumnResizeMode="GridColumnResizeMode.NextColumn"
AllowSelectRowByClick="false"
PageSize="13"
ShowFilterRow="true">
<Columns>
<DxGridCommandColumn NewButtonVisible="false" DeleteButtonVisible="AcDomain.IsDeveloperVersion" Width="135" MinWidth="135" FixedPosition="GridColumnFixedPosition.Left" />
<DxGridDataColumn FieldName="Id" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" DisplayFormat="N"/>
<DxGridDataColumn FieldName="OrderId" SortIndex="1" SortOrder="GridColumnSortOrder.Descending">
<DxGridCommandColumn NewButtonVisible="false" DeleteButtonVisible="AcDomain.IsDeveloperVersion" Width="80" MinWidth="80" FixedPosition="GridColumnFixedPosition.Left" />
<DxGridDataColumn FieldName="Id" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" DisplayFormat="N" />
<DxGridDataColumn FieldName="OrderId" Caption="Order" SortIndex="1" SortOrder="GridColumnSortOrder.Descending" Width="70">
<CellDisplayTemplate>
@{
var idKeyField = ((Transfer)context.DataItem).Id;
var editUri = $"mytransfers/{idKeyField:N}";
<NavLink href="@editUri">
<text>@context.Value</text>
</NavLink>
var idKeyField = ((Transfer)context.DataItem).Id.ToString("N");
var editUri = $"mytransfers/{idKeyField}";
<NavLink href="@editUri">
<text>@context.Value</text>
</NavLink>
}
</CellDisplayTemplate>
</DxGridDataColumn>
<DxGridDataColumn FieldName="FromAddress"/>
<DxGridDataColumn FieldName="ToAddress"/>
<DxGridDataColumn FieldName="Appointment" DisplayFormat="g" Width="140" />
<DxGridDataColumn FieldName="FullName"/>
<DxGridDataColumn FieldName="ContactPhone"/>
<DxGridDataColumn FieldName="ContactEmail">
<DxGridDataColumn FieldName="FromAddress" />
<DxGridDataColumn FieldName="ToAddress" />
<DxGridDataColumn FieldName="Appointment" DisplayFormat="g" Width="125" />
<DxGridDataColumn FieldName="PassengerCount" Caption="Passengers" Width="90" TextAlignment="GridTextAlignment.Center" CaptionAlignment="GridTextAlignment.Center" />
<DxGridDataColumn FieldName="LuggageCount" Caption="Luggages" Width="80" TextAlignment="GridTextAlignment.Center" CaptionAlignment="GridTextAlignment.Center" />
<DxGridDataColumn FieldName="FlightNumber" Caption="FlightNum" Width="95" TextAlignment="GridTextAlignment.Center" CaptionAlignment="GridTextAlignment.Center" />
<DxGridDataColumn FieldName="Price" Caption="Price" Width="70" CaptionAlignment="GridTextAlignment.Center" />
<DxGridDataColumn FieldName="FullName" />
<DxGridDataColumn FieldName="ContactPhone" Width="120" />
<DxGridDataColumn FieldName="ContactEmail" Width="120">
<CellDisplayTemplate>
@{
var keyField = context.Value;
var keyItem = (Transfer)context.DataItem;
string buttonText = "Contact";
<DxButton Click="() => SendMail(keyItem)" Text="@buttonText" RenderStyle="ButtonRenderStyle.Primary"/>
<DxButton Click="() => SendMail(keyItem)" Text="@buttonText" RenderStyle="ButtonRenderStyle.Primary" />
}
</CellDisplayTemplate>
</DxGridDataColumn>
<DxGridDataColumn FieldName="PassengerCount"/>
<DxGridDataColumn FieldName="PaymentId" DisplayFormat="N" />
<DxGridDataColumn Caption="Paid" FieldName="Paid" />
<DxGridDataColumn FieldName="TransferStatusType" SortIndex="0" SortOrder="GridColumnSortOrder.Ascending" SortMode="GridColumnSortMode.Value">
<DxGridDataColumn FieldName="PaymentId" DisplayFormat="N" Visible="false" />
<DxGridDataColumn Caption="Paid" FieldName="Paid" Width="75" TextAlignment="GridTextAlignment.Center" CaptionAlignment="GridTextAlignment.Center" />
<DxGridDataColumn FieldName="TransferStatusType" Caption="Status" SortIndex="0" Width="120" SortOrder="GridColumnSortOrder.Ascending" SortMode="GridColumnSortMode.Value">
<CellDisplayTemplate>
@{
@ -139,12 +141,14 @@
}
</CellDisplayTemplate>
</DxGridDataColumn>
<DxGridDataColumn FieldName="Created" DisplayFormat="g" Width="140" CaptionAlignment="GridTextAlignment.Center" TextAlignment="GridTextAlignment.Center" />
<DxGridDataColumn FieldName="ReferralId" DisplayFormat="N" Visible="false" />
<DxGridDataColumn FieldName="Comment" Caption="Comment" />
<DxGridDataColumn FieldName="Created" DisplayFormat="g" Width="125" CaptionAlignment="GridTextAlignment.Center" TextAlignment="GridTextAlignment.Center" />
</Columns>
<DetailRowTemplate>
<DxTabs>
<DxTabPage Text="Messages">
<MessageDetailGridComponent ContextId="((Transfer)context.DataItem).Id" />
<DxTabPage Text="Messages">
<MessageDetailGridComponent ContextId="((Transfer)context.DataItem).Id" />
</DxTabPage>
<DxTabPage Text="Driver">
<TransferToDriverGridComponent ContextId="((Transfer)context.DataItem).Id" ParentData="(Transfer)context.DataItem" />
@ -236,31 +240,31 @@
private bool _popupVisible;
private TransferGrid _gridTransfer;
private DxTagBox<TransferStatusModel, TransferStatusModel> _filterTag;
public List<string> IgnoreList =
[
"ReceiverEmailAddress",
"ReceiverFullName",
"ReceiverId",
"SenderEmailAddress",
"SenderFullName",
"SenderId",
"ContextId",
"ReceiverFullName",
"ReceiverId",
"SenderEmailAddress",
"SenderFullName",
"SenderId",
"ContextId",
];
private static 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();
@ -396,7 +400,7 @@
_filterText = filterText;
_gridTransfer.SetFieldFilterCriteria("TransferStatusType", filterCriteria);
}
private void DataSourceChanged(IList<Transfer> transfers)
{
_logger.Info("DataSourceChanged called");
@ -408,7 +412,7 @@
// if(!SelectedCategories.Any())
// SelectedCategories = [Statuses.FirstOrDefault(x => x.StatusValue == (byte)TransferStatusType.Finished)!];
// var filterTransferStatusType = Statuses.FirstOrDefault(x => x.StatusValue == (byte)TransferStatusType.Finished)!;
// if (SelectedCategories.All(x => x.StatusValue != filterTransferStatusType.StatusValue))
@ -462,23 +466,23 @@
}
_dataStorage = new DxSchedulerDataStorage
{
AppointmentMappings = new DxSchedulerAppointmentMappings()
{
Type = "AppointmentType",
Start = "StartDate",
End = "EndDate",
Subject = "Caption",
AllDay = "AllDay",
Location = "Location",
Description = "Description",
LabelId = "Label",
StatusId = "Status",
RecurrenceInfo = "Recurrence"
},
AppointmentMappings = new DxSchedulerAppointmentMappings()
{
Type = "AppointmentType",
Start = "StartDate",
End = "EndDate",
Subject = "Caption",
AllDay = "AllDay",
Location = "Location",
Description = "Description",
LabelId = "Label",
StatusId = "Status",
RecurrenceInfo = "Recurrence"
},
AppointmentsSource = AppointmentModels
};
AppointmentsSource = AppointmentModels
};
}
public AppointmentModel CreateAppointmentModel(Transfer transfer)

View File

@ -304,6 +304,7 @@ namespace TIAMWebApp.Server.Controllers
//[AllowAnonymous]
//[HttpGet]
//[Route(APIUrls.GetAllCarsRouteName)]
[NonAction]
[SignalR(SignalRTags.GetAllCarsByProductId)]
public async Task<List<Car>> GetAllCarsByProductId(Guid productId)
{
@ -394,18 +395,22 @@ namespace TIAMWebApp.Server.Controllers
//[HttpPost]
//[Route(APIUrls.AddProductRouteName)]
//[Tags("In-Progress", "Product")]
[NonAction]
[SignalR(SignalRTags.UpdateProduct)]
public async Task<Product> UpdateProduct([FromBody] Product product)
public async Task<Product?> UpdateProduct([FromBody] Product product)
{
_logger.Info(@"UpdateProduct called");
var result = await adminDal.UpdateProductAsync(product);
return product;
return await adminDal.UpdateProductAsync(product);
;
//var result = await adminDal.UpdateProductAsync(product);
//return product;
}
//[HttpPost]
//[Route(APIUrls.AddProductRouteName)]
//[Tags("In-Progress", "Product")]
[NonAction]
[SignalR(SignalRTags.RemoveProduct)]
public async Task<Product> RemoveProduct([FromBody] Product product)
{