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.Price = 30000;
product.UserProductMappings[0].Permissions = 2; product.UserProductMappings[0].Permissions = 2;
Assert.IsTrue(await Dal.UpdateProductAsync(product)); Assert.IsNotNull(await Dal.UpdateProductAsync(product));
product = await Dal.GetProductByIdAsync(productId); product = await Dal.GetProductByIdAsync(productId);

View File

@ -63,42 +63,43 @@ namespace TIAM.Database.DataLayers.Admins
public Task<bool> AddTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.AddTransfer(transfer)); public Task<bool> AddTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.AddTransfer(transfer));
public async Task<Transfer?> UpdateTransferAsync(Transfer transfer) 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;
ctx.Entry(entity).State = EntityState.Detached;
ctx.Entry(entity).CurrentValues.SetValues(transfer);
return ctx.UpdateTransfer(entity);
//foreach (var entityEntry in ctx.ChangeTracker.Entries())
//{ //{
// if (entityEntry.Entity is not Transfer) // Transfer? entity = null;
// entityEntry.State = EntityState.Unchanged;
// 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);
// return ctx.UpdateTransfer(entity);
// //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 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);
// });
// return result ? entity : null;
//} //}
//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;
//transfer.TransferToDrivers = 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, 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 => => TransactionAsync(ctx =>
@ -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<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<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 => public Task<TransferToDriver?> UpdateTransferToDriverAsync(TransferToDriver transferToDriver)
{ => UpdateSafeAsync(transferToDriver, (ctx, safeTransferToDriver) => ctx.UpdateTransferToDriver(safeTransferToDriver));
transferToDriver2 = ctx.TransferToDrivers.FirstOrDefault(x => x.Id == transferToDriverId)!; //public async Task<TransferToDriver?> UpdateTransferToDriverAsync(TransferToDriver transferToDriver)
transferToDriver2.CarId = transferToDriver.CarId; //{
transferToDriver2.LicencePlate = transferToDriver.LicencePlate; // var transferToDriverId = transferToDriver.Id;
transferToDriver2.UserProductMappingId = transferToDriver.UserProductMappingId; // TransferToDriver transferToDriver2 = null!;
transferToDriver2.TransferId = transferToDriver.TransferId;
transferToDriver2.Price = transferToDriver.Price;
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)); public Task<bool> RemoveTransferToDriverAsync(TransferToDriver transferToDriver) => TransactionAsync(ctx => ctx.RemoveTransferToDriver(transferToDriver.Id));
#endregion TransferToDriver #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 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> 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(Product product) => RemoveProductAsync(product.Id);
public Task<bool> RemoveProductAsync(Guid productId) => TransactionAsync(ctx => ctx.RemoveProduct(productId)); public Task<bool> RemoveProductAsync(Guid productId) => TransactionAsync(ctx => ctx.RemoveProduct(productId));

View File

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using TIAM.Core.Enums;
using TIAM.Entities.Transfers; using TIAM.Entities.Transfers;
namespace TIAM.Database.DbSets.Transfers; namespace TIAM.Database.DbSets.Transfers;
@ -13,6 +14,20 @@ public static class TransferDbSetExtensions
public static bool UpdateTransfer(this ITransferDbSet ctx, Transfer transfer) public static bool UpdateTransfer(this ITransferDbSet ctx, Transfer transfer)
=> ctx.Transfers.Update(transfer).State == EntityState.Modified; => 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) private static bool RemoveTransfer(this ITransferDbSet ctx, Transfer transfer)
{ {
ctx.TransferToDrivers.RemoveRange(ctx.TransferToDrivers.Where(x => x.TransferId == transfer.Id)); 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) public static bool AddTransferToDriver(this ITransferDbSet ctx, TransferToDriver transferToDriver)
{ {
var transfer = ctx.GetTransferById(transferToDriver.TransferId)!; ctx.UpdateTransferStatus(transferToDriver.TransferId, TransferStatusType.AssignedToDriver);
transfer.TransferStatusType = TransferStatusType.AssignedToDriver;
return ctx.TransferToDrivers.Add(transferToDriver).State == EntityState.Added; 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) private static bool RemoveTransferToDriver(this ITransferDbSet ctx, TransferToDriver transferToDriver)
{ {
//TODO: TransferStatusType change, ha nincs sofőr a törlés után! - J. //TODO: TransferStatusType change, ha nincs sofőr a törlés után! - J.

View File

@ -88,7 +88,6 @@
OnGridItemChanged="DataSourceItemChanged" OnGridItemChanged="DataSourceItemChanged"
OnGridItemDeleting="DataItemDeleting" OnGridItemDeleting="DataItemDeleting"
OnGridEditModelSaving="DataItemSaving" OnGridEditModelSaving="DataItemSaving"
CustomizeElement="Grid_CustomizeElement" CustomizeElement="Grid_CustomizeElement"
CustomizeEditModel="Grid_CustomizeEditModel" CustomizeEditModel="Grid_CustomizeEditModel"
EditMode="GridEditMode.EditForm" EditMode="GridEditMode.EditForm"
@ -98,38 +97,41 @@
ShowFilterRow="true"> ShowFilterRow="true">
<Columns> <Columns>
<DxGridCommandColumn NewButtonVisible="false" DeleteButtonVisible="AcDomain.IsDeveloperVersion" Width="135" MinWidth="135" FixedPosition="GridColumnFixedPosition.Left" /> <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="Id" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" DisplayFormat="N" />
<DxGridDataColumn FieldName="OrderId" SortIndex="1" SortOrder="GridColumnSortOrder.Descending"> <DxGridDataColumn FieldName="OrderId" Caption="Order" SortIndex="1" SortOrder="GridColumnSortOrder.Descending" Width="70">
<CellDisplayTemplate> <CellDisplayTemplate>
@{ @{
var idKeyField = ((Transfer)context.DataItem).Id; var idKeyField = ((Transfer)context.DataItem).Id.ToString("N");
var editUri = $"mytransfers/{idKeyField:N}"; var editUri = $"mytransfers/{idKeyField}";
<NavLink href="@editUri"> <NavLink href="@editUri">
<text>@context.Value</text> <text>@context.Value</text>
</NavLink> </NavLink>
} }
</CellDisplayTemplate> </CellDisplayTemplate>
</DxGridDataColumn> </DxGridDataColumn>
<DxGridDataColumn FieldName="FromAddress"/> <DxGridDataColumn FieldName="FromAddress" />
<DxGridDataColumn FieldName="ToAddress"/> <DxGridDataColumn FieldName="ToAddress" />
<DxGridDataColumn FieldName="Appointment" DisplayFormat="g" Width="140" /> <DxGridDataColumn FieldName="Appointment" DisplayFormat="g" Width="125" />
<DxGridDataColumn FieldName="FullName"/> <DxGridDataColumn FieldName="PassengerCount" Caption="Passengers" Width="90" TextAlignment="GridTextAlignment.Center" CaptionAlignment="GridTextAlignment.Center" />
<DxGridDataColumn FieldName="ContactPhone"/> <DxGridDataColumn FieldName="LuggageCount" Caption="Luggages" Width="80" TextAlignment="GridTextAlignment.Center" CaptionAlignment="GridTextAlignment.Center" />
<DxGridDataColumn FieldName="ContactEmail"> <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> <CellDisplayTemplate>
@{ @{
var keyField = context.Value; var keyField = context.Value;
var keyItem = (Transfer)context.DataItem; var keyItem = (Transfer)context.DataItem;
string buttonText = "Contact"; string buttonText = "Contact";
<DxButton Click="() => SendMail(keyItem)" Text="@buttonText" RenderStyle="ButtonRenderStyle.Primary"/> <DxButton Click="() => SendMail(keyItem)" Text="@buttonText" RenderStyle="ButtonRenderStyle.Primary" />
} }
</CellDisplayTemplate> </CellDisplayTemplate>
</DxGridDataColumn> </DxGridDataColumn>
<DxGridDataColumn FieldName="PassengerCount"/> <DxGridDataColumn FieldName="PaymentId" DisplayFormat="N" Visible="false" />
<DxGridDataColumn FieldName="PaymentId" DisplayFormat="N" /> <DxGridDataColumn Caption="Paid" FieldName="Paid" Width="75" TextAlignment="GridTextAlignment.Center" CaptionAlignment="GridTextAlignment.Center" />
<DxGridDataColumn Caption="Paid" FieldName="Paid" /> <DxGridDataColumn FieldName="TransferStatusType" Caption="Status" SortIndex="0" Width="120" SortOrder="GridColumnSortOrder.Ascending" SortMode="GridColumnSortMode.Value">
<DxGridDataColumn FieldName="TransferStatusType" SortIndex="0" SortOrder="GridColumnSortOrder.Ascending" SortMode="GridColumnSortMode.Value">
<CellDisplayTemplate> <CellDisplayTemplate>
@{ @{
@ -139,7 +141,9 @@
} }
</CellDisplayTemplate> </CellDisplayTemplate>
</DxGridDataColumn> </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> </Columns>
<DetailRowTemplate> <DetailRowTemplate>
<DxTabs> <DxTabs>

View File

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