Browse Source

Send Missing report

master
Flo Smilari 4 years ago
parent
commit
9e6c83ffa8

+ 4
- 3
Pages/AccountPage.razor View File

@@ -73,8 +73,8 @@
@code {
[Parameter]
public string FromRoute { get; set; }
[Parameter]
public string FromRoute { get; set; }
private UserData Account = new();
@@ -105,10 +105,11 @@
}
private void Next() {
UserDataProvider.mapReport(ReportDataProvider.Report, Account);
if ("Found".Equals(FromRoute)) {
UserDataProvider.mapReport(ReportDataProvider.Report, Account);
NavigationManager.NavigateTo("fundvelo/conclusion_found");
} else {
UserDataProvider.mapMissingReport(ReportDataProvider.GetMissingReport(), Account);
NavigationManager.NavigateTo("fundvelo/conclusion_missing");
}
}

+ 1
- 1
Pages/CaritasServiceFundVeloFoundConclusion.razor View File

@@ -65,7 +65,7 @@
base.OnInitialized();
PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
try {
response = await ILFBicycleRest.SendFoundReport(ReportDataProvider.GetFoundReport());
response = await ILFBicycleRest.SendFoundReport(ReportDataProvider.Report);
responseOk = System.Net.HttpStatusCode.OK == response.StatusCode ? true : false;
} catch (HttpRequestException ex) {
response = new(i18n.GetString("FoundBike"), new string[] { ex.Message });

+ 37
- 3
Pages/CaritasServiceFundVeloMissingConclusion.razor View File

@@ -1,19 +1,33 @@
@page "/fundvelo/conclusion_missing"
@using cwebplusApp.Shared.Services;
@using cwebplusApp.Shared.Models;
@inject NavigationManager NavigationManager;
@inject IStringLocalizer<Resources> i18n;
@inject PageHistoryManager PageHistoryManager;
@inject ReportDataProvider ReportDataProvider;
@inject ILFBicycleRest ILFBicycleRest;
@inject Toaster Toaster;
@inject AppState AppState;
<div class="row px-3 h-100">
<div class="row no-gutters align-items-start justify-content-center w-100">
<MatHeadline4 Style="font-family:Ubuntu;padding-top:1em">@i18n["Info"]</MatHeadline4>
</div>
<div class="row no-gutters align-items-start justify-content-center w-100">
<MatHeadline6 Style="font-family:Ubuntu">@i18n["FinishedTextMissing"]</MatHeadline6>
@if (running) {
<div style="width:48px;margin:0 auto;">
<MatProgressCircle Indeterminate="true" Size="MatProgressCircleSize.Large" />
</div>
<div class="w-100" style="text-align:center;">
<h6 style="font-style:italic;padding-bottom:1em">@i18n["Info.Report.Transmitting"]</h6>
</div>
} else {
if (responseOk) {
<MatHeadline6 Style="font-family:Ubuntu">@i18n["FinishedTextMissing"]</MatHeadline6>
}
}
</div>
<div class="row no-gutters align-items-end justify-content-center w-100" style="padding-bottom:2em;padding-top:2em">
<div class="col w-100 text-center">
@@ -25,10 +39,30 @@
@code {
protected override void OnInitialized() {
private bool responseOk = false;
private bool running = true;
ReportResponse response;
protected async override void OnInitialized() {
base.OnInitialized();
PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
ILFBicycleRest.SendMissingReport(ReportDataProvider.GetMissingReport());
try {
response = await ILFBicycleRest.SendMissingReport(ReportDataProvider.Report);
responseOk = System.Net.HttpStatusCode.OK == response.StatusCode ? true : false;
} catch (HttpRequestException ex) {
response = new(i18n.GetString("MissingBike"), new string[] { ex.Message });
responseOk = false;
}
running = false;
if (responseOk) {
Toaster.ShowSuccess(i18n.GetString("MissingBike"), response.Message);
PageHistoryManager.Reset();
} else {
Toaster.ShowError(response.Message, response.GetDataAsFormattedList());
}
StateHasChanged();
AppState.NotifyChanged();
}
private void Finished() {

+ 1
- 1
Shared/Models/MissingReport.cs View File

@@ -9,7 +9,7 @@
public string NeueMarke { get; set; }
public string Zusatz { get; set; }
public string Postfach { get; set; }
public int SuchDienstId { get; set; }
public int? SuchDienstId { get; set; }
public string SuchDienstNr { get; set; }

+ 2
- 2
Shared/Services/ILFBicycleRest.cs View File

@@ -14,8 +14,8 @@ namespace cwebplusApp.Shared.Services {
Task<List<Brand>> GetBrands();
Task<ReportResponse> SendFoundReport(FoundReport report);
Task<ReportResponse> SendFoundReport(Report report);
Task<ReportResponse> SendMissingReport(MissingReport report);
Task<ReportResponse> SendMissingReport(Report report);
}
}

+ 11
- 19
Shared/Services/LFBicycleRest.cs View File

@@ -76,9 +76,18 @@ namespace cwebplusApp.Shared.Services {
throw new HttpRequestException("HTTP client not initialized!");
}
public async Task<ReportResponse> SendFoundReport(FoundReport report) {
public async Task<ReportResponse> SendFoundReport(Report report) {
string subResourceUrl = Configuration.GetValue<string>("subresource_url_foundreport");
return await SendReport(report, subResourceUrl);
}
public async Task<ReportResponse> SendMissingReport(Report report) {
string subResourceUrl = Configuration.GetValue<string>("subresource_url_missingreport");
return await SendReport(report, subResourceUrl);
}
protected async Task<ReportResponse> SendReport(Report report, string subResourceUrl) {
if (httpClient != null) {
string subResourceUrl = Configuration.GetValue<string>("subresource_url_foundreport");
if (!String.IsNullOrEmpty(subResourceUrl)) {
string reportJson = JsonConvert.SerializeObject(report);
HttpContent content = new StringContent(reportJson, Encoding.UTF8, "application/json");
@@ -91,22 +100,5 @@ namespace cwebplusApp.Shared.Services {
}
throw new HttpRequestException("HTTP client not initialized!");
}
public async Task<ReportResponse> SendMissingReport(MissingReport report) {
if (httpClient != null) {
string subResourceUrl = Configuration.GetValue<string>("subresource_url_missingreport");
if (!String.IsNullOrEmpty(subResourceUrl)) {
string reportJson = JsonConvert.SerializeObject(report);
HttpContent content = new StringContent(reportJson, Encoding.UTF8, "application/json");
HttpResponseMessage httpResult = await httpClient.PostAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName), content);
if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) {
ReportResponse reponse = JsonConvert.DeserializeObject<ReportResponse>(await httpResult.Content.ReadAsStringAsync());
return reponse;
}
throw new HttpRequestException("HTTP error " + httpResult.StatusCode);
}
}
throw new HttpRequestException("HTTP client not initialized!");
}
}
}

+ 13
- 0
Shared/Services/UserDataProvider.cs View File

@@ -75,5 +75,18 @@ namespace cwebplusApp.Shared.Services {
report.Nachname = Lastname;
report.Telefon = Phone;
}
public static void mapMissingReport(MissingReport report, UserData userData) {
report.Anrede = userData.Salutation;
report.Vorname = userData.Firstname;
report.Nachname = userData.Lastname;
report.Telefon = userData.Phone;
report.PersonOrt = userData.City;
report.PersonPLZ = userData.Zip;
report.PersonStrasse = userData.Address;
report.Mobil = userData.Phone;
report.Mail = userData.Email;
}
}
}

Loading…
Cancel
Save