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
12<EditForm Model="newCustomer" OnValidSubmit="AddCustomer" OnInvalidSubmit="EventCallback.Empty">
13 <StandardModal Header="Ny kunde" SubmitButtonName="Opprett kunde" @ref="Modal" OnModalClosed="() => newCustomer = new()">
15 <div class="create-modal-container">
16 <ObjectGraphDataAnnotationsValidator />
18 <FloatingInput Name="Kundenavn*">
19 <InputText @bind-Value="@newCustomer.CustomerName" type="text" class="form-control input-text" id="floatingInput" placeholder=" " autocomplete="off"/>
22 <FloatingInput Name="Org.Nr.*">
23 <InputText @bind-Value="@newCustomer.OrganizationNumber" type="text" class="form-control input-text" id="floatingInput" placeholder=" " autocomplete="off"/>
26 <FloatingInput Name="Reskontronummer">
27 <InputText @bind-Value="newCustomer.LedgerNumber" type="text" class="form-control input-text" id="floatingInput" placeholder=" " />
30 @if (_regionViewService.Regions != null)
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" />
35 <datalist id="countryList">
36 @foreach (var r in _regionViewService.Regions.DistinctBy(r => r.Country).ToList())
38 <option value="@r.Country">@r.Country</option>
43 @if (newCustomer.Region.Country != null)
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" />
48 <datalist id="areaList">
49 @foreach (var r in _regionViewService.Regions.Where(r => r.Country == newCustomer.Region.Country).DistinctBy(r => r.Area).ToList())
51 <option value="@r.Area">@r.Area</option>
56 <FloatingSelect TItem="int?" Name="Prioritet" StandardOption="Velg prioritet" ValueChanged="v => newCustomer.PrioritySeq = v">
57 @if (_priorityViewService.Priorities != null)
59 @foreach (var p in _priorityViewService.Priorities)
61 <option value="@p.PrioritySeq">@p.PriorityName.ToString()?.CapitalizeFirstLetter()</option>
66 <FloatingSelect TItem="int?" Name="Kundeansvarlig" StandardOption="Velg kundeansvarlig" ValueChanged="v => newCustomer.UserSeq = v" >
67 @if (_userViewService.Users != null)
69 @foreach (var u in _userViewService.Users)
71 <option value="@u.UserSeq">@u.UserEmail</option>
76 <FloatingSelect TItem="int?" Name="Hovedbransje" StandardOption="Velg hovedbransje" ValueChanged="v => SelectedMainSegmentSeq = v" >
77 @if (_mainSegmentViewService.MainSegments != null)
79 @foreach (var ms in _mainSegmentViewService.MainSegments)
81 <option value="@ms.MainSegmentSeq">@ms.MainSegmentName</option>
86 @if (SelectedMainSegmentSeq != null)
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)
91 <option value="@s.SegmentSeq">@s.SegmentName</option>
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=""/>
107 private CustomerClientModel? newCustomer { get; set; } = new();
108 private StandardModal Modal { get; set; }
110 private int? SelectedMainSegmentSeq { get; set; }
112 private async void AddCustomer()
114 var addedCustomer = await _customerViewService.AddCustomer(newCustomer!);
115 if (addedCustomer != null)