From 9c5c698ecf97fd2088608b9d392290fbd49f400c Mon Sep 17 00:00:00 2001 From: Frede Hundewadt <22748698+fhdk@users.noreply.github.com> Date: Mon, 16 May 2022 10:34:27 +0200 Subject: [PATCH] built v0.2.37 --- Wonky.Client/Components/AppVersion.razor | 2 +- .../HttpRepository/ActivityHttpRepository.cs | 5 +- Wonky.Client/Pages/CompanyUpdate.razor.cs | 2 + Wonky.Client/Pages/CrmActivityCreate.razor | 2 +- Wonky.Client/Pages/CrmActivityCreate.razor.cs | 59 +++++++++++-------- Wonky.Client/Program.cs | 2 +- .../Services/AuthenticationService.cs | 2 +- .../AuthStateProvider.cs | 2 +- Wonky.Client/Wonky.Client.csproj | 1 + Wonky.Entity/DTO/DtoNgActivity.cs | 2 +- 10 files changed, 47 insertions(+), 32 deletions(-) rename Wonky.Client/{Providers => Shared}/AuthStateProvider.cs (99%) diff --git a/Wonky.Client/Components/AppVersion.razor b/Wonky.Client/Components/AppVersion.razor index 7b4fc433..0797f698 100644 --- a/Wonky.Client/Components/AppVersion.razor +++ b/Wonky.Client/Components/AppVersion.razor @@ -17,7 +17,7 @@ @Name @Version@if(IsBeta){-beta} @code { - private const string Version = "0.2.36"; + private const string Version = "0.2.37"; private const string Name = "wwo"; private const bool IsBeta = true; } diff --git a/Wonky.Client/HttpRepository/ActivityHttpRepository.cs b/Wonky.Client/HttpRepository/ActivityHttpRepository.cs index 992e073b..5806dfbb 100644 --- a/Wonky.Client/HttpRepository/ActivityHttpRepository.cs +++ b/Wonky.Client/HttpRepository/ActivityHttpRepository.cs @@ -37,12 +37,12 @@ public class ActivityHttpRepository : IActivityHttpRepository }; private readonly NavigationManager _navigation; - private ILogger _logger; + private ILogger _logger; private readonly HttpClient _client; private readonly ApiConfig _apiConfig; public ActivityHttpRepository(HttpClient client, - ILogger logger, + ILogger logger, NavigationManager navigation, IOptions configuration) { _client = client; @@ -77,6 +77,7 @@ public class ActivityHttpRepository : IActivityHttpRepository public async Task CreateActivity(DtoNgActivity model) { + Console.WriteLine(JsonSerializer.Serialize(model)); var response = await _client.PostAsJsonAsync($"{_apiConfig.ActivityEndpoint}", model).ConfigureAwait(true); var content = await response.Content.ReadAsStringAsync(); var result = JsonSerializer.Deserialize(content); diff --git a/Wonky.Client/Pages/CompanyUpdate.razor.cs b/Wonky.Client/Pages/CompanyUpdate.razor.cs index cd4fc287..28d8b8db 100644 --- a/Wonky.Client/Pages/CompanyUpdate.razor.cs +++ b/Wonky.Client/Pages/CompanyUpdate.razor.cs @@ -87,7 +87,9 @@ public partial class CompanyUpdate : IDisposable } DtoNgCompany.LastVisit = $"{LastVisit:yyyy-MM-dd}"; DtoNgCompany.NextVisit = $"{NextVisit:yyyy-MM-dd}"; + Console.WriteLine(JsonSerializer.Serialize(DtoNgCompany)); + await CompanyRepo.UpdateCompany(DtoNgCompany); ToastService.ShowSuccess($"Godt så. Firma '{DtoNgCompany!.Name}' er opdateret."); diff --git a/Wonky.Client/Pages/CrmActivityCreate.razor b/Wonky.Client/Pages/CrmActivityCreate.razor index 4260ed78..6a0d2b7b 100644 --- a/Wonky.Client/Pages/CrmActivityCreate.razor +++ b/Wonky.Client/Pages/CrmActivityCreate.razor @@ -85,7 +85,7 @@
- +
diff --git a/Wonky.Client/Pages/CrmActivityCreate.razor.cs b/Wonky.Client/Pages/CrmActivityCreate.razor.cs index ab30b834..769d70c1 100644 --- a/Wonky.Client/Pages/CrmActivityCreate.razor.cs +++ b/Wonky.Client/Pages/CrmActivityCreate.razor.cs @@ -13,6 +13,7 @@ // along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] // +using System.Text.Json; using Blazored.LocalStorage; using Blazored.Toast.Services; using Wonky.Client.Helpers; @@ -62,6 +63,7 @@ public partial class CrmActivityCreate : IDisposable private bool InvalidDate { get; set; } = true; private UserInfoView Ux { get; set; } = new(); private VatUtils _vatUtils { get; set; } + private DateTime _draftDate { get; set; } protected override void OnParametersSet() { @@ -70,9 +72,10 @@ public partial class CrmActivityCreate : IDisposable protected override async Task OnInitializedAsync() { - _vatUtils = new VatUtils(); Interceptor.RegisterEvent(); Interceptor.RegisterBeforeSendEvent(); + + _vatUtils = new VatUtils(); _prefs = await UserPrefs.GetPreferences(); _paging.SearchColumn = _prefs.ItemSearch; _paging.PageSize = Convert.ToInt32(_prefs.PageSize); @@ -83,12 +86,13 @@ public partial class CrmActivityCreate : IDisposable DraftContext = new EditContext(_poDraft); DraftContext.OnFieldChanged += HandleFieldChanged; - // set up indexdb identification - _poDraft.SalesHeadId = Guid.NewGuid().ToString(); + // set up identification + _poDraft.SalesHeadId = ""; _poDraft.CompanyId = CompanyId; - _poDraft.ActivityDate = string.IsNullOrWhiteSpace(_prefs.WorkDate) + _draftDate = string.IsNullOrWhiteSpace(_prefs.WorkDate) ? DateTime.Now : DateTime.Parse(_prefs.WorkDate); + _poDraft.ActivityDate = $"{_draftDate:yyyy-MM-dd}"; // permanent identifications _poDraft.SalesRep = Ux.Adviser; @@ -114,34 +118,40 @@ public partial class CrmActivityCreate : IDisposable { HideButtons = true; // write work date to preference - await UserPrefs.SetWorkDate(_poDraft.ActivityDate); + await UserPrefs.SetWorkDate(_draftDate); var activityType = _poDraft.ActivityTypeEnum switch { - "phone" => "Tlf. ", - "onSite" => "Bsg. ", + "phone" => "Tlf", + "onSite" => "Bsg", _ => "" }; - _poDraft.OurRef = $"{activityType}{Ux.FullName.Split(" ")[0]}"; - + _poDraft.OurRef = $"{Ux.FullName.Split(" ")[0]} {activityType}"; + _poDraft.ActivityDate = $"{_draftDate:yyyy-MM-dd}"; var ln = 0; + // post to create activity endpoint - foreach (var line in DraftStateProvider.Draft.Items.Select(item => new DtoNgActivityLine - { - Price = item.Price, - Discount = item.Discount, - Qty = item.Quantity, - Sku = item.Item.Sku, - Text = item.Item.Name, - LineAmount = item.LineTotal, - LineNumber = ++ln, - Sas = item.Sas - })) + var lines = new List(); + foreach (var item in DraftStateProvider.Draft.Items) { - _poDraft.Lines.Add(line); + var line = new DtoNgActivityLine{ + Price = item.Price, + Discount = item.Discount, + Qty = item.Quantity, + Sku = item.Item.Sku, + Text = item.Item.Name, + LineAmount = item.LineTotal, + LineNumber = ++ln, + Sas = item.Sas + }; + lines.Add(line); } - //await StorageService.SetItemAsync(CompanyId, _poDraft); - await ActivityRepo.CreateActivity(_poDraft); - ToastService.ShowSuccess($"Godt så! Aktivitet oprettet for {_poDraft.Name}."); + _poDraft.Lines = lines; + + await StorageService.SetItemAsync(CompanyId, _poDraft); + + var result = await ActivityRepo.CreateActivity(_poDraft).ConfigureAwait(true); + Console.WriteLine(JsonSerializer.Serialize(result)); + ToastService.ShowSuccess($"{result.Message}."); NavigationManager.NavigateTo($"/companies"); } @@ -158,6 +168,7 @@ public partial class CrmActivityCreate : IDisposable private void CheckDate() { + _poDraft.ActivityDate = $"{_draftDate:yyyy-MM-dd}"; InvalidDate = _poDraft.CheckDate; Console.WriteLine($"InvalidDate => {InvalidDate}"); } diff --git a/Wonky.Client/Program.cs b/Wonky.Client/Program.cs index 3535b9b0..4ae0da12 100644 --- a/Wonky.Client/Program.cs +++ b/Wonky.Client/Program.cs @@ -23,8 +23,8 @@ using Blazored.Toast; using Wonky.Client; using Wonky.Client.HttpInterceptors; using Wonky.Client.HttpRepository; -using Wonky.Client.Providers; using Wonky.Client.Services; +using Wonky.Client.Shared; using Wonky.Entity.Configuration; var builder = WebAssemblyHostBuilder.CreateDefault(args); diff --git a/Wonky.Client/Services/AuthenticationService.cs b/Wonky.Client/Services/AuthenticationService.cs index d5f848c0..eab849c1 100644 --- a/Wonky.Client/Services/AuthenticationService.cs +++ b/Wonky.Client/Services/AuthenticationService.cs @@ -19,7 +19,7 @@ using System.Text.Json; using Blazored.LocalStorage; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.Extensions.Options; -using Wonky.Client.Providers; +using Wonky.Client.Shared; using Wonky.Entity.Configuration; using Wonky.Entity.DTO; diff --git a/Wonky.Client/Providers/AuthStateProvider.cs b/Wonky.Client/Shared/AuthStateProvider.cs similarity index 99% rename from Wonky.Client/Providers/AuthStateProvider.cs rename to Wonky.Client/Shared/AuthStateProvider.cs index 610a3998..94b16d9d 100644 --- a/Wonky.Client/Providers/AuthStateProvider.cs +++ b/Wonky.Client/Shared/AuthStateProvider.cs @@ -19,7 +19,7 @@ using Blazored.LocalStorage; using Microsoft.AspNetCore.Components.Authorization; using Wonky.Entity.DTO; -namespace Wonky.Client.Providers +namespace Wonky.Client.Shared { public class AuthStateProvider : AuthenticationStateProvider { diff --git a/Wonky.Client/Wonky.Client.csproj b/Wonky.Client/Wonky.Client.csproj index 689f4457..f4010919 100644 --- a/Wonky.Client/Wonky.Client.csproj +++ b/Wonky.Client/Wonky.Client.csproj @@ -33,6 +33,7 @@ + diff --git a/Wonky.Entity/DTO/DtoNgActivity.cs b/Wonky.Entity/DTO/DtoNgActivity.cs index 68a9b817..4283f964 100644 --- a/Wonky.Entity/DTO/DtoNgActivity.cs +++ b/Wonky.Entity/DTO/DtoNgActivity.cs @@ -36,7 +36,7 @@ namespace Wonky.Entity.DTO [Required(ErrorMessage = "Vælg aktivitetstype")] public string ActivityTypeEnum { get; set; } = ""; [Required(ErrorMessage = "Vælg status for besøg ")] public string ActivityStatusEnum { get; set; } = ""; public bool CheckDate { get; set; } - [Required] public DateTime ActivityDate { get; set; } + [Required] public string ActivityDate { get; set; } = ""; [MaxLength(50, ErrorMessage = "Du kan højst bruge 50 tegn")] public string Demo { get; set; } = ""; [MaxLength(20, ErrorMessage = "Du kan højst bruge 20 tegn")] public string OurRef { get; set; } = ""; [MaxLength(20, ErrorMessage = "Du kan højst bruge 20 tegn")] public string ReferenceNumber { get; set; } = "";