transferdestination changes
This commit is contained in:
parent
f317406acf
commit
553759039f
|
|
@ -43,6 +43,14 @@ namespace TIAM.Database.DataLayers.Admins
|
||||||
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) && ctx.SaveChanges() > 0);
|
||||||
#endregion Transfer
|
#endregion Transfer
|
||||||
|
|
||||||
|
#region TransferDestination
|
||||||
|
public Task<bool> AddTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.AddTransferDestination(transferDestination) && ctx.SaveChanges() > 0);
|
||||||
|
public Task<bool> UpdateTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.UpdateTransferDestination(transferDestination) && ctx.SaveChanges() > 0);
|
||||||
|
public Task<bool> RemoveTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.RemoveTransferDestination(transferDestination) && ctx.SaveChanges() > 0);
|
||||||
|
public Task<bool> RemoveTransferDestinationAsync(Guid transferDestinationId) => TransactionAsync(ctx => ctx.RemoveTransferDestination(transferDestinationId) && ctx.SaveChanges() > 0);
|
||||||
|
|
||||||
|
#endregion TransferDestination
|
||||||
|
|
||||||
public User? GetUserById(Guid userId, bool autoInclude = false) => Session(ctx => ctx.GetUserById(userId, autoInclude));
|
public User? GetUserById(Guid userId, bool autoInclude = false) => Session(ctx => ctx.GetUserById(userId, autoInclude));
|
||||||
public User? GetUserByEmail(string email, bool autoInclude = false) => Session(ctx => ctx.GetUserByEmail(email, autoInclude));
|
public User? GetUserByEmail(string email, bool autoInclude = false) => Session(ctx => ctx.GetUserByEmail(email, autoInclude));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,23 @@ public static class TransferDbSetExtensions
|
||||||
=> ctx.TransferDestinations.FirstOrDefault(x => x.Id == transferDestinationId);
|
=> ctx.TransferDestinations.FirstOrDefault(x => x.Id == transferDestinationId);
|
||||||
|
|
||||||
public static IQueryable<TransferDestination> GetTransferDestinations(this ITransferDestinationDbSet ctx)
|
public static IQueryable<TransferDestination> GetTransferDestinations(this ITransferDestinationDbSet ctx)
|
||||||
=> ctx.TransferDestinations;
|
=> ctx.TransferDestinations;
|
||||||
|
|
||||||
|
#region TransferDestination
|
||||||
|
public static bool AddTransferDestination(this ITransferDestinationDbSet ctx, TransferDestination transferDestination)
|
||||||
|
=> ctx.TransferDestinations.Add(transferDestination).State == EntityState.Added;
|
||||||
|
|
||||||
|
public static bool UpdateTransferDestination(this ITransferDestinationDbSet ctx, TransferDestination transferDestination)
|
||||||
|
=> ctx.TransferDestinations.Update(transferDestination).State == EntityState.Modified;
|
||||||
|
|
||||||
|
public static bool RemoveTransferDestination(this ITransferDestinationDbSet ctx, TransferDestination transferDestination)
|
||||||
|
=> ctx.TransferDestinations.Remove(transferDestination).State == EntityState.Deleted;
|
||||||
|
|
||||||
|
public static bool RemoveTransferDestination(this ITransferDestinationDbSet ctx, Guid transferDestinationId)
|
||||||
|
{
|
||||||
|
var transfer = ctx.GetTransferDestinationById(transferDestinationId);
|
||||||
|
return transfer == null || ctx.RemoveTransferDestination(transferDestinationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion TransferDestination
|
||||||
}
|
}
|
||||||
|
|
@ -16,6 +16,7 @@ namespace TIAM.Entities.TransferDestinations
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
public Guid AddressId { get; set; }
|
public Guid AddressId { get; set; }
|
||||||
|
[ForeignKey(nameof(AddressId))]
|
||||||
public virtual Address Address { get; set; }
|
public virtual Address Address { get; set; }
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ namespace TIAMMobileApp.Services
|
||||||
switch (type.Name)
|
switch (type.Name)
|
||||||
{
|
{
|
||||||
case "TransferDestinationWizardModel":
|
case "TransferDestinationWizardModel":
|
||||||
var result = await transferDataService.CreateTransferDestination((TransferDestinationWizardModel)data);
|
var result = await transferDataService.CreateTransferDestination((TransferDestination)data);
|
||||||
return result as TModelType;
|
return result as TModelType;
|
||||||
|
|
||||||
//var a = new WizardProcessorResult<TransferDestination>();
|
//var a = new WizardProcessorResult<TransferDestination>();
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@
|
||||||
</DxGridDataColumn>
|
</DxGridDataColumn>
|
||||||
<DxGridDataColumn FieldName="Description" FixedPosition="GridColumnFixedPosition.Left" MinWidth="80" Width="20%" />
|
<DxGridDataColumn FieldName="Description" FixedPosition="GridColumnFixedPosition.Left" MinWidth="80" Width="20%" />
|
||||||
<DxGridDataColumn FieldName="AddressString" MinWidth="80" Width="20%" />
|
<DxGridDataColumn FieldName="AddressString" MinWidth="80" Width="20%" />
|
||||||
|
<DxGridDataColumn FieldName="PriceType" MinWidth="80" Width="20%" />
|
||||||
<DxGridDataColumn FieldName="Price" MinWidth="80" Width="20%" />
|
<DxGridDataColumn FieldName="Price" MinWidth="80" Width="20%" />
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -72,11 +73,14 @@
|
||||||
@EditFormContext.GetEditor("Name")
|
@EditFormContext.GetEditor("Name")
|
||||||
</DxFormLayoutItem>
|
</DxFormLayoutItem>
|
||||||
<DxFormLayoutItem Caption=@localizer.GetString(ResourceKeys.Destination) ColSpanMd="6">
|
<DxFormLayoutItem Caption=@localizer.GetString(ResourceKeys.Destination) ColSpanMd="6">
|
||||||
@EditFormContext.GetEditor("Destination")
|
@EditFormContext.GetEditor("Description")
|
||||||
</DxFormLayoutItem>
|
</DxFormLayoutItem>
|
||||||
<DxFormLayoutItem Caption=@localizer.GetString(ResourceKeys.DestinationAddress) ColSpanMd="6">
|
<DxFormLayoutItem Caption=@localizer.GetString(ResourceKeys.DestinationAddress) ColSpanMd="6">
|
||||||
@EditFormContext.GetEditor("AddressString")
|
@EditFormContext.GetEditor("AddressString")
|
||||||
</DxFormLayoutItem>
|
</DxFormLayoutItem>
|
||||||
|
<DxFormLayoutItem Caption=@localizer.GetString(ResourceKeys.Price) ColSpanMd="6">
|
||||||
|
@EditFormContext.GetEditor("PriceType")
|
||||||
|
</DxFormLayoutItem>
|
||||||
<DxFormLayoutItem Caption=@localizer.GetString(ResourceKeys.Price) ColSpanMd="6">
|
<DxFormLayoutItem Caption=@localizer.GetString(ResourceKeys.Price) ColSpanMd="6">
|
||||||
@EditFormContext.GetEditor("Price")
|
@EditFormContext.GetEditor("Price")
|
||||||
</DxFormLayoutItem>
|
</DxFormLayoutItem>
|
||||||
|
|
|
||||||
|
|
@ -84,10 +84,9 @@ namespace TIAMSharedUI.Pages.User.SysAdmins
|
||||||
{
|
{
|
||||||
var newDestination = (TransferDestinationWizardModel)e.EditModel;
|
var newDestination = (TransferDestinationWizardModel)e.EditModel;
|
||||||
newDestination.Id = Guid.NewGuid().ToString();
|
newDestination.Id = Guid.NewGuid().ToString();
|
||||||
newDestination.Name = "ghjgkg hkgh ghjkghgkjgh";
|
newDestination.Name = "Destination name";
|
||||||
newDestination.Description = "ghjgkg hkgh ghjkghgkjgh";
|
newDestination.Description = "Type some description here";
|
||||||
newDestination.AddressString = "ghjgkg hkgh ghjkghgkjgh";
|
newDestination.AddressString = "The address of the destination";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -103,20 +102,23 @@ namespace TIAMSharedUI.Pages.User.SysAdmins
|
||||||
{
|
{
|
||||||
//add new row to grid
|
//add new row to grid
|
||||||
myModel = (TransferDestinationWizardModel)e.EditModel;
|
myModel = (TransferDestinationWizardModel)e.EditModel;
|
||||||
|
|
||||||
//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(new TransferDestinationWizardModel
|
await transferDataService.CreateTransferDestination(TransferDestinationWizardModel.SaveToTransferDestination(myModel));
|
||||||
{
|
//await transferDataService.CreateTransferDestination(new TransferDestination
|
||||||
Name = myModel.Name,
|
/*{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = myModel.Name,
|
||||||
Description = myModel.Description,
|
Description = myModel.Description,
|
||||||
AddressString = myModel.AddressString
|
AddressString = myModel.AddressString,
|
||||||
});
|
Price = myModel.Price,
|
||||||
|
PriceType = myModel.PriceType
|
||||||
|
});*/
|
||||||
logToBrowserConsole.LogToBC("New orderData added");
|
logToBrowserConsole.LogToBC("New orderData added");
|
||||||
|
|
||||||
//add mymodel to transferData array
|
//add mymodel to transferData array
|
||||||
TransferDataFromDb = ((TransferDestinationWizardModel[])TransferDataFromDb).Append(myModel);
|
TransferDataFromDb = ((TransferDestinationWizardModel[])TransferDataFromDb).Append(myModel).ToArray();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -124,17 +126,23 @@ namespace TIAMSharedUI.Pages.User.SysAdmins
|
||||||
//modify transferData where transferData.Id == e.EditModel.Id
|
//modify transferData where transferData.Id == e.EditModel.Id
|
||||||
//get transfer from TransferData by Id
|
//get transfer from TransferData by Id
|
||||||
|
|
||||||
|
var abg = ((TransferDestinationWizardModel[])TransferDataFromDb).Length;
|
||||||
|
|
||||||
foreach (var transferToModify in (TransferDestinationWizardModel[])TransferDataFromDb)
|
foreach (var transferToModify in (TransferDestinationWizardModel[])TransferDataFromDb)
|
||||||
{
|
{
|
||||||
myModel = (TransferDestinationWizardModel)e.EditModel;
|
myModel = (TransferDestinationWizardModel)e.EditModel;
|
||||||
|
|
||||||
if (transferToModify.Id == myModel.Id)
|
if (transferToModify.Id == myModel.Id)
|
||||||
{
|
{
|
||||||
myModel = (TransferDestinationWizardModel)e.EditModel;
|
|
||||||
|
transferToModify.Id = myModel.Id;
|
||||||
transferToModify.Name = myModel.Name;
|
transferToModify.Name = myModel.Name;
|
||||||
transferToModify.Description = myModel.Description;
|
transferToModify.Description = myModel.Description;
|
||||||
transferToModify.AddressString = myModel.AddressString;
|
transferToModify.AddressString = myModel.AddressString;
|
||||||
transferToModify.Price = myModel.Price;
|
transferToModify.Price = myModel.Price;
|
||||||
|
transferToModify.PriceType = myModel.PriceType;
|
||||||
|
|
||||||
|
await transferDataService.UpdateTransferDestination(TransferDestinationWizardModel.SaveToTransferDestination(transferToModify));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,7 +162,9 @@ namespace TIAMSharedUI.Pages.User.SysAdmins
|
||||||
async Task UpdateDataAsync()
|
async Task UpdateDataAsync()
|
||||||
{
|
{
|
||||||
//DataSource = await NwindDataService.GetEmployeesEditableAsync();
|
//DataSource = await NwindDataService.GetEmployeesEditableAsync();
|
||||||
|
await transferDataService.GetDestinationsAsync();
|
||||||
//refresh grid
|
//refresh grid
|
||||||
|
|
||||||
logToBrowserConsole.LogToBC("orderData grid refreshed");
|
logToBrowserConsole.LogToBC("orderData grid refreshed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -167,9 +177,11 @@ 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(Guid.NewGuid(), item.Name, item.Description, item.AddressString));
|
new TransferDestinationWizardModel(item.Id, item.Name, item.Description, item.AddressString, item.Price, item.PriceType)).ToArray();
|
||||||
logToBrowserConsole.LogToBC($"TransferDataFromDb: {item.Name}");
|
logToBrowserConsole.LogToBC($"TransferDataFromDb: {item.Name}");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
logToBrowserConsole.LogToBC($"TransferDataFromDb: {((TransferDestinationWizardModel[])TransferDataFromDb).Length}");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColumnChooserButton_Click()
|
void ColumnChooserButton_Click()
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ namespace TIAMWebApp.Client.Services
|
||||||
private readonly HttpClient http;
|
private readonly HttpClient http;
|
||||||
private readonly ISecureStorageHandler secureStorageHandler;
|
private readonly ISecureStorageHandler secureStorageHandler;
|
||||||
private readonly IJSRuntime jsRuntime;
|
private readonly IJSRuntime jsRuntime;
|
||||||
private readonly LogToBrowserConsole logToBrowserConsole;
|
private readonly LogToBrowserConsole logToBrowserConsole;
|
||||||
private readonly IServiceProviderDataService serviceProviderDataService;
|
private readonly IServiceProviderDataService serviceProviderDataService;
|
||||||
public Dictionary<int, string> userRoleTypes { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
public Dictionary<int, string> userRoleTypes { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||||
|
|
||||||
|
|
@ -33,7 +33,7 @@ namespace TIAMWebApp.Client.Services
|
||||||
this.jsRuntime = jSRuntime;
|
this.jsRuntime = jSRuntime;
|
||||||
this.logToBrowserConsole = new LogToBrowserConsole(jsRuntime);
|
this.logToBrowserConsole = new LogToBrowserConsole(jsRuntime);
|
||||||
this.serviceProviderDataService = serviceProviderDataService;
|
this.serviceProviderDataService = serviceProviderDataService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -42,7 +42,7 @@ namespace TIAMWebApp.Client.Services
|
||||||
{
|
{
|
||||||
//api call to get user
|
//api call to get user
|
||||||
var userModelDto = await GetUserByIdAsync(id);
|
var userModelDto = await GetUserByIdAsync(id);
|
||||||
|
|
||||||
if (userModelDto != null)
|
if (userModelDto != null)
|
||||||
{
|
{
|
||||||
//get user's properties
|
//get user's properties
|
||||||
|
|
@ -65,7 +65,9 @@ namespace TIAMWebApp.Client.Services
|
||||||
|
|
||||||
public async Task<string> TestUserApi(int Param)
|
public async Task<string> TestUserApi(int Param)
|
||||||
{
|
{
|
||||||
var url = APIUrls.UserTest;
|
var url = $"{Setting.BaseUrl}/{APIUrls.UserTest}";
|
||||||
|
|
||||||
|
|
||||||
var response = await http.PostAsJsonAsync(url, Param);
|
var response = await http.PostAsJsonAsync(url, Param);
|
||||||
var result = await response.Content.ReadAsStringAsync();
|
var result = await response.Content.ReadAsStringAsync();
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -74,7 +76,7 @@ namespace TIAMWebApp.Client.Services
|
||||||
public async Task<string> AuthenticateUser(LoginModel loginModel)
|
public async Task<string> AuthenticateUser(LoginModel loginModel)
|
||||||
{
|
{
|
||||||
string result = string.Empty;
|
string result = string.Empty;
|
||||||
var url = APIUrls.AuthenticateUser;
|
var url = $"{Setting.BaseUrl}/{APIUrls.AuthenticateUser}";
|
||||||
|
|
||||||
var response = await http.PostAsJsonAsync(url, loginModel);
|
var response = await http.PostAsJsonAsync(url, loginModel);
|
||||||
|
|
||||||
|
|
@ -105,7 +107,7 @@ namespace TIAMWebApp.Client.Services
|
||||||
{
|
{
|
||||||
|
|
||||||
bool isSuccess = true;
|
bool isSuccess = true;
|
||||||
string result = string.Empty;
|
string result = string.Empty;
|
||||||
var url = $"{Setting.BaseUrl}/{APIUrls.CreateUser}";
|
var url = $"{Setting.BaseUrl}/{APIUrls.CreateUser}";
|
||||||
logToBrowserConsole.LogToBC("CreateUser url: " + url);
|
logToBrowserConsole.LogToBC("CreateUser url: " + url);
|
||||||
var response = await http.PostAsJsonAsync(url, regModel);
|
var response = await http.PostAsJsonAsync(url, regModel);
|
||||||
|
|
@ -152,45 +154,44 @@ namespace TIAMWebApp.Client.Services
|
||||||
{
|
{
|
||||||
logToBrowserConsole.LogToBC("RefreshToken() called");
|
logToBrowserConsole.LogToBC("RefreshToken() called");
|
||||||
bool isTokenRefreshed = false;
|
bool isTokenRefreshed = false;
|
||||||
using (var client = new HttpClient())
|
|
||||||
|
var url = $"{Setting.BaseUrl}/{APIUrls.RefreshToken}";
|
||||||
|
//var url = APIUrls.RefreshToken;
|
||||||
|
|
||||||
|
var serializedStr = JsonConvert.SerializeObject(new AuthenticateRequestAndResponse
|
||||||
{
|
{
|
||||||
var url = $"{Setting.BaseUrl}{APIUrls.RefreshToken}";
|
RefreshToken = Setting.UserBasicDetails.RefreshToken,
|
||||||
//var url = APIUrls.RefreshToken;
|
AccessToken = Setting.UserBasicDetails.AccessToken
|
||||||
|
});
|
||||||
|
|
||||||
var serializedStr = JsonConvert.SerializeObject(new AuthenticateRequestAndResponse
|
try
|
||||||
|
{
|
||||||
|
logToBrowserConsole.LogToBC("Refreshtoken url: " + url);
|
||||||
|
var response = await http.PostAsync(url, new StringContent(serializedStr, Encoding.UTF8, "application/json"));
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
RefreshToken = Setting.UserBasicDetails.RefreshToken,
|
string contentStr = await response.Content.ReadAsStringAsync();
|
||||||
AccessToken = Setting.UserBasicDetails.AccessToken
|
var mainResponse = JsonConvert.DeserializeObject<MainResponse>(contentStr);
|
||||||
});
|
if (mainResponse.IsSuccess)
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
logToBrowserConsole.LogToBC("Refreshtoken url: " + url);
|
|
||||||
var response = await client.PostAsync(url, new StringContent(serializedStr, Encoding.UTF8, "application/json"));
|
|
||||||
if (response.IsSuccessStatusCode)
|
|
||||||
{
|
{
|
||||||
string contentStr = await response.Content.ReadAsStringAsync();
|
var tokenDetails = JsonConvert.DeserializeObject<AuthenticateRequestAndResponse>(mainResponse.Content.ToString());
|
||||||
var mainResponse = JsonConvert.DeserializeObject<MainResponse>(contentStr);
|
Setting.UserBasicDetails.AccessToken = tokenDetails.AccessToken;
|
||||||
if (mainResponse.IsSuccess)
|
Setting.UserBasicDetails.RefreshToken = tokenDetails.RefreshToken;
|
||||||
{
|
|
||||||
var tokenDetails = JsonConvert.DeserializeObject<AuthenticateRequestAndResponse>(mainResponse.Content.ToString());
|
|
||||||
Setting.UserBasicDetails.AccessToken = tokenDetails.AccessToken;
|
|
||||||
Setting.UserBasicDetails.RefreshToken = tokenDetails.RefreshToken;
|
|
||||||
|
|
||||||
string userDetailsStr = JsonConvert.SerializeObject(Setting.UserBasicDetails);
|
string userDetailsStr = JsonConvert.SerializeObject(Setting.UserBasicDetails);
|
||||||
await secureStorageHandler.SaveToSecureStorageAsync(nameof(Setting.UserBasicDetails), userDetailsStr);
|
await secureStorageHandler.SaveToSecureStorageAsync(nameof(Setting.UserBasicDetails), userDetailsStr);
|
||||||
isTokenRefreshed = true;
|
isTokenRefreshed = true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
string msg = ex.Message;
|
|
||||||
logToBrowserConsole.LogToBC("Refreshtoken exception: " + ex.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
string msg = ex.Message;
|
||||||
|
logToBrowserConsole.LogToBC("Refreshtoken exception: " + ex.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return isTokenRefreshed;
|
return isTokenRefreshed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ namespace TIAMWebApp.Client.Services
|
||||||
switch (type.Name)
|
switch (type.Name)
|
||||||
{
|
{
|
||||||
case "TransferDestinationWizardModel":
|
case "TransferDestinationWizardModel":
|
||||||
var result = await transferDataService.CreateTransferDestination((TransferDestinationWizardModel)data);
|
var result = await transferDataService.CreateTransferDestination((TransferDestination)data);
|
||||||
return result as TModelType;
|
return result as TModelType;
|
||||||
|
|
||||||
case "TransferWizardModel":
|
case "TransferWizardModel":
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
|
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("CreateTransferDestination")]
|
[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!");
|
||||||
|
|
@ -83,34 +83,31 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TransferDestinationWizardModel? transferDestinationModel = JObject.Parse(SerializedTransferDestinationModel.GetRawText()).ToObject<TransferDestinationWizardModel>();
|
TransferDestination? transferDestination = JObject.Parse(SerializedTransferDestinationModel.GetRawText()).ToObject<TransferDestination>();
|
||||||
|
|
||||||
if (transferDestinationModel != null)
|
if (transferDestination != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
var id = Guid.NewGuid();
|
var id = Guid.NewGuid();
|
||||||
TransferDestination transferDestination = new TransferDestination(id, transferDestinationModel.Name, transferDestinationModel.Description, transferDestinationModel.AddressString);
|
//TransferDestination transferDestination = new TransferDestination(id, transferDestinationModel.Name, transferDestinationModel.Description, transferDestinationModel.AddressString);
|
||||||
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(transferDestinationModel.Name) || string.IsNullOrEmpty(transferDestinationModel.AddressString))
|
if (string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString))
|
||||||
{
|
{
|
||||||
return BadRequest("Invalid request");
|
return BadRequest("Invalid request");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine($"TransferDestination to be created: {id}");
|
Console.WriteLine($"TransferDestination to be created: {id}");
|
||||||
|
Console.WriteLine($"TransferDestination to be created: {transferDestination.AddressId}");
|
||||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.Name}");
|
Console.WriteLine($"TransferDestination to be created: {transferDestination.Name}");
|
||||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.Price}");
|
Console.WriteLine($"TransferDestination to be created: {transferDestination.Price}");
|
||||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.PriceType}");
|
Console.WriteLine($"TransferDestination to be created: {transferDestination.PriceType}");
|
||||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.AddressString}");
|
Console.WriteLine($"TransferDestination to be created: {transferDestination.AddressString}");
|
||||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.Description}");
|
Console.WriteLine($"TransferDestination to be created: {transferDestination.Description}");
|
||||||
|
|
||||||
transferDestination.AddressId = Guid.Empty;
|
|
||||||
transferDestination.Price = 15000;
|
|
||||||
transferDestination.PriceType = PriceType.Fix;
|
|
||||||
|
|
||||||
//await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination);
|
//await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination);
|
||||||
await _transferDestinationDal.CreateTransferDestinationAsync(transferDestination);
|
await _adminDal.AddTransferDestinationAsync(transferDestination);
|
||||||
return Ok(transferDestination);
|
return Ok(transferDestination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -125,5 +122,79 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpPost]
|
||||||
|
[Route(APIUrls.UpdateTransferDestinationRouteName)]
|
||||||
|
public async Task<IActionResult> UpdateTransferDestination([FromBody]JsonElement SerializedTransferDestinationModel)
|
||||||
|
{
|
||||||
|
Console.WriteLine("UpdateTransferDestination called!");
|
||||||
|
if (string.IsNullOrEmpty(SerializedTransferDestinationModel.GetRawText()))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Bad request!");
|
||||||
|
return BadRequest("SerializedTramsferDestinationWizardModel is required");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Serialized model not empty!");
|
||||||
|
TransferDestination? transferDestination = JObject.Parse(SerializedTransferDestinationModel.GetRawText()).ToObject<TransferDestination>();
|
||||||
|
Console.WriteLine($"TransferDestination to be updated: {SerializedTransferDestinationModel.GetRawText()}");
|
||||||
|
Console.WriteLine($"TransferDestination to be updated: {transferDestination.AddressString}");
|
||||||
|
|
||||||
|
|
||||||
|
if (transferDestination != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
//TransferDestination transferDestination = new TransferDestination(id, transferDestinationModel.Name, transferDestinationModel.Description, transferDestinationModel.AddressString);
|
||||||
|
|
||||||
|
if (transferDestination.Id == Guid.Empty || string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Serialized model not empty, but bad request!");
|
||||||
|
return BadRequest("Invalid request");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
Console.WriteLine($"TransferDestination to be updated: {transferDestination.Id}");
|
||||||
|
Console.WriteLine($"TransferDestination to be updated new name: {transferDestination.Name}");
|
||||||
|
Console.WriteLine($"TransferDestination to be updated new price: {transferDestination.Price}");
|
||||||
|
Console.WriteLine($"TransferDestination to be updated new priceType: {transferDestination.PriceType}");
|
||||||
|
Console.WriteLine($"TransferDestination to be updated new address: {transferDestination.AddressString}");
|
||||||
|
Console.WriteLine($"TransferDestination to be updated new description: {transferDestination.Description}");
|
||||||
|
|
||||||
|
var dbTransferDestinationJson = _adminDal.GetTransferDestinationJsonById(transferDestination.Id);
|
||||||
|
Console.WriteLine($"TransferDestination JSON to be updated: {dbTransferDestinationJson}");
|
||||||
|
|
||||||
|
var dbTransferDestination = JObject.Parse(dbTransferDestinationJson).ToObject<TransferDestination>();
|
||||||
|
if (dbTransferDestination.Id != Guid.Empty)
|
||||||
|
{
|
||||||
|
|
||||||
|
dbTransferDestination.AddressId = transferDestination.AddressId;
|
||||||
|
dbTransferDestination.Price = transferDestination.Price;
|
||||||
|
dbTransferDestination.PriceType = transferDestination.PriceType;
|
||||||
|
dbTransferDestination.Name = transferDestination.Name;
|
||||||
|
dbTransferDestination.Description = transferDestination.Description;
|
||||||
|
dbTransferDestination.AddressString = transferDestination.AddressString;
|
||||||
|
dbTransferDestination.Address = transferDestination.Address;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination);
|
||||||
|
await _adminDal.UpdateTransferDestinationAsync(dbTransferDestination);
|
||||||
|
return Ok(dbTransferDestination);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return BadRequest("Invalid request");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -9,7 +9,10 @@ namespace TIAMWebApp.Shared.Application.Interfaces
|
||||||
Task<List<TransferDestination>> GetDestinationsAsync();
|
Task<List<TransferDestination>> GetDestinationsAsync();
|
||||||
Task<TransferDestination?> GetTransferDestinationbyCoordinatesAsync(string destinationId);
|
Task<TransferDestination?> GetTransferDestinationbyCoordinatesAsync(string destinationId);
|
||||||
Task<TransferDestination?> GetTransferDestinationbyAddressAsync(string destinationId);
|
Task<TransferDestination?> GetTransferDestinationbyAddressAsync(string destinationId);
|
||||||
Task<TransferDestination?> CreateTransferDestination(TransferDestinationWizardModel model);
|
Task<TransferDestination?> CreateTransferDestination(TransferDestination model);
|
||||||
|
|
||||||
|
Task<TransferDestination?> UpdateTransferDestination(TransferDestination model);
|
||||||
|
|
||||||
Task<TransferWizardModel?> CreateTransfer(TransferWizardModel model);
|
Task<TransferWizardModel?> CreateTransfer(TransferWizardModel model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,8 @@ namespace TIAMWebApp.Shared.Application.Models
|
||||||
public const string CreateTransferRouteName = "CreateTransfer";
|
public const string CreateTransferRouteName = "CreateTransfer";
|
||||||
public const string CreateTransfer = TransferDataAPI+CreateTransferRouteName;
|
public const string CreateTransfer = TransferDataAPI+CreateTransferRouteName;
|
||||||
|
|
||||||
|
public const string UpdateTransferDestinationRouteName = "UpdateTransfer";
|
||||||
|
public const string UpdateTransferDestination = TransferDataAPI + UpdateTransferDestinationRouteName;
|
||||||
|
|
||||||
//serviceprovider
|
//serviceprovider
|
||||||
public const string CreateServiceProviderRouteName = "CreateServiceProvider";
|
public const string CreateServiceProviderRouteName = "CreateServiceProvider";
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
using AyCode.Entities.Locations;
|
using AyCode.Entities.Locations;
|
||||||
using AyCode.Interfaces.TimeStampInfo;
|
using AyCode.Interfaces.TimeStampInfo;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.NetworkInformation;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using TIAM.Core.Enums;
|
||||||
|
using TIAM.Entities.Addresses;
|
||||||
|
using TIAM.Entities.TransferDestinations;
|
||||||
using TIAM.Resources;
|
using TIAM.Resources;
|
||||||
|
|
||||||
namespace TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
|
namespace TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
|
||||||
|
|
@ -36,7 +41,9 @@ namespace TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
|
||||||
[Required(ErrorMessage = "The price should be specified.")]
|
[Required(ErrorMessage = "The price should be specified.")]
|
||||||
[DataType("Price")]
|
[DataType("Price")]
|
||||||
[Display(Name = ResourceKeys.Price, ResourceType = typeof(TIAMResources))]
|
[Display(Name = ResourceKeys.Price, ResourceType = typeof(TIAMResources))]
|
||||||
public double? Price { get; set; }
|
public double Price { get; set; }
|
||||||
|
|
||||||
|
public PriceType PriceType { get; set; }
|
||||||
|
|
||||||
//[DataType("Latitude")]
|
//[DataType("Latitude")]
|
||||||
//[Display(Name = "Destination latitude")]
|
//[Display(Name = "Destination latitude")]
|
||||||
|
|
@ -48,16 +55,46 @@ namespace TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
|
||||||
|
|
||||||
public TransferDestinationWizardModel() { }
|
public TransferDestinationWizardModel() { }
|
||||||
|
|
||||||
public TransferDestinationWizardModel(string name, string description, string address) :this(Guid.NewGuid(), name, description, address)
|
public TransferDestinationWizardModel(string name, string description, string address, double price, PriceType priceType) :this(Guid.NewGuid(), name, description, address, price, priceType)
|
||||||
{ }
|
{ }
|
||||||
public TransferDestinationWizardModel(Guid id, string name, string description, string address)
|
public TransferDestinationWizardModel(Guid id, string name, string description, string address, double price, PriceType priceType)
|
||||||
{
|
{
|
||||||
|
|
||||||
Id = id.ToString();
|
Id = id.ToString();
|
||||||
Name = name;
|
Name = name;
|
||||||
Description = description;
|
Description = description;
|
||||||
AddressString = address;
|
AddressString = address;
|
||||||
|
Price = price;
|
||||||
|
PriceType = priceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TransferDestination SaveToTransferDestination(TransferDestinationWizardModel model)
|
||||||
|
=> SaveToTransferDestination(model, new TransferDestination());
|
||||||
|
|
||||||
|
public static TransferDestination SaveToTransferDestination(TransferDestinationWizardModel model, TransferDestination destination)
|
||||||
|
{
|
||||||
|
destination.Id = Guid.Parse(model.Id);
|
||||||
|
destination.Name = model.Name;
|
||||||
|
destination.Description = model.Description;
|
||||||
|
destination.AddressString = model.AddressString;
|
||||||
|
destination.Price = model.Price;
|
||||||
|
destination.PriceType = model.PriceType;
|
||||||
|
|
||||||
|
if (destination.Address == null)
|
||||||
|
{
|
||||||
|
var addressId = Guid.NewGuid();
|
||||||
|
|
||||||
|
destination.Address = new Address();
|
||||||
|
destination.AddressId = addressId;
|
||||||
|
destination.Address.Id = addressId;
|
||||||
|
}
|
||||||
|
Random rand = new Random();
|
||||||
|
int range = 42;
|
||||||
|
|
||||||
|
destination.Address.AddressText = model.AddressString;
|
||||||
|
destination.Address.Longitude = rand.NextDouble() * range;
|
||||||
|
destination.Address.Latitude = rand.NextDouble() * range;
|
||||||
|
return destination;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,9 @@ namespace TIAMWebApp.Shared.Application.Services
|
||||||
return await http.GetFromJsonAsync<TransferDestination>(url);
|
return await http.GetFromJsonAsync<TransferDestination>(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<TransferDestination?> CreateTransferDestination(TransferDestinationWizardModel model)
|
public async Task<TransferDestination?> CreateTransferDestination(TransferDestination model)
|
||||||
{
|
{
|
||||||
var url = $"{Setting.BaseUrl}/{APIUrls.CreateTransfer}";
|
var url = $"{Setting.BaseUrl}/{APIUrls.CreateTransferDestination}";
|
||||||
var response = await http.PostAsJsonAsync(url, model);
|
var response = await http.PostAsJsonAsync(url, model);
|
||||||
|
|
||||||
//var result = new WizardProcessorResult();
|
//var result = new WizardProcessorResult();
|
||||||
|
|
@ -83,5 +83,26 @@ namespace TIAMWebApp.Shared.Application.Services
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<TransferDestination?> UpdateTransferDestination(TransferDestination model)
|
||||||
|
{
|
||||||
|
var url = $"{Setting.BaseUrl}/{APIUrls.UpdateTransferDestination}";
|
||||||
|
var response = await http.PostAsJsonAsync(url, model);
|
||||||
|
|
||||||
|
//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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue