diff --git a/TIAM.Database/DataLayers/TransferDestinations/TransferDestinationDal.cs b/TIAM.Database/DataLayers/TransferDestinations/TransferDestinationDal.cs index 8bd29753..7a69fd1c 100644 --- a/TIAM.Database/DataLayers/TransferDestinations/TransferDestinationDal.cs +++ b/TIAM.Database/DataLayers/TransferDestinations/TransferDestinationDal.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using AyCode.Database; +using AyCode.Utils.Extensions; using Microsoft.EntityFrameworkCore; using Microsoft.Identity.Client; using TIAM.Database.DbContexts.Transfers; @@ -21,7 +22,11 @@ public class TransferDestinationDal : DalBase public Task CreateTransferDestinationAsync(TransferDestination transferDestination) { //transferDestination.Created = DateTime.UtcNow; - //transferDestination.Modified = DateTime.UtcNow; + //transferDestination.Modified = DateTime.UtcNow; + + if (transferDestination.Id.IsNullOrEmpty()) + transferDestination.Id = Guid.NewGuid(); + Context.TransferDestinations.Add(transferDestination); return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0); } diff --git a/TIAM.Entities/TransferDestinations/TransferDestination.cs b/TIAM.Entities/TransferDestinations/TransferDestination.cs index 34e1db41..117b670c 100644 --- a/TIAM.Entities/TransferDestinations/TransferDestination.cs +++ b/TIAM.Entities/TransferDestinations/TransferDestination.cs @@ -20,9 +20,17 @@ namespace TIAM.Entities.TransferDestinations public TransferDestination() { } public TransferDestination(double latitude, double longitude, string address) : this(Guid.NewGuid(), latitude, longitude, address) { } - public TransferDestination(Guid id, double latitude, double longitude, string address) : base(Guid.NewGuid(), latitude, longitude, address) { } - public TransferDestination(Guid id, string name, double latitude, double longitude, string address) : base(id, latitude,longitude, address) { } - public TransferDestination(Guid id, string name, string description, double latitude, double longitude, string address) : base(id, latitude,longitude, address) { } + public TransferDestination(Guid id, double latitude, double longitude, string address) : base(id, latitude, longitude, address) { } + + public TransferDestination(Guid id, string name, double latitude, double longitude, string address) : this(id, latitude, longitude, address) + { + Name = name; + } + + public TransferDestination(Guid id, string name, string description, double latitude, double longitude, string address) : this(id, name, latitude, longitude, address) + { + Description = description; + } } } diff --git a/TIAMMobileApp/Services/TransferDataService.cs b/TIAMMobileApp/Services/TransferDataService.cs index 96821dc0..9478a038 100644 --- a/TIAMMobileApp/Services/TransferDataService.cs +++ b/TIAMMobileApp/Services/TransferDataService.cs @@ -17,11 +17,25 @@ namespace TIAMMobileApp.Services this.http = http; } - public async Task CreateTransferDestination(TransferDestinationWizardModel model) + public async Task CreateTransferDestination(TransferDestinationWizardModel model) { var url = $"{Setting.BaseUrl}/{APIUrls.CreateTransferDestination}"; var response = await http.PostAsJsonAsync(url, model); - return response.IsSuccessStatusCode; + + //var result = new WizardProcessorResult(); + + //if (response.IsSuccessStatusCode) + //{ + // result.IsSucces = true; + // result.ResultJson = await response.Content.ReadAsStringAsync(); + //} + + if (!response.IsSuccessStatusCode) + return null; + + var result = (TransferDestination)(await response.Content.ReadFromJsonAsync(typeof(TransferDestination)))!; + + return result; } /// diff --git a/TIAMMobileApp/Services/WizardProcessor.cs b/TIAMMobileApp/Services/WizardProcessor.cs index 37d34784..dd21811e 100644 --- a/TIAMMobileApp/Services/WizardProcessor.cs +++ b/TIAMMobileApp/Services/WizardProcessor.cs @@ -1,5 +1,6 @@ using TIAM.Entities.TransferDestinations; using TIAMWebApp.Shared.Application.Interfaces; +using TIAMWebApp.Shared.Application.Models; using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels; namespace TIAMMobileApp.Services @@ -16,20 +17,22 @@ namespace TIAMMobileApp.Services this.userDataService = userDataService; } - public async Task ProcessWizardAsync(Type type, object data) + public async Task ProcessWizardAsync(Type type, object data) where TModelType: class { switch (type.Name) { case "TransferDestinationWizardModel": var result = await transferDataService.CreateTransferDestination((TransferDestinationWizardModel)data); - if (result) - return "Success"; - else - return "Failed"; + return result as TModelType; + + //var a = new WizardProcessorResult(); + //a.Model = result; + //return a as TResult; case "ServiceProvider": + return null; default: - return "Not implemented"; + return null; } } diff --git a/TIAMMobileApp/TIAMMobileApp.csproj b/TIAMMobileApp/TIAMMobileApp.csproj index 404e63f0..36a70503 100644 --- a/TIAMMobileApp/TIAMMobileApp.csproj +++ b/TIAMMobileApp/TIAMMobileApp.csproj @@ -29,6 +29,7 @@ 10.0.17763.0 10.0.17763.0 6.5 + enable diff --git a/TIAMSharedUI/Pages/TestPage.razor b/TIAMSharedUI/Pages/TestPage.razor index edd83b8b..6c32feb2 100644 --- a/TIAMSharedUI/Pages/TestPage.razor +++ b/TIAMSharedUI/Pages/TestPage.razor @@ -3,6 +3,7 @@ @using TIAMWebApp.Shared.Application.Interfaces @using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels @using TIAMWebApp.Shared.Application.Utility +@using TIAM.Entities.TransferDestinations @inject LogToBrowserConsole logToBrowserConsole @inject IWizardProcessor WizardProcessor

TestPage

@@ -94,9 +95,8 @@ }; public List TransferDestinationIgnorList = new List { - "Id", - "Created", - "Modified" + "Latitude", + "Longitude" }; @@ -130,7 +130,7 @@ public async Task SubmitForm(object Result) { - //await WizardProcessor.ProcessWizardAsync(Result.GetType(), Result); + var transferDestination = await WizardProcessor.ProcessWizardAsync(Result.GetType(), Result); logToBrowserConsole.LogToBC($"Submitted nested form: {Result.GetType().FullName}"); } } diff --git a/TIAMWebApp/Client/Services/TransferDataService.cs b/TIAMWebApp/Client/Services/TransferDataService.cs index a72ab792..93c059ee 100644 --- a/TIAMWebApp/Client/Services/TransferDataService.cs +++ b/TIAMWebApp/Client/Services/TransferDataService.cs @@ -39,11 +39,25 @@ namespace TIAMWebApp.Client.Services return await http.GetFromJsonAsync(url); } - public async Task CreateTransferDestination(TransferDestinationWizardModel model) + public async Task CreateTransferDestination(TransferDestinationWizardModel model) { var url = $"{Setting.BaseUrl}/{APIUrls.CreateTransferDestination}"; var response = await http.PostAsJsonAsync(url, model); - return response.IsSuccessStatusCode; + + //var result = new WizardProcessorResult(); + + //if (response.IsSuccessStatusCode) + //{ + // result.IsSucces = true; + // result.ResultJson = await response.Content.ReadAsStringAsync(); + //} + + if (!response.IsSuccessStatusCode) + return null; + + var result = (TransferDestination)(await response.Content.ReadFromJsonAsync(typeof(TransferDestination)))!; + + return result; } } } diff --git a/TIAMWebApp/Client/Services/WizardProcessor.cs b/TIAMWebApp/Client/Services/WizardProcessor.cs index 1578db08..743f9ded 100644 --- a/TIAMWebApp/Client/Services/WizardProcessor.cs +++ b/TIAMWebApp/Client/Services/WizardProcessor.cs @@ -16,20 +16,18 @@ namespace TIAMWebApp.Client.Services this.userDataService = userDataService; } - public async Task ProcessWizardAsync(Type type, object data) + public async Task ProcessWizardAsync(Type type, object data) where TModelType: class { switch (type.Name) { case "TransferDestinationWizardModel": var result = await transferDataService.CreateTransferDestination((TransferDestinationWizardModel)data); - if (result) - return "Success"; - else - return "Failed"; - + return result as TModelType; + case "ServiceProvider": + return null; default: - return "Not implemented"; + return null; } } diff --git a/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs b/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs index 6018e375..6e6a4032 100644 --- a/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs +++ b/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs @@ -86,8 +86,8 @@ namespace TIAMWebApp.Server.Controllers if (transferDestinationModel != null) { - var Id = Guid.NewGuid(); - TransferDestination transferDestination = new TransferDestination(Id, transferDestinationModel.Name, transferDestinationModel.Description, transferDestinationModel.Latitude, transferDestinationModel.Longitude, transferDestinationModel.Address); + var id = Guid.NewGuid(); + TransferDestination transferDestination = new TransferDestination(id, transferDestinationModel.Name, transferDestinationModel.Description, transferDestinationModel.Latitude, transferDestinationModel.Longitude, transferDestinationModel.Address); if (string.IsNullOrEmpty(transferDestinationModel.Name) || string.IsNullOrEmpty(transferDestinationModel.Address)) @@ -96,14 +96,14 @@ namespace TIAMWebApp.Server.Controllers } else { - Console.WriteLine($"TransferDestination to be created: {Id}"); + Console.WriteLine($"TransferDestination to be created: {id}"); Console.WriteLine($"TransferDestination to be created: {transferDestination.Latitude}"); Console.WriteLine($"TransferDestination to be created: {transferDestination.Longitude}"); Console.WriteLine($"TransferDestination to be created: {transferDestination.Address}"); //await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination); await _transferDestinationDal.CreateTransferDestinationAsync(transferDestination); - return Ok("yes"); + return Ok(transferDestination); } } diff --git a/TIAMWebApp/Shared/Interfaces/ITransferDataService.cs b/TIAMWebApp/Shared/Interfaces/ITransferDataService.cs index 71c2a96f..8847391e 100644 --- a/TIAMWebApp/Shared/Interfaces/ITransferDataService.cs +++ b/TIAMWebApp/Shared/Interfaces/ITransferDataService.cs @@ -9,6 +9,6 @@ namespace TIAMWebApp.Shared.Application.Interfaces Task GetDestinationsAsync(); Task GetTransferDestinationbyCoordinatesAsync(string destinationId); Task GetTransferDestinationbyAddressAsync(string destinationId); - Task CreateTransferDestination(TransferDestinationWizardModel model); + Task CreateTransferDestination(TransferDestinationWizardModel model); } } diff --git a/TIAMWebApp/Shared/Interfaces/IWizardProcessor.cs b/TIAMWebApp/Shared/Interfaces/IWizardProcessor.cs index 575b1519..1a244e81 100644 --- a/TIAMWebApp/Shared/Interfaces/IWizardProcessor.cs +++ b/TIAMWebApp/Shared/Interfaces/IWizardProcessor.cs @@ -8,7 +8,7 @@ namespace TIAMWebApp.Shared.Application.Interfaces { public interface IWizardProcessor { - public Task ProcessWizardAsync(Type type, object data); + public Task ProcessWizardAsync(Type type, object data) where TModelType : class; public Task ValidateWizardStepAsync(Type type, string fieldName, object fieldValue); } diff --git a/TIAMWebApp/Shared/Interfaces/IWizardProcessorResult.cs b/TIAMWebApp/Shared/Interfaces/IWizardProcessorResult.cs new file mode 100644 index 00000000..4ed7f3e4 --- /dev/null +++ b/TIAMWebApp/Shared/Interfaces/IWizardProcessorResult.cs @@ -0,0 +1,8 @@ +namespace TIAMWebApp.Shared.Application.Interfaces; + +public interface IWizardProcessorResult +{ + public TModelType Model { get; set; } + public string ResultJson { get; set; } + public bool IsSucces { get; set; } +} \ No newline at end of file diff --git a/TIAMWebApp/Shared/Models/WizardProcessorResult.cs b/TIAMWebApp/Shared/Models/WizardProcessorResult.cs new file mode 100644 index 00000000..fe63c3ce --- /dev/null +++ b/TIAMWebApp/Shared/Models/WizardProcessorResult.cs @@ -0,0 +1,10 @@ +using TIAMWebApp.Shared.Application.Interfaces; + +namespace TIAMWebApp.Shared.Application.Models; + +public class WizardProcessorResult : IWizardProcessorResult +{ + public TModel Model { get; set; } + public string ResultJson { get; set; } + public bool IsSucces { get; set; } +} \ No newline at end of file