Escali License control 1
AddCustomerModal.razor
Gå til dokumentasjonen til denne filen.
1@using Microsoft.AspNetCore.Components
2@using Escali.LicenseControl.Client.ClientModels
3@using Escali.LicenseControl.Client.ViewModels
4@using Escali.LicenseControl.DataAccess.Models
5@using Escali.LicenseControl.Client.Utils
6@inject CustomerViewModel _customerViewService
7@inject PriorityViewModel _priorityViewService
8@inject MainSegmentViewModel _mainSegmentViewService
9@inject RegionViewModel _regionViewService
10@inject UserViewModel _userViewService
11
12<EditForm Model="newCustomer" OnValidSubmit="AddCustomer" OnInvalidSubmit="EventCallback.Empty">
13 <StandardModal Header="Ny kunde" SubmitButtonName="Opprett kunde" @ref="Modal" OnModalClosed="() => newCustomer = new()">
14
15 <div class="create-modal-container">
16 <ObjectGraphDataAnnotationsValidator />
17
18 <FloatingInput Name="Kundenavn*">
19 <InputText @bind-Value="@newCustomer.CustomerName" type="text" class="form-control input-text" id="floatingInput" placeholder=" " autocomplete="off"/>
20 </FloatingInput>
21
22 <FloatingInput Name="Org.Nr.*">
23 <InputText @bind-Value="@newCustomer.OrganizationNumber" type="text" class="form-control input-text" id="floatingInput" placeholder=" " autocomplete="off"/>
24 </FloatingInput>
25
26 <FloatingInput Name="Reskontronummer">
27 <InputText @bind-Value="newCustomer.LedgerNumber" type="text" class="form-control input-text" id="floatingInput" placeholder=" " />
28 </FloatingInput>
29
30 @if (_regionViewService.Regions != null)
31 {
32 <FloatingInput Name="Land*">
33 <InputText @bind-Value="newCustomer.Region.Country" type="text" class="form-control input-text" id="floatingInput" placeholder=" " list="countryList" autocomplete="off" />
34 </FloatingInput>
35 <datalist id="countryList">
36 @foreach (var r in _regionViewService.Regions.DistinctBy(r => r.Country).ToList())
37 {
38 <option value="@r.Country">@r.Country</option>
39 }
40 </datalist>
41 }
42
43 @if (newCustomer.Region.Country != null)
44 {
45 <FloatingInput Name="Region">
46 <InputText @bind-Value="newCustomer.Region.Area" type="text" class="form-control input-text" id="floatingInput" placeholder=" " list="areaList" autocomplete="off" />
47 </FloatingInput>
48 <datalist id="areaList">
49 @foreach (var r in _regionViewService.Regions.Where(r => r.Country == newCustomer.Region.Country).DistinctBy(r => r.Area).ToList())
50 {
51 <option value="@r.Area">@r.Area</option>
52 }
53 </datalist>
54 }
55
56 <FloatingSelect TItem="int?" Name="Prioritet" StandardOption="Velg prioritet" ValueChanged="v => newCustomer.PrioritySeq = v">
57 @if (_priorityViewService.Priorities != null)
58 {
59 @foreach (var p in _priorityViewService.Priorities)
60 {
61 <option value="@p.PrioritySeq">@p.PriorityName.ToString()?.CapitalizeFirstLetter()</option>
62 }
63 }
64 </FloatingSelect>
65
66 <FloatingSelect TItem="int?" Name="Kundeansvarlig" StandardOption="Velg kundeansvarlig" ValueChanged="v => newCustomer.UserSeq = v" >
67 @if (_userViewService.Users != null)
68 {
69 @foreach (var u in _userViewService.Users)
70 {
71 <option value="@u.UserSeq">@u.UserEmail</option>
72 }
73 }
74 </FloatingSelect>
75
76 <FloatingSelect TItem="int?" Name="Hovedbransje" StandardOption="Velg hovedbransje" ValueChanged="v => SelectedMainSegmentSeq = v" >
77 @if (_mainSegmentViewService.MainSegments != null)
78 {
79 @foreach (var ms in _mainSegmentViewService.MainSegments)
80 {
81 <option value="@ms.MainSegmentSeq">@ms.MainSegmentName</option>
82 }
83 }
84 </FloatingSelect>
85
86 @if (SelectedMainSegmentSeq != null)
87 {
88 <FloatingSelect TItem="int?" Name="Bransje" StandardOption="Velg bransje" ValueChanged="v => newCustomer.SegmentSeq = v" >
89 @foreach (var s in _mainSegmentViewService.MainSegments.Single(s => s.MainSegmentSeq == SelectedMainSegmentSeq).Segments)
90 {
91 <option value="@s.SegmentSeq">@s.SegmentName</option>
92 }
93 </FloatingSelect>
94 }
95
96 </div>
97
98 </StandardModal>
99</EditForm>
100
101<button class="btn btn-primary button-with-icon" @onclick="() => Modal.OpenModal()">
102 Ny kunde<img class="button-icon" src="Icons/add-icon.svg" alt=""/>
103</button>
104
105@code {
106
107 private CustomerClientModel? newCustomer { get; set; } = new();
108 private StandardModal Modal { get; set; }
109
110 private int? SelectedMainSegmentSeq { get; set; }
111
112 private async void AddCustomer()
113 {
114 var addedCustomer = await _customerViewService.AddCustomer(newCustomer!);
115 if (addedCustomer != null)
116 {
117 newCustomer = new();
118 Modal.HideModal();
119 }
120 }
121
122}