improvements, fixes, etc...
This commit is contained in:
parent
90156b7239
commit
13d7b0930a
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -62,42 +62,43 @@ 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;
|
||||
|
||||
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())
|
||||
public Task<Transfer?> UpdateTransferAsync(Transfer transfer) => UpdateSafeAsync(transfer, (ctx, safeTransfer) => ctx.UpdateTransfer(safeTransfer));
|
||||
//public async Task<Transfer?> UpdateTransferAsync(Transfer transfer)
|
||||
//{
|
||||
// if (entityEntry.Entity is not Transfer)
|
||||
// entityEntry.State = EntityState.Unchanged;
|
||||
// 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)
|
||||
// // 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, List<TransferToDriver> transferToDrivers)
|
||||
=> TransactionAsync(ctx =>
|
||||
|
|
@ -129,25 +130,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
|
||||
|
|
@ -202,7 +206,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));
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -88,7 +88,6 @@
|
|||
OnGridItemChanged="DataSourceItemChanged"
|
||||
OnGridItemDeleting="DataItemDeleting"
|
||||
OnGridEditModelSaving="DataItemSaving"
|
||||
|
||||
CustomizeElement="Grid_CustomizeElement"
|
||||
CustomizeEditModel="Grid_CustomizeEditModel"
|
||||
EditMode="GridEditMode.EditForm"
|
||||
|
|
@ -98,38 +97,41 @@
|
|||
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}";
|
||||
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,7 +141,9 @@
|
|||
}
|
||||
</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>
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue