Fix selectable items in company details.

This commit is contained in:
2020-05-25 20:07:38 +01:00
parent 23a127a1e9
commit 1ca77f1692
4 changed files with 18 additions and 33 deletions

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<Version>3.0.99.1159</Version> <Version>3.0.99.1170</Version>
<Company>Canary Islands Computer Museum</Company> <Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright> <Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product> <Product>Canary Islands Computer Museum Website</Product>

View File

@@ -31,6 +31,7 @@
} }
@page "/admin/companies/details/{Id:int}" @page "/admin/companies/details/{Id:int}"
@using Marechai.Database
@inherits OwningComponentBase<CompaniesService> @inherits OwningComponentBase<CompaniesService>
@inject IStringLocalizer<CompaniesService> L @inject IStringLocalizer<CompaniesService> L
@inject Iso31661NumericService CountriesService @inject Iso31661NumericService CountriesService
@@ -52,7 +53,12 @@
</Field> </Field>
<Field> <Field>
<FieldLabel>@L["Status"]</FieldLabel> <FieldLabel>@L["Status"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@CompanyStatus"/> <Select Disabled="!_editable" TValue="int" @bind-SelectedValue="@Status">
@foreach (int status in Enum.GetValues(typeof(CompanyStatus)))
{
<SelectItem TValue="int" Value="@status">@(((CompanyStatus)status).ToString())</SelectItem>
}
</Select>
</Field> </Field>
@if(_editable || _model.Founded.HasValue) @if(_editable || _model.Founded.HasValue)
{ {
@@ -110,25 +116,18 @@
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.PostalCode" /> <TextEdit ReadOnly="!_editable" @bind-Text="@_model.PostalCode" />
</Field> </Field>
} }
@if (_editable) @if (_editable || _model.CountryId != null)
{ {
<Field> <Field>
<FieldLabel>@L["Country"]</FieldLabel> <FieldLabel>@L["Country"]</FieldLabel>
<Select ReadOnly="!_editable" TValue="short?" @bind-SelectedValue="@_model.CountryId"> <Select Disabled="!_editable" TValue="short?" @bind-SelectedValue="@_model.CountryId">
@foreach (var country in _countries) @foreach (var country in _countries)
{ {
<SelectItem Value="@country.Id">@country.Name</SelectItem> <SelectItem TValue="short?" Value="@country.Id">@country.Name</SelectItem>
} }
</Select> </Select>
</Field> </Field>
} }
else if (_model.CountryId != null)
{
<Field>
<FieldLabel>@L["Country"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.Country.Name" />
</Field>
}
@if (_editable || _model.Sold != null) @if (_editable || _model.Sold != null)
{ {
<Field> <Field>
@@ -136,25 +135,18 @@
<DateEdit ReadOnly="!_editable" TValue="DateTime?" @bind-Date="@_model.Sold" /> <DateEdit ReadOnly="!_editable" TValue="DateTime?" @bind-Date="@_model.Sold" />
</Field> </Field>
} }
@if (_editable) @if (_editable || _model.SoldToId != null)
{ {
<Field> <Field>
<FieldLabel>@L["Sold to"]</FieldLabel> <FieldLabel>@L["Sold to"]</FieldLabel>
<Select ReadOnly="!_editable" TValue="int?" @bind-SelectedValue="@_model.SoldToId"> <Select Disabled="!_editable" TValue="int?" @bind-SelectedValue="@_model.SoldToId">
@foreach (var company in _companies) @foreach (var company in _companies)
{ {
<SelectItem Value="@company.Id">@company.Name</SelectItem> <SelectItem TValue="int?" Value="@company.Id">@company.Name</SelectItem>
} }
</Select> </Select>
</Field> </Field>
} }
else if (_model.SoldToId != null)
{
<Field>
<FieldLabel>@L["Sold to"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.SoldTo.Name" />
</Field>
}
</div> </div>
<div> <div>
<span class="btn btn-primary">@L["Edit"]</span> <span class="btn btn-primary">@L["Edit"]</span>

View File

@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Marechai.Database; using Marechai.Database;
@@ -18,16 +17,10 @@ namespace Marechai.Pages.Admin.Details
[Parameter] [Parameter]
public int Id { get; set; } public int Id { get; set; }
public string CompanyStatus int Status
{ {
get => _model.Status.ToString(); get => (int)_model.Status;
set set => _model.Status = (CompanyStatus)value;
{
if(!Enum.TryParse(value, true, out CompanyStatus parsed))
return;
_model.Status = parsed;
}
} }
protected override async Task OnAfterRenderAsync(bool firstRender) protected override async Task OnAfterRenderAsync(bool firstRender)

View File

@@ -1 +1 @@
{"projectId":"fd3f3857-80b9-4ed7-90f8-c6ebd0ae449f","projectName":"Marechai","neverTrack":false} {"projectId":"9fc561fc-2850-4b18-8a34-33bab85e34e1","projectName":"Marechai"}