-
+
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; } = "";