1@inject CurrencyViewModel _currencyViewService
2@inject PriceListViewModel _priceListViewService
3@inject StateService _stateService
4@using System.ComponentModel.DataAnnotations
6@using Microsoft.AspNetCore.Components
10<EditForm Model="NewPriceList" OnValidSubmit="Submit" OnInvalidSubmit="EventCallback.Empty" >
12 <StandardModal Header="Ny prisliste" SubmitButtonName="Opprett prisliste" @ref="Modal" OnModalClosed="ResetPriceList">
14 <div class="create-modal-container">
15 <ObjectGraphDataAnnotationsValidator />
17 <FloatingInput Name="Navn*">
18 <InputText @bind-Value="NewPriceList.PriceListName" type="text" class="form-control input-text" id="floatingInput" placeholder=" " autocomplete="off"/>
21 @if (_currencyViewService.Currencies != null && NewPriceList.Currency != null)
23 <FloatingInput Name="Valuta*">
24 <InputText @bind-Value="NewPriceList.Currency.CurrencyName" type="text" class="form-control input-text hide-picker" id="floatingInput" placeholder=" " list="valutaList" autocomplete="off"/>
26 <datalist id="valutaList">
27 @foreach (var c in _currencyViewService.Currencies.DistinctBy(c => c.CurrencyName).ToList())
29 <option value="@c.CurrencyName">@c.CurrencyName</option>
34 <div class="input-split">
35 <div class="input-container form-floating mb-3">
36 <InputDate @bind-Value="NewPriceList.DateFrom" class="form-control input-text input-split-left" id="floatingInput" autocomplete="off" max="@NewPriceList.DateTo"/>
37 <label for="floatingInput">Startdato</label>
40 <div class="input-container form-floating mb-3">
41 <InputDate @bind-Value="NewPriceList.DateTo" class="form-control input-text input-split-right" id="floatingInput" autocomplete="off"/>
42 <label for="floatingInput">Sluttdato</label>
46 <div class="input-container">
47 <InputSelect class="form-select form-select-modal" @bind-Value="NewPriceList.PriceListToCopy" >
48 <option disabled>Velg prisliste for utgangspunkt*</option>
49 @if (_priceListViewService.PriceLists != null)
51 if (!_priceListViewService.PriceLists.Any(p => p.ProductSeq == _stateService.SelectedProductSeq.Value && p.Currency.CurrencyName == NewPriceList.Currency?.CurrencyName))
53 <option selected value="@(() => NewPriceList.PriceListToCopy = null)">Finnes ingen prislister med valgt valuta</option>
55 @foreach (var p in _priceListViewService.PriceLists.Where(p => p.ProductSeq == _stateService.SelectedProductSeq.Value && p.Currency.CurrencyName == NewPriceList.Currency?.CurrencyName).ToList())
57 <option value="@p.PriceListSeq">@p.PriceListName</option>
63 <div class="input-container form-floating mb-3">
64 <InputNumber @bind-Value="NewPriceList.PriceAdjustmentFactor" class="form-control input-text" id="floatingInput" placeholder="Faktor for prisøkning" autocomplete="off"/>
65 <label for="floatingInput">Faktor for prisøkning (min. 1)*</label>
74<button class="btn btn-primary button-with-icon" @onclick="() => Modal.OpenModal()">
76 <img class="button-icon" src="Icons/add-icon.svg" alt=""/>
81 private PriceListClientModelInput NewPriceList { get; set; } = new()
84 DateFrom = DateTime.Now,
87 private StandardModal Modal { get; set; }
89 private async void Submit()
91 NewPriceList.ProductSeq = _stateService.SelectedProductSeq.Value;
94 if (_currencyViewService.Currencies != null)
96 var seq = _currencyViewService.Currencies.SingleOrDefault(c => c.CurrencyName == NewPriceList.Currency.CurrencyName)?.CurrencySeq;
97 if (seq != null) currencySeq = seq.Value;
100 if (currencySeq != 0)
102 NewPriceList.Currency = null;
103 NewPriceList.CurrencySeq = currencySeq;
106 var mappedPriceList = _mapper.Map<PriceListClientModel>(NewPriceList);
108 var addedPricelist = await _priceListViewService.CreatePricelist(mappedPriceList, NewPriceList.PriceListToCopy!.Value, NewPriceList.PriceAdjustmentFactor!.Value);
109 if (addedPricelist != null)
111 await InvokeAsync(_currencyViewService.GetCurrencies);
118 private void ResetPriceList()
123 DateFrom = DateTime.Now,
124 DateTo = DateTime.Now
128 protected override void OnInitialized()
130 _currencyViewService.DataChanged += StateHasChanged;
133 void IDisposable.Dispose()
135 _currencyViewService.DataChanged -= StateHasChanged;