TransferDestination, Address fixes

This commit is contained in:
jozsef.b@aycode.com 2024-02-05 19:03:00 +01:00
parent 553759039f
commit a49c5229b8
8 changed files with 144 additions and 77 deletions

View File

@ -6,9 +6,11 @@ using TIAM.Core.Enums;
using TIAM.Database.DataLayers.Admins; using TIAM.Database.DataLayers.Admins;
using TIAM.Database.DbContexts.Admins; using TIAM.Database.DbContexts.Admins;
using TIAM.Database.DbSets.Emails; using TIAM.Database.DbSets.Emails;
using TIAM.Entities.Addresses;
using TIAM.Entities.Drivers; using TIAM.Entities.Drivers;
using TIAM.Entities.Emails; using TIAM.Entities.Emails;
using TIAM.Entities.Products; using TIAM.Entities.Products;
using TIAM.Entities.TransferDestinations;
using TIAM.Entities.Users; using TIAM.Entities.Users;
using TIAM.Models.Dtos.Users; using TIAM.Models.Dtos.Users;
using TIAM.Entities.Transfers; using TIAM.Entities.Transfers;
@ -324,6 +326,7 @@ namespace TIAM.Database.Test
//Assert.IsNotNull(user.UserProductMappings[0].Product, "Product is null"); //Assert.IsNotNull(user.UserProductMappings[0].Product, "Product is null");
} }
[DataTestMethod] [DataTestMethod]
[DataRow(["8f38f8e3-a92c-4979-88b1-dc812a82245f", "814b5495-c2e9-4f1d-a73f-37cd5d353078", "71392CFD-FB9C-45C1-9540-7BE3782CF26A"])] [DataRow(["8f38f8e3-a92c-4979-88b1-dc812a82245f", "814b5495-c2e9-4f1d-a73f-37cd5d353078", "71392CFD-FB9C-45C1-9540-7BE3782CF26A"])]
public async Task TransferCrudTest(string[] transferIdProductIdUserProductIdStrings) public async Task TransferCrudTest(string[] transferIdProductIdUserProductIdStrings)
@ -384,6 +387,65 @@ namespace TIAM.Database.Test
Assert.IsNull(transfer); //a korábbi törlés miatt NULL kell legyen - J. Assert.IsNull(transfer); //a korábbi törlés miatt NULL kell legyen - J.
} }
[DataTestMethod]
[DataRow(["069089cd-66d4-4f0d-851b-2eea14fa62a4", "be709d9b-87dc-4c94-bf9e-d6254db3fa3e"])]
public async Task TransferDestinationCrudTest(string[] transferDestIdaddressIdStrings)
{
var transferDestId = Guid.Parse(transferDestIdaddressIdStrings[0]);
var addressId = Guid.Parse(transferDestIdaddressIdStrings[1]);
var name = "Liszt Ferenc repülőtér";
var address = "Budapest, Liszt Ferenc tér";
var modifiedAddress = "modified; " + address;
await Dal.RemoveTransferDestinationAsync(transferDestId, true); //kitöröljük a szemetet, ha korábbról bentmaradt - J.
var transferDest = new TransferDestination
{
Id = transferDestId,
AddressId = addressId,
Name = name,
Description = name + "description",
Price = 15000,
PriceType = PriceType.Fix,
Address = new Address
{
Id = addressId,
AddressText = address,
IsValid = false,
IsHelper = false,
Latitude = new Random().NextDouble() + 42d,
Longitude = new Random().NextDouble() + 19d
}
};
Assert.IsTrue(await Dal.AddTransferDestinationAsync(transferDest));
Assert.IsNotNull(transferDest);
transferDest = Dal.GetTransferDestinationById(transferDestId);
Assert.IsNotNull(transferDest);
Assert.IsNotNull(transferDest.Address);
transferDest.Price = 20000;
transferDest.Address.AddressText = modifiedAddress;
Assert.IsTrue(await Dal.UpdateTransferDestinationAsync(transferDest));
transferDest = Dal.GetTransferDestinationById(transferDestId);
Assert.IsNotNull(transferDest);
Assert.IsNotNull(transferDest.Address);
Assert.IsTrue(transferDest.Price == 20000);
Assert.IsTrue(transferDest.Address.AddressText == modifiedAddress);
Assert.IsTrue(transferDest.Id == transferDestId, "transferDest.Id != transferDestId");
Assert.IsTrue(await Dal.RemoveTransferDestinationAsync(transferDestId, true)); //mielőbb kitöröljük, h ne maradjon szemét a db-ben - J.
transferDest = Dal.GetTransferDestinationById(transferDestId);
Assert.IsNull(transferDest); //a korábbi törlés miatt NULL kell legyen - J.
}
#endregion Transfer #endregion Transfer
#region EmailMessage #region EmailMessage

View File

@ -1,8 +1,6 @@
using System.Security.Cryptography.X509Certificates; using AyCode.Database.DbSets.Users;
using AyCode.Database.DbSets.Users;
using AyCode.Models.Enums; using AyCode.Models.Enums;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using TIAM.Core; using TIAM.Core;
//using TIAM.Database.DataLayers.ServiceProviders; //using TIAM.Database.DataLayers.ServiceProviders;
using TIAM.Database.DbContexts.Admins; using TIAM.Database.DbContexts.Admins;
@ -37,17 +35,17 @@ namespace TIAM.Database.DataLayers.Admins
public Transfer? GetTransferById(Guid transferId, bool autoInclude = false) => Session(ctx => ctx.GetTransferById(transferId, autoInclude)); public Transfer? GetTransferById(Guid transferId, bool autoInclude = false) => Session(ctx => ctx.GetTransferById(transferId, autoInclude));
public string? GetTransferJsonById(Guid transferId, bool autoInclude = false) => Session(ctx => ctx.GetTransferById(transferId, autoInclude)?.ToJson()); public string? GetTransferJsonById(Guid transferId, bool autoInclude = false) => Session(ctx => ctx.GetTransferById(transferId, autoInclude)?.ToJson());
public Task<bool> AddTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.AddTransfer(transfer) && ctx.SaveChanges() > 0); public Task<bool> AddTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.AddTransfer(transfer));
public Task<bool> UpdateTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.UpdateTransfer(transfer) && ctx.SaveChanges() > 0); public Task<bool> UpdateTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.UpdateTransfer(transfer));
public Task<bool> RemoveTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.RemoveTransfer(transfer) && ctx.SaveChanges() > 0); public Task<bool> RemoveTransferAsync(Transfer transfer) => TransactionAsync(ctx => ctx.RemoveTransfer(transfer));
public Task<bool> RemoveTransferAsync(Guid transferId) => TransactionAsync(ctx => ctx.RemoveTransfer(transferId) && ctx.SaveChanges() > 0); public Task<bool> RemoveTransferAsync(Guid transferId) => TransactionAsync(ctx => ctx.RemoveTransfer(transferId));
#endregion Transfer #endregion Transfer
#region TransferDestination #region TransferDestination
public Task<bool> AddTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.AddTransferDestination(transferDestination) && ctx.SaveChanges() > 0); public Task<bool> AddTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.AddTransferDestination(transferDestination));
public Task<bool> UpdateTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.UpdateTransferDestination(transferDestination) && ctx.SaveChanges() > 0); public Task<bool> UpdateTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.UpdateTransferDestination(transferDestination));
public Task<bool> RemoveTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.RemoveTransferDestination(transferDestination) && ctx.SaveChanges() > 0); public Task<bool> RemoveTransferDestinationAsync(TransferDestination transferDestination, bool removeAddress = false) => TransactionAsync(ctx => ctx.RemoveTransferDestination(transferDestination, removeAddress));
public Task<bool> RemoveTransferDestinationAsync(Guid transferDestinationId) => TransactionAsync(ctx => ctx.RemoveTransferDestination(transferDestinationId) && ctx.SaveChanges() > 0); public Task<bool> RemoveTransferDestinationAsync(Guid transferDestinationId, bool removeAddress = false) => TransactionAsync(ctx => ctx.RemoveTransferDestination(transferDestinationId, removeAddress));
#endregion TransferDestination #endregion TransferDestination
@ -66,10 +64,10 @@ namespace TIAM.Database.DataLayers.Admins
public string GetProductsJson(bool includeUsers = true) => Session(ctx => ctx.ProductsWithUserRelations(includeUsers).ToJson()); public string GetProductsJson(bool includeUsers = true) => Session(ctx => ctx.ProductsWithUserRelations(includeUsers).ToJson());
public List<Product> GetProductsByServiceProviderId(Guid serviceProviderId, bool includeUsers = true) => Session(ctx => ctx.GetProductsByServiceProviderId(serviceProviderId, includeUsers).ToList()); public List<Product> GetProductsByServiceProviderId(Guid serviceProviderId, bool includeUsers = true) => Session(ctx => ctx.GetProductsByServiceProviderId(serviceProviderId, includeUsers).ToList());
public string GetProductsJsonByServiceProviderId(Guid serviceProviderId, bool includeUsers = true) => Session(ctx => ctx.GetProductsByServiceProviderId(serviceProviderId, includeUsers).ToJson()); public string GetProductsJsonByServiceProviderId(Guid serviceProviderId, bool includeUsers = true) => Session(ctx => ctx.GetProductsByServiceProviderId(serviceProviderId, includeUsers).ToJson());
public Task<bool> AddProduct(Product product) => TransactionAsync(ctx => ctx.AddProduct(product) && ctx.SaveChanges() > 0); public Task<bool> AddProduct(Product product) => TransactionAsync(ctx => ctx.AddProduct(product));
public Task<bool> UpdateProduct(Product product) => TransactionAsync(ctx => ctx.UpdateProduct(product) && ctx.SaveChanges() > 0); public Task<bool> UpdateProduct(Product product) => TransactionAsync(ctx => ctx.UpdateProduct(product));
public Task<bool> RemoveProduct(Product product) => TransactionAsync(ctx => ctx.RemoveProduct(product) && ctx.SaveChanges() > 0); public Task<bool> RemoveProduct(Product product) => TransactionAsync(ctx => ctx.RemoveProduct(product));
public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude)); public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude));
public Task<UserProductMapping?> GetUserProductMappingByIdAsync(Guid userProductMappingId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude)); public Task<UserProductMapping?> GetUserProductMappingByIdAsync(Guid userProductMappingId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude));
@ -88,7 +86,7 @@ namespace TIAM.Database.DataLayers.Admins
#region UserProductMapping #region UserProductMapping
public Task<bool> AddUserProductMappingAsync(UserProductMapping userProductMapping) public Task<bool> AddUserProductMappingAsync(UserProductMapping userProductMapping)
=> TransactionAsync(ctx => ctx.AddUserProductMapping(userProductMapping) && ctx.SaveChanges() > 0); => TransactionAsync(ctx => ctx.AddUserProductMapping(userProductMapping));
public async Task<UserProductMapping?> AddUserProductMappingAsync(Guid userProductMappingId, Guid userId, Guid productId, int permissions = 1, UserProductJsonDetailModel? userProductToCars = null) public async Task<UserProductMapping?> AddUserProductMappingAsync(Guid userProductMappingId, Guid userId, Guid productId, int permissions = 1, UserProductJsonDetailModel? userProductToCars = null)
{ {
@ -105,7 +103,7 @@ namespace TIAM.Database.DataLayers.Admins
} }
public Task<bool> UpdateUserProductMappingAsync(UserProductMapping userProductMapping) public Task<bool> UpdateUserProductMappingAsync(UserProductMapping userProductMapping)
=> TransactionAsync(ctx => ctx.UpdateUserProductMapping(userProductMapping) && ctx.SaveChanges() > 0); => 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)
{ {
@ -122,10 +120,10 @@ namespace TIAM.Database.DataLayers.Admins
} }
public Task<bool> RemoveUserProductMappingAsync(Guid userProductMappingId) public Task<bool> RemoveUserProductMappingAsync(Guid userProductMappingId)
=> TransactionAsync(ctx => ctx.RemoveUserProductMapping(userProductMappingId) && ctx.SaveChanges() > 0); => TransactionAsync(ctx => ctx.RemoveUserProductMapping(userProductMappingId));
public Task<bool> RemoveUserProductMappingAsync(Guid userId, Guid productId) public Task<bool> RemoveUserProductMappingAsync(Guid userId, Guid productId)
=> TransactionAsync(ctx => ctx.RemoveUserProductMapping(userId, productId) && ctx.SaveChanges() > 0); => TransactionAsync(ctx => ctx.RemoveUserProductMapping(userId, productId));
#endregion UserProductMapping #endregion UserProductMapping
@ -139,13 +137,13 @@ namespace TIAM.Database.DataLayers.Admins
public Task<bool> AddEmailMessageAsync(EmailMessage emailMessage) public Task<bool> AddEmailMessageAsync(EmailMessage emailMessage)
=> TransactionAsync(ctx => ctx.AddEmailMessage(emailMessage) && ctx.SaveChanges() > 0); => TransactionAsync(ctx => ctx.AddEmailMessage(emailMessage));
public Task<bool> UpdateEmailMessageAsync(EmailMessage emailMessage) public Task<bool> UpdateEmailMessageAsync(EmailMessage emailMessage)
=> TransactionAsync(ctx => ctx.UpdateEmailMessage(emailMessage) && ctx.SaveChanges() > 0); => TransactionAsync(ctx => ctx.UpdateEmailMessage(emailMessage));
public Task<bool> RemoveEmailMessageAsync(Guid emailMessageId) public Task<bool> RemoveEmailMessageAsync(Guid emailMessageId)
=> TransactionAsync(ctx => ctx.RemoveEmailMessage(emailMessageId) && ctx.SaveChanges() > 0); => TransactionAsync(ctx => ctx.RemoveEmailMessage(emailMessageId));
#endregion EmailMessage #endregion EmailMessage
@ -327,26 +325,26 @@ namespace TIAM.Database.DataLayers.Admins
{ {
List<AssignedPermissionModel> result = new List<AssignedPermissionModel>(); List<AssignedPermissionModel> result = new List<AssignedPermissionModel>();
var UserProductMappings = Context.UserProductMappings.Where(x => x.ProductId == contextId).ToListAsync(); var userProductMappings = Context.UserProductMappings.Where(x => x.ProductId == contextId).ToList();
if (UserProductMappings.Result != null) //if (userProductMappings.Result != null)
{ {
foreach (var item in UserProductMappings.Result) foreach (var item in userProductMappings)
{ {
var mappingRow = Context.PermissionContextMappings.Where(x => x.SubjectId == item.Id).ToListAsync(); var mappingRows = Context.PermissionContextMappings.Where(x => x.SubjectId == item.Id).ToList();
if (mappingRow.Result == null) if (mappingRows.Count == 0)
{ {
//user has no permission but is assigned... must be banned //user has no permission but is assigned... must be banned
} }
else if (mappingRow.Result.Count > 1) else if (mappingRows.Count > 1)
{ {
//user has been assigned more than onece to same context //user has been assigned more than onece to same context
} }
else else
{ {
foreach (var mapping in mappingRow.Result) foreach (var mapping in mappingRows)
{ {
result.Add(new AssignedPermissionModel(item.ProductId, item.Id, mapping.SubjectType, item.UserId.ToString(), mapping.Permissions)); result.Add(new AssignedPermissionModel(item.ProductId, item.Id, mapping.SubjectType, item.UserId.ToString(), mapping.Permissions));
} }
@ -355,26 +353,26 @@ namespace TIAM.Database.DataLayers.Admins
} }
} }
var AssingedGroups = Context.PermissionGroups.Where(x => x.OwnerId == contextId).ToListAsync(); var assingedGroups = Context.PermissionGroups.Where(x => x.OwnerId == contextId).ToList();
if (AssingedGroups.Result != null) //if (assingedGroups.Result != null)
{ {
foreach (var group in AssingedGroups.Result) foreach (var group in assingedGroups)
{ {
var mappingRow = Context.PermissionContextMappings.Where(x => x.SubjectId == group.Id).ToListAsync(); var mappingRows = Context.PermissionContextMappings.Where(x => x.SubjectId == group.Id).ToList();
if (mappingRow.Result == null) if (mappingRows.Count == 0)
{ {
//group has no permission but is assigned... //group has no permission but is assigned...
} }
else if (mappingRow.Result.Count > 1) else if (mappingRows.Count > 1)
{ {
//group has been assigned more than onece to same context //group has been assigned more than onece to same context
} }
else else
{ {
foreach (var mapping in mappingRow.Result) foreach (var mapping in mappingRows)
{ {
result.Add(new AssignedPermissionModel(group.OwnerId, group.Id, mapping.SubjectType, group.GroupName, mapping.Permissions)); result.Add(new AssignedPermissionModel(group.OwnerId, group.Id, mapping.SubjectType, group.GroupName, mapping.Permissions));
} }

View File

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using TIAM.Entities.Addresses;
using TIAM.Entities.Products; using TIAM.Entities.Products;
using TIAM.Entities.TransferDestinations; using TIAM.Entities.TransferDestinations;
@ -7,4 +8,5 @@ namespace TIAM.Database.DbSets.Transfers;
public interface ITransferDestinationDbSet public interface ITransferDestinationDbSet
{ {
public DbSet<TransferDestination> TransferDestinations { get; set; } public DbSet<TransferDestination> TransferDestinations { get; set; }
public DbSet<Address> Addresses { get; set; }
} }

View File

@ -1,7 +1,4 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using TIAM.Database.DbSets.Products;
using TIAM.Database.DbSets.Users;
using TIAM.Entities.Products;
using TIAM.Entities.TransferDestinations; using TIAM.Entities.TransferDestinations;
using TIAM.Entities.Transfers; using TIAM.Entities.Transfers;
@ -47,13 +44,17 @@ public static class TransferDbSetExtensions
public static bool UpdateTransferDestination(this ITransferDestinationDbSet ctx, TransferDestination transferDestination) public static bool UpdateTransferDestination(this ITransferDestinationDbSet ctx, TransferDestination transferDestination)
=> ctx.TransferDestinations.Update(transferDestination).State == EntityState.Modified; => ctx.TransferDestinations.Update(transferDestination).State == EntityState.Modified;
public static bool RemoveTransferDestination(this ITransferDestinationDbSet ctx, TransferDestination transferDestination) public static bool RemoveTransferDestination(this ITransferDestinationDbSet ctx, TransferDestination transferDestination, bool removeAddress)
=> ctx.TransferDestinations.Remove(transferDestination).State == EntityState.Deleted;
public static bool RemoveTransferDestination(this ITransferDestinationDbSet ctx, Guid transferDestinationId)
{ {
var transfer = ctx.GetTransferDestinationById(transferDestinationId); if (removeAddress) ctx.Addresses.Remove(transferDestination.Address);
return transfer == null || ctx.RemoveTransferDestination(transferDestinationId);
return ctx.TransferDestinations.Remove(transferDestination).State == EntityState.Deleted;
}
public static bool RemoveTransferDestination(this ITransferDestinationDbSet ctx, Guid transferDestinationId, bool removeAddress)
{
var transferDestination = ctx.GetTransferDestinationById(transferDestinationId);
return transferDestination == null || ctx.RemoveTransferDestination(transferDestination, removeAddress);
} }
#endregion TransferDestination #endregion TransferDestination

View File

@ -27,7 +27,7 @@ namespace TIAM.Entities.TransferDestinations
public PriceType PriceType { get; set; } public PriceType PriceType { get; set; }
//TEMPORARY!!! //TEMPORARY!!!
public string AddressString { get; set; } public string? AddressString { get; set; }
public DateTime Created { get; set; } public DateTime Created { get; set; }
public DateTime Modified { get; set; } public DateTime Modified { get; set; }

View File

@ -105,7 +105,7 @@ namespace TIAMSharedUI.Pages.User.SysAdmins
//add new orderData to orderData array //add new orderData to orderData array
//await NwindDataService.InsertEmployeeAsync((EditableEmployee)e.EditModel); //await NwindDataService.InsertEmployeeAsync((EditableEmployee)e.EditModel);
await transferDataService.CreateTransferDestination(TransferDestinationWizardModel.SaveToTransferDestination(myModel)); await transferDataService.CreateTransferDestination(TransferDestinationWizardModel.CopyToTransferDestination(myModel));
//await transferDataService.CreateTransferDestination(new TransferDestination //await transferDataService.CreateTransferDestination(new TransferDestination
/*{ /*{
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
@ -142,7 +142,7 @@ namespace TIAMSharedUI.Pages.User.SysAdmins
transferToModify.Price = myModel.Price; transferToModify.Price = myModel.Price;
transferToModify.PriceType = myModel.PriceType; transferToModify.PriceType = myModel.PriceType;
await transferDataService.UpdateTransferDestination(TransferDestinationWizardModel.SaveToTransferDestination(transferToModify)); await transferDataService.UpdateTransferDestination(TransferDestinationWizardModel.CopyToTransferDestination(transferToModify));
} }
} }
@ -177,7 +177,7 @@ namespace TIAMSharedUI.Pages.User.SysAdmins
{ {
//add new transferwizardmodel to transferData array //add new transferwizardmodel to transferData array
TransferDataFromDb = ((TransferDestinationWizardModel[])TransferDataFromDb).Append( TransferDataFromDb = ((TransferDestinationWizardModel[])TransferDataFromDb).Append(
new TransferDestinationWizardModel(item.Id, item.Name, item.Description, item.AddressString, item.Price, item.PriceType)).ToArray(); new TransferDestinationWizardModel(item.Id, item.Name, item.Description, item.AddressString, item.Price, item.PriceType, item.Address)).ToArray();
logToBrowserConsole.LogToBC($"TransferDataFromDb: {item.Name}"); logToBrowserConsole.LogToBC($"TransferDataFromDb: {item.Name}");
} }

View File

@ -74,16 +74,16 @@ namespace TIAMWebApp.Server.Controllers
[AllowAnonymous] [AllowAnonymous]
[HttpPost] [HttpPost]
[Route(APIUrls.CreateTransferDestinationRouteName)] [Route(APIUrls.CreateTransferDestinationRouteName)]
public async Task<IActionResult> CreateTransferDestination([FromBody] JsonElement SerializedTransferDestinationModel) public async Task<IActionResult> CreateTransferDestination([FromBody] JsonElement serializedTransferDestinationModel)
{ {
Console.WriteLine("CreateTransferDestination called!"); Console.WriteLine("CreateTransferDestination called!");
if (string.IsNullOrEmpty(SerializedTransferDestinationModel.GetRawText())) if (string.IsNullOrEmpty(serializedTransferDestinationModel.GetRawText()))
{ {
return BadRequest("SerializedTramsferDestinationWizardModel is required"); return BadRequest("SerializedTramsferDestinationWizardModel is required");
} }
else else
{ {
TransferDestination? transferDestination = JObject.Parse(SerializedTransferDestinationModel.GetRawText()).ToObject<TransferDestination>(); TransferDestination? transferDestination = JObject.Parse(serializedTransferDestinationModel.GetRawText()).ToObject<TransferDestination>();
if (transferDestination != null) if (transferDestination != null)
{ {
@ -125,10 +125,10 @@ namespace TIAMWebApp.Server.Controllers
[AllowAnonymous] [AllowAnonymous]
[HttpPost] [HttpPost]
[Route(APIUrls.UpdateTransferDestinationRouteName)] [Route(APIUrls.UpdateTransferDestinationRouteName)]
public async Task<IActionResult> UpdateTransferDestination([FromBody]JsonElement SerializedTransferDestinationModel) public async Task<IActionResult> UpdateTransferDestination([FromBody]JsonElement serializedTransferDestination)
{ {
Console.WriteLine("UpdateTransferDestination called!"); Console.WriteLine("UpdateTransferDestination called!");
if (string.IsNullOrEmpty(SerializedTransferDestinationModel.GetRawText())) if (string.IsNullOrEmpty(serializedTransferDestination.GetRawText()))
{ {
Console.WriteLine("Bad request!"); Console.WriteLine("Bad request!");
return BadRequest("SerializedTramsferDestinationWizardModel is required"); return BadRequest("SerializedTramsferDestinationWizardModel is required");
@ -136,8 +136,8 @@ namespace TIAMWebApp.Server.Controllers
else else
{ {
Console.WriteLine("Serialized model not empty!"); Console.WriteLine("Serialized model not empty!");
TransferDestination? transferDestination = JObject.Parse(SerializedTransferDestinationModel.GetRawText()).ToObject<TransferDestination>(); TransferDestination? transferDestination = JObject.Parse(serializedTransferDestination.GetRawText()).ToObject<TransferDestination>();
Console.WriteLine($"TransferDestination to be updated: {SerializedTransferDestinationModel.GetRawText()}"); Console.WriteLine($"TransferDestination to be updated: {serializedTransferDestination.GetRawText()}");
Console.WriteLine($"TransferDestination to be updated: {transferDestination.AddressString}"); Console.WriteLine($"TransferDestination to be updated: {transferDestination.AddressString}");
@ -162,27 +162,27 @@ namespace TIAMWebApp.Server.Controllers
Console.WriteLine($"TransferDestination to be updated new address: {transferDestination.AddressString}"); Console.WriteLine($"TransferDestination to be updated new address: {transferDestination.AddressString}");
Console.WriteLine($"TransferDestination to be updated new description: {transferDestination.Description}"); Console.WriteLine($"TransferDestination to be updated new description: {transferDestination.Description}");
var dbTransferDestinationJson = _adminDal.GetTransferDestinationJsonById(transferDestination.Id); //var dbTransferDestinationJson = _adminDal.GetTransferDestinationJsonById(transferDestination.Id);
Console.WriteLine($"TransferDestination JSON to be updated: {dbTransferDestinationJson}"); //Console.WriteLine($"TransferDestination JSON to be updated: {dbTransferDestinationJson}");
var dbTransferDestination = JObject.Parse(dbTransferDestinationJson).ToObject<TransferDestination>(); //var dbTransferDestination = JObject.Parse(dbTransferDestinationJson).ToObject<TransferDestination>();
if (dbTransferDestination.Id != Guid.Empty)
{
dbTransferDestination.AddressId = transferDestination.AddressId; //var dbTransferDestination = _adminDal.GetTransferDestinationById(transferDestination.Id, true);
dbTransferDestination.Price = transferDestination.Price; //if (dbTransferDestination.Id != Guid.Empty)
dbTransferDestination.PriceType = transferDestination.PriceType; //{
dbTransferDestination.Name = transferDestination.Name; // dbTransferDestination.AddressId = transferDestination.AddressId;
dbTransferDestination.Description = transferDestination.Description; // dbTransferDestination.Price = transferDestination.Price;
dbTransferDestination.AddressString = transferDestination.AddressString; // dbTransferDestination.PriceType = transferDestination.PriceType;
dbTransferDestination.Address = transferDestination.Address; // dbTransferDestination.Name = transferDestination.Name;
// dbTransferDestination.Description = transferDestination.Description;
} // dbTransferDestination.AddressString = transferDestination.AddressString;
// dbTransferDestination.Address = transferDestination.Address;
//}
//await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination); //await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination);
await _adminDal.UpdateTransferDestinationAsync(dbTransferDestination); await _adminDal.UpdateTransferDestinationAsync(transferDestination);
return Ok(dbTransferDestination); return Ok(transferDestination);
} }
} }
else else

View File

@ -45,6 +45,8 @@ namespace TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
public PriceType PriceType { get; set; } public PriceType PriceType { get; set; }
public Address Address { get; set; }
//[DataType("Latitude")] //[DataType("Latitude")]
//[Display(Name = "Destination latitude")] //[Display(Name = "Destination latitude")]
//public double Latitude { get; set; } //public double Latitude { get; set; }
@ -55,23 +57,24 @@ namespace TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
public TransferDestinationWizardModel() { } public TransferDestinationWizardModel() { }
public TransferDestinationWizardModel(string name, string description, string address, double price, PriceType priceType) :this(Guid.NewGuid(), name, description, address, price, priceType) public TransferDestinationWizardModel(string name, string description, string addressString, double price, PriceType priceType, Address address) :this(Guid.NewGuid(), name, description, addressString, price, priceType, address)
{ } { }
public TransferDestinationWizardModel(Guid id, string name, string description, string address, double price, PriceType priceType) public TransferDestinationWizardModel(Guid id, string name, string description, string addressString, double price, PriceType priceType, Address address)
{ {
Id = id.ToString(); Id = id.ToString();
Name = name; Name = name;
Description = description; Description = description;
AddressString = address; AddressString = addressString;
Price = price; Price = price;
PriceType = priceType; PriceType = priceType;
Address = address;
} }
public static TransferDestination SaveToTransferDestination(TransferDestinationWizardModel model) public static TransferDestination CopyToTransferDestination(TransferDestinationWizardModel model)
=> SaveToTransferDestination(model, new TransferDestination()); => CopyToTransferDestination(model, new TransferDestination());
public static TransferDestination SaveToTransferDestination(TransferDestinationWizardModel model, TransferDestination destination) public static TransferDestination CopyToTransferDestination(TransferDestinationWizardModel model, TransferDestination destination)
{ {
destination.Id = Guid.Parse(model.Id); destination.Id = Guid.Parse(model.Id);
destination.Name = model.Name; destination.Name = model.Name;
@ -79,6 +82,7 @@ namespace TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
destination.AddressString = model.AddressString; destination.AddressString = model.AddressString;
destination.Price = model.Price; destination.Price = model.Price;
destination.PriceType = model.PriceType; destination.PriceType = model.PriceType;
destination.Address = model.Address;
if (destination.Address == null) if (destination.Address == null)
{ {