Untitled
unknown
plain_text
2 years ago
7.8 kB
9
Indexable
@using HINT.Dto.Article
@using HINT.Services.User;
@using HINT.Shared.Components._Icons
@using HINT.Dto.Inventory
@using HINT.Services.Article;
@using HINT.Services.Site;
@using HINT.Services.Project;
@inject ArticleServices _articleServices
@inject IStringLocalizer<Profile> _sharedLocalizer
@inject IStringLocalizer<Projects> _localizer
<PageHeader Title="Ändra artikel" Context="@PageHeader.PageHeaderContext.Dialog"></PageHeader>
@if (_errorMessage != null)
{
<ErrorText>@_errorMessage</ErrorText>
}
<EditForm Model="_model" OnSubmit="UpdateArticleClicked">
<DialogRow>
<TextField Id="projectName" @bind-Value="_model.Name" Label="Benämnning" MaxLength="ProjectServices.MaxLengthName" />
</DialogRow>
<DialogRow>
<TextField Id="projectCategory" @bind-Value="_model.Category" Label="Kategori" MaxLength="ProjectServices.MaxLengthName" />
</DialogRow>
<DialogRow>
<TextField Id="projectDescription" @bind-Value="_model.Description" Label="Beskrivning" MaxLength="ProjectServices.MaxLengthDescription" />
</DialogRow>
@* <DialogRow>
<TextField Id="projectWeight" @bind-Value="_model.Weight" Label="Vikt" MaxLength="ProjectServices.MaxLengthName" />
</DialogRow> *@
@* <DialogRow>
<Checkbox State="Checkbox.CheckboxState.Default" Checked="@IsCertified(_model.IsCertifiedSvanen)" Label="Svanenmärkt" OnClick="() => ToggleChecked(_model.IsCertifiedSvanen)" />
</DialogRow> *@
<DialogRow>
<DropDownSelectBoolValue @bind-Value="_model.IsTestOfNewDropDownComponent"
Label="Test Of New DropDownComponent" />
</DialogRow>
<DialogRow>
<DropDownSelectBoolValue @bind-Value="_model.IsCertifiedSvanen"
Label="Svanenmärkt"
/>
</DialogRow>
<DialogRow>
<DropDownSelectBoolValue @bind-Value="_model.IsCertifiedBraMiljoval"
Label="Bra Miljöval"
/>
</DialogRow>
<DialogRow>
<DropDownSelectBoolValue @bind-Value="_model.IsCertifiedCradleToCradle"
Label="Cradle to Cradle"
/>
</DialogRow>
<DialogRow>
<DropDownSelectBoolValue @bind-Value="_model.IsCertifiedEuEcoLabel"
Label="Eu Ecolabel"
/>
</DialogRow>
<DialogRow>
<DropDownSelectBoolValue @bind-Value="_model.IsCertifiedMobelfakta"
Label="Möbelfakta"
/>
</DialogRow>
@* <DialogRow>
<DropDownSelect @bind-Value="_model.IsCertifiedSvanen"
Label="Svanenmärkt"
Items="_answers" />
</DialogRow>
<DialogRow>
<DropDownSelect @bind-Value="_model.IsCertifiedBraMiljoval"
Label="Bra Miljöval"
Items="_answers" />
</DialogRow>
<DialogRow>
<DropDownSelect @bind-Value="_model.IsCertifiedCradleToCradle"
Label="Cradle to Cradle"
Items="_answers" />
</DialogRow>
<DialogRow>
<DropDownSelect @bind-Value="_model.IsCertifiedEuEcoLabel"
Label="Eu Ecolabel"
Items="_answers" />
</DialogRow>
<DialogRow>
<DropDownSelect @bind-Value="_model.IsCertifiedMobelfakta"
Label="Möbelfakta"
Items="_answers" />
</DialogRow> *@
<DialogButtonRow>
<CancelButton OnClick="CloseForm" />
<Button Text=@_sharedLocalizer["Spara"] Value="confirm" />
</DialogButtonRow>
</EditForm>
@code {
private Dictionary<Guid, String> _answers = new();
protected override void OnInitialized()
{
_answers = DefaultArticleChoices.All()
.ToDictionary(s => s.Choice, s => s.Name);
}
[Parameter]
public EventCallback OnClose { get; set; }
[Parameter]
public Guid ArticleId { get; set; }
[CascadingParameter]
protected LoggedInUserViewModel? LoggedInUser { get; set; }
private UpdateArticleModel _model = new();
private bool _isConfirmButtonDisabled = true;
private string? _errorMessage;
protected override async Task OnParametersSetAsync()
{
base.OnParametersSet();
if (ArticleId != Guid.Empty)
{
ArticleViewModel article = await _articleServices.GetArticle(ArticleId);
_model.Name = article.Name ?? "";
_model.Category = article.Category ?? "";
_model.Description = article.Description ?? "";
_model.Littera = article.Littera ?? "";
// TODO add all fields of article.
_model.Weight = article.Weight;
_model.IsTestOfNewDropDownComponent = true;
_model.IsCertifiedSvanen = article.IsCertifiedSvanen;
_model.IsCertifiedMobelfakta = article.IsCertifiedMobelfakta;
_model.IsCertifiedCradleToCradle = article.IsCertifiedCradleToCradle;
_model.IsCertifiedEuEcoLabel = article.IsCertifiedEuEcoLabe;
_model.IsCertifiedBraMiljoval = article.IsCertifiedBraMiljoval;
_model.IsPreviousOwner = article.;
_model.Material = article.Material ?? "";
_model.Make = article.Make ?? "";
_model.ArticleNumber = article.ArticleNumber ?? "";
_model.Height = article.Height;
_model.Width = article.Width;
_model.Depth = article.Depth;
_model.Treatment = article.Treatment ?? "";
_model.Diameter = article.Diameter;
_model.Price = article.Price;
_model.SeatHeight = article.SeatHeight;
_model.CO2eq = article.CO2eq;
_model.EnvironmentalProductDeclaration = article.EnvironmentalProductDeclaration ?? "";
}
}
private async Task CloseForm()
{
if (OnClose.HasDelegate)
{
await OnClose.InvokeAsync();
}
}
private async Task UpdateArticleClicked()
{
if (LoggedInUser == null || ArticleId == Guid.Empty)
{
return;
}
try
{
// TODO add all fields of article
await _articleServices.UpdateArticle(
new(ArticleId,
_model.Name,
_model.Description,
_model.Littera,
// _model.Category,
_model.Weight,
_model.IsCertifiedSvanen,
_model.IsCertifiedMobelfakta,
_model.IsCertifiedCradleToCradle,
_model.IsCertifiedEuEcoLabel,
_model.IsCertifiedBraMiljoval,
_model.IsPreviousOwner,
_model.Material,
_model.Make,
_model.ArticleNumber,
_model.Height,
_model.Width,
_model.Depth,
_model.Treatment,
_model.Diameter,
_model.Price,
_model.SeatHeight,
_model.CO2eq,
_model.EnvironmentalProductDeclaration
),
LoggedInUser.ServiceContext());
await CloseForm();
}
catch (Exception ex)
{
_errorMessage = ex.Message;
}
}
}Editor is loading...
Leave a Comment