Add company editing in admin view.

This commit is contained in:
2020-05-27 21:24:53 +01:00
parent e68d4a3f05
commit 8879ba184e
9 changed files with 701 additions and 219 deletions

View File

@@ -1,154 +0,0 @@
@{
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Filename : Edit.cshtml
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Admin view edit
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2020 Natalia Portillo
*******************************************************************************/
}
@using Marechai.Database
@model Marechai.Database.Models.Company
@{
ViewData["Title"] = "Edit";
}
<h2>Edit</h2>
<h4>Company</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Edit">
<div asp-validation-summary="ModelOnly" class="text-danger">
</div>
<input type="hidden" asp-for="Id" />
<div class="form-group">
<label asp-for="Name" class="control-label">
</label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Founded" class="control-label">
</label>
<input asp-for="Founded" class="form-control" />
<span asp-validation-for="Founded" class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Website" class="control-label">
</label>
<input asp-for="Website" class="form-control" />
<span asp-validation-for="Website" class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Twitter" class="control-label">
</label>
<input asp-for="Twitter" class="form-control" />
<span asp-validation-for="Twitter" class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Facebook" class="control-label">
</label>
<input asp-for="Facebook" class="form-control" />
<span asp-validation-for="Facebook" class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Sold" class="control-label">
</label>
<input asp-for="Sold" class="form-control" />
<span asp-validation-for="Sold" class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="SoldTo" class="control-label">
</label>
<select asp-for="SoldToId" class="form-control" asp-items="ViewBag.SoldToId">
<option value="">None or unknown</option>
</select>
<span asp-validation-for="SoldToId" class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Address" class="control-label">
</label>
<input asp-for="Address" class="form-control" />
<span asp-validation-for="Address" class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="City" class="control-label">
</label>
<input asp-for="City" class="form-control" />
<span asp-validation-for="City" class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Province" class="control-label">
</label>
<input asp-for="Province" class="form-control" />
<span asp-validation-for="Province" class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="PostalCode" class="control-label">
</label>
<input asp-for="PostalCode" class="form-control" />
<span asp-validation-for="PostalCode" class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="CountryId" class="control-label">
</label>
<select asp-for="CountryId" class="form-control" asp-items="ViewBag.CountryId">
</select>
<span asp-validation-for="CountryId" class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Status" class="control-label">
</label>
<select asp-for="Status" class="form-control" asp-items="Html.GetEnumSelectList<CompanyStatus>().OrderBy(s => s.Text)">
</select>
<span asp-validation-for="Status" class="text-danger">
</span>
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" value="Save" />
<a asp-action="Index" class="btn btn-secondary">
Back to List
</a>
</div>
</form>
</div>
</div>
@section Scripts {
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
}

View File

@@ -90,9 +90,7 @@
</td>
<td>
<a class="btn btn-primary" href="/admin/companies/details/@item.Id">@L["Details"]</a>
<span class="btn btn-secondary">
@L["Edit"]
</span>
<a class="btn btn-primary" href="/admin/companies/edit/@item.Id">@L["Edit"]</a>
<Button Color="Color.Danger" Clicked="() => {ShowModal(item.Id);}">@L["Delete"]</Button>
</td>
</tr>

View File

@@ -31,10 +31,12 @@
}
@page "/admin/companies/details/{Id:int}"
@page "/admin/companies/edit/{Id:int}"
@using Marechai.Database
@inherits OwningComponentBase<CompaniesService>
@inject IStringLocalizer<CompaniesService> L
@inject Iso31661NumericService CountriesService
@inject NavigationManager NavigationManager
@attribute [Authorize(Roles = "UberAdmin, Admin")]
<h3>@L["Company details"]</h3>
<hr />
@@ -49,106 +51,264 @@
<div>
<Field>
<FieldLabel>@L["Name"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.Name"/>
<Validation Validator="@ValidateName">
<TextEdit ReadOnly="!_editing" @bind-Text="@_model.Name">
<Feedback>
<ValidationError>@L["Please enter a valid name."]</ValidationError>
</Feedback>
</TextEdit>
</Validation>
</Field>
<Field>
<FieldLabel>@L["Status"]</FieldLabel>
<Select Disabled="!_editable" TValue="int" @bind-SelectedValue="@Status">
<Select Disabled="!_editing" TValue="int" @bind-SelectedValue="@Status">
@foreach (int status in Enum.GetValues(typeof(CompanyStatus)))
{
<SelectItem TValue="int" Value="@status">@(((CompanyStatus)status).ToString())</SelectItem>
}
</Select>
</Field>
@if(_editable || _model.Founded.HasValue)
@if (_editing || _model.Founded != null)
{
<Field>
<FieldLabel>@L["Founded"]</FieldLabel>
<DateEdit ReadOnly="!_editable" TValue="DateTime?" @bind-Date="@_model.Founded"/>
@if (_editing)
{
<Check TValue="bool" @bind-Checked="@_unknownFounded">@L["Unknown (foundation date)"]</Check>
}
@if (!_editing || !_unknownFounded)
{
<Validation Validator="@ValidateFounded">
<DateEdit TValue="DateTime?" ReadOnly="!_editing" @bind-Text="@_model.Founded" >
<Feedback>
<ValidationError>@L["Please enter a valid foundation date."]</ValidationError>
</Feedback>
</DateEdit>
</Validation>
}
</Field>
}
@if (_editable || _model.Website != null)
@if (_editing || _model.Website != null)
{
<Field>
<FieldLabel>@L["Website"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.Website" />
@if (_editing)
{
<Check TValue="bool" @bind-Checked="@_unknownWebsite">@L["Unknown (website)"]</Check>
}
@if (!_editing ||
!_unknownWebsite)
{
<Validation Validator="@ValidateWebsite">
<TextEdit ReadOnly="!_editing" @bind-Text="@_model.Website">
<Feedback>
<ValidationError>@L["Please enter a valid website."]</ValidationError>
</Feedback>
</TextEdit>
</Validation>
}
</Field>
}
@if (_editable || _model.Twitter != null)
@if (_editing || _model.Twitter != null)
{
<Field>
<FieldLabel>@L["Twitter"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.Twitter" />
@if (_editing)
{
<Check TValue="bool" @bind-Checked="@_unknownTwitter">@L["Unknown (twitter)"]</Check>
}
@if (!_editing ||
!_unknownTwitter)
{
<Validation Validator="@ValidateTwitter">
<TextEdit ReadOnly="!_editing" @bind-Text="@_model.Twitter">
<Feedback>
<ValidationError>@L["Please enter a valid Twitter handle."]</ValidationError>
</Feedback>
</TextEdit>
</Validation>
}
</Field>
}
@if (_editable || _model.Facebook != null)
@if (_editing || _model.Facebook != null)
{
<Field>
<FieldLabel>@L["Facebook"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.Facebook" />
<TextEdit ReadOnly="!_editing" @bind-Text="@_model.Facebook" />
@if (_editing)
{
<Check TValue="bool" @bind-Checked="@_unknownFacebook">@L["Unknown (facebook)"]</Check>
}
@if (!_editing ||
!_unknownFacebook)
{
<Validation Validator="@ValidateFacebook">
<TextEdit ReadOnly="!_editing" @bind-Text="@_model.Facebook">
<Feedback>
<ValidationError>@L["Please enter a valid Facebook user name."]</ValidationError>
</Feedback>
</TextEdit>
</Validation>
}
</Field>
}
@if (_editable || _model.Address != null)
@if (_editing || _model.Address != null)
{
<Field>
<FieldLabel>@L["Address"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.Address" />
@if (_editing)
{
<Check TValue="bool" @bind-Checked="@_unknownAddress">@L["Unknown (address)"]</Check>
}
@if (!_editing ||
!_unknownAddress)
{
<Validation Validator="@ValidateAddress">
<TextEdit ReadOnly="!_editing" @bind-Text="@_model.Address">
<Feedback>
<ValidationError>@L["Please enter a valid address."]</ValidationError>
</Feedback>
</TextEdit>
</Validation>
}
</Field>
}
@if (_editable || _model.City != null)
@if (_editing || _model.Address != null)
{
<Field>
<FieldLabel>@L["City"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.City" />
@if (_editing)
{
<Check TValue="bool" @bind-Checked="@_unknownCity">@L["Unknown (city)"]</Check>
}
@if (!_editing ||
!_unknownCity)
{
<Validation Validator="@ValidateCity">
<TextEdit ReadOnly="!_editing" @bind-Text="@_model.City">
<Feedback>
<ValidationError>@L["Please enter a valid city."]</ValidationError>
</Feedback>
</TextEdit>
</Validation>
}
</Field>
}
@if (_editable || _model.Province != null)
@if (_editing || _model.Province != null)
{
<Field>
<FieldLabel>@L["Province"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.Province" />
@if (_editing)
{
<Check TValue="bool" @bind-Checked="@_unknownProvince">@L["Unknown (province)"]</Check>
}
@if (!_editing ||
!_unknownProvince)
{
<Validation Validator="@ValidateProvince">
<TextEdit ReadOnly="!_editing" @bind-Text="@_model.Province">
<Feedback>
<ValidationError>@L["Please enter a valid province."]</ValidationError>
</Feedback>
</TextEdit>
</Validation>
}
</Field>
}
@if (_editable || _model.PostalCode != null)
@if (_editing || _model.Address != null)
{
<Field>
<FieldLabel>@L["Postal code"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.PostalCode" />
@if (_editing)
{
<Check TValue="bool" @bind-Checked="@_unknownPostalCode">@L["Unknown (postal code)"]</Check>
}
@if (!_editing ||
!_unknownPostalCode)
{
<Validation Validator="@ValidatePostalCode">
<TextEdit ReadOnly="!_editing" @bind-Text="@_model.PostalCode">
<Feedback>
<ValidationError>@L["Please enter a valid postal code."]</ValidationError>
</Feedback>
</TextEdit>
</Validation>
}
</Field>
}
@if (_editable || _model.CountryId != null)
@if (_editing || _model.CountryId != null)
{
<Field>
<FieldLabel>@L["Country"]</FieldLabel>
<Select Disabled="!_editable" TValue="short?" @bind-SelectedValue="@_model.CountryId">
@foreach (var country in _countries)
{
<SelectItem TValue="short?" Value="@country.Id">@country.Name</SelectItem>
}
</Select>
@if (_editing)
{
<Check TValue="bool" @bind-Checked="@_unknownCountry">@L["Unknown (country)"]</Check>
}
@if (!_editing ||
!_unknownCountry)
{
<Select Disabled="!_editing" TValue="short?" @bind-SelectedValue="@_model.CountryId">
@foreach (var country in _countries)
{
<SelectItem TValue="short?" Value="@country.Id">@country.Name</SelectItem>
}
</Select>
}
</Field>
}
@if (_editable || _model.Sold != null)
@if (((int)_model.Status) > 1)
{
<Field>
<FieldLabel>@L["Sold"]</FieldLabel>
<DateEdit ReadOnly="!_editable" TValue="DateTime?" @bind-Date="@_model.Sold" />
</Field>
}
@if (_editable || _model.SoldToId != null)
{
<Field>
<FieldLabel>@L["Sold to"]</FieldLabel>
<Select Disabled="!_editable" TValue="int?" @bind-SelectedValue="@_model.SoldToId">
@foreach (var company in _companies)
@if (_editing || _model.Sold != null)
{
<Field>
<FieldLabel>@L["Sold"]</FieldLabel>
@if (_editing)
{
<SelectItem TValue="int?" Value="@company.Id">@company.Name</SelectItem>
<Check TValue="bool" @ bind-Checked="@_unknownSold">@L["Unknown (sold/merged/bankrupt date)"]</Check>
}
</Select>
</Field>
@if (!_editing ||
!_unknownSold)
{
<Validation Validator="@ValidateSold">
<DateEdit TValue="DateTime?" ReadOnly="!_editing" @ bind-Text="@_model.Sold">
<Feedback>
<ValidationError>@L["Please enter a valid sold/merge/bankruptcy date."]</ValidationError>
</Feedback>
</DateEdit>
</Validation>
}
</Field>
}
@if (_editing || _model.SoldToId != null)
{
<Field>
<FieldLabel>@L["Sold to"]</FieldLabel>
@if (_editing)
{
<Check TValue="bool" @ bind-Checked="@_unknownSoldTo">@L["Unknown (sold to)"]</Check>
}
@if (!_editing ||
!_unknownSoldTo)
{
<Select Disabled="!_editing" TValue="int?" @ bind-SelectedValue="@_model.SoldToId">
@foreach (var company in _companies)
{
<SelectItem TValue="short?" Value="@company.Id">@company.Name</SelectItem>
}
</Select>
}
</Field>
}
}
</div>
<div>
<span class="btn btn-primary">@L["Edit"]</span>
@if (!_editing)
{
<Button Color="Color.Primary" Clicked="@OnEditClicked">@L["Edit"]</Button>
}
else
{
<Button Color="Color.Success" Clicked="@OnSaveClicked">@L["Save"]</Button>
<Button Color="Color.Danger" Clicked="@OnCancelClicked">@L["Cancel"]</Button>
}
<a href="/admin/companies" class="btn btn-secondary">@L["Back to list"]</a>
</div>

View File

@@ -1,7 +1,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Blazorise;
using Marechai.Database;
using Marechai.Database.Models;
using Marechai.Shared;
using Marechai.ViewModels;
using Microsoft.AspNetCore.Components;
@@ -9,11 +12,22 @@ namespace Marechai.Pages.Admin.Details
{
public partial class Company
{
List<CompanyViewModel> _companies;
List<Iso31661Numeric> _countries;
bool _editable;
bool _loaded;
Database.Models.Company _model;
List<CompanyViewModel> _companies;
List<Iso31661Numeric> _countries;
bool _editing;
bool _loaded;
CompanyViewModel _model;
bool _unknownAddress;
bool _unknownCity;
bool _unknownCountry;
bool _unknownFacebook;
bool _unknownFounded;
bool _unknownPostalCode;
bool _unknownProvince;
bool _unknownSold;
bool _unknownSoldTo;
bool _unknownTwitter;
bool _unknownWebsite;
[Parameter]
public int Id { get; set; }
@@ -37,7 +51,165 @@ namespace Marechai.Pages.Admin.Details
_companies = await Service.GetAsync();
_model = await Service.GetAsync(Id);
_editing = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
StartsWith("admin/companies/edit/", StringComparison.InvariantCulture);
if(_editing)
SetCheckboxes();
StateHasChanged();
}
void SetCheckboxes()
{
_unknownWebsite = string.IsNullOrWhiteSpace(_model.Website);
_unknownCountry = !_model.CountryId.HasValue;
_unknownFounded = !_model.Founded.HasValue;
_unknownAddress = string.IsNullOrWhiteSpace(_model.Address);
_unknownFacebook = string.IsNullOrWhiteSpace(_model.Facebook);
_unknownCity = string.IsNullOrWhiteSpace(_model.City);
_unknownProvince = string.IsNullOrWhiteSpace(_model.Province);
_unknownTwitter = string.IsNullOrWhiteSpace(_model.Twitter);
_unknownPostalCode = string.IsNullOrWhiteSpace(_model.PostalCode);
_unknownSold = !_model.Sold.HasValue;
_unknownSoldTo = !_model.SoldToId.HasValue;
}
void OnEditClicked()
{
_editing = true;
SetCheckboxes();
StateHasChanged();
}
async void OnCancelClicked()
{
_editing = false;
_model = await Service.GetAsync(Id);
SetCheckboxes();
StateHasChanged();
}
async void OnSaveClicked()
{
if(_unknownWebsite)
_model.Website = null;
else if(string.IsNullOrWhiteSpace(_model.Website))
return;
if(_unknownCountry)
_model.CountryId = null;
else if(_model.CountryId < 0)
return;
if(_unknownFounded)
_model.Founded = null;
else if(_model.Founded?.Date >= DateTime.UtcNow.Date)
return;
if(_unknownAddress)
_model.Address = null;
else if(string.IsNullOrWhiteSpace(_model.Address))
return;
if(_unknownFacebook)
_model.Facebook = null;
else if(string.IsNullOrWhiteSpace(_model.Facebook))
return;
if(_unknownFacebook)
_model.Facebook = null;
else if(string.IsNullOrWhiteSpace(_model.Facebook))
return;
if(_unknownCity)
_model.City = null;
else if(string.IsNullOrWhiteSpace(_model.City))
return;
if(string.IsNullOrWhiteSpace(_model.Name))
return;
if(_unknownProvince)
_model.Province = null;
else if(string.IsNullOrWhiteSpace(_model.Province))
return;
if(_unknownTwitter)
_model.Twitter = null;
else if(string.IsNullOrWhiteSpace(_model.Twitter))
return;
if(_unknownPostalCode)
_model.PostalCode = null;
else if(string.IsNullOrWhiteSpace(_model.PostalCode))
return;
if(_unknownSoldTo)
_model.SoldToId = null;
else if(_model.SoldToId < 0)
return;
if(_unknownSold)
_model.Sold = null;
else if(_model.Sold?.Date >= DateTime.UtcNow.Date)
return;
_editing = false;
await Service.UpdateAsync(_model);
_model = await Service.GetAsync(Id);
SetCheckboxes();
StateHasChanged();
}
void ValidateName(ValidatorEventArgs e) =>
Validators.ValidateString(e, L["Name must be smaller than 256 characters."], 256);
void ValidateFounded(ValidatorEventArgs e) => Validators.ValidateDate(e);
void ValidateAddress(ValidatorEventArgs e) =>
Validators.ValidateString(e, L["Address must be smaller than 80 characters."], 80);
void ValidateCity(ValidatorEventArgs e) =>
Validators.ValidateString(e, L["City name must be smaller than 80 characters."], 80);
void ValidateProvince(ValidatorEventArgs e) =>
Validators.ValidateString(e, L["Province name must be smaller than 80 characters."], 80);
void ValidatePostalCode(ValidatorEventArgs e) =>
Validators.ValidateString(e, L["Postal code name must be smaller than 25 characters."], 25);
void ValidateSold(ValidatorEventArgs e) => Validators.ValidateDate(e);
void ValidateWebsite(ValidatorEventArgs e) =>
Validators.ValidateUrl(e, L["Webpage must be smaller than 255 characters."], 255);
void ValidateTwitter(ValidatorEventArgs e)
{
if(!(e.Value is string twitter))
{
e.Status = ValidationStatus.Error;
return;
}
if(twitter.Length < 1 ||
twitter.Length > 255)
{
e.ErrorText = L["Twitter handle must be smaller than 255 characters."];
e.Status = ValidationStatus.Error;
return;
}
if(twitter[0] == '@')
return;
e.ErrorText = L["Invalid Twitter handle."];
e.Status = ValidationStatus.Error;
}
void ValidateFacebook(ValidatorEventArgs e) =>
Validators.ValidateString(e, L["Facebook username must be smaller than 256 characters."], 256);
}
}

View File

@@ -0,0 +1,165 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- ReSharper disable MarkupTextTypo -->
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Unknown (country)" xml:space="preserve">
<value>Unknown</value>
<comment>Unknown, referring to a country</comment>
</data>
<data name="Unknown (foundation date)" xml:space="preserve">
<value>Unknown</value>
<comment>Unknown, referring to the foundation date</comment>
</data>
<data name="Unknown (website)" xml:space="preserve">
<value>Unknown</value>
<comment>Unknown, referring to a website</comment>
</data>
<data name="Unknown (twitter)" xml:space="preserve">
<value>Unknown</value>
<comment>Unknown, referring to a twitter handle</comment>
</data>
<data name="Unknown (facebook)" xml:space="preserve">
<value>Unknown</value>
<comment>Unknown, referring to a facebook username</comment>
</data>
<data name="Unknown (address)" xml:space="preserve">
<value>Unknown</value>
<comment>Unknown, referring to a postal address</comment>
</data>
<data name="Unknown (city)" xml:space="preserve">
<value>Unknown</value>
<comment>Unknown, referring to a city</comment>
</data>
<data name="Unknown (province)" xml:space="preserve">
<value>Unknown</value>
<comment>Unknown, referring to a province</comment>
</data>
<data name="Unknown (postal code)" xml:space="preserve">
<value>Unknown</value>
<comment>Unknown, referring to a postal code</comment>
</data>
<data name="Unknown (sold/merged/bankrupt date)" xml:space="preserve">
<value>Unknown</value>
<comment>Unknown, referring to the date when the company was sold, merged, bankrupted, or renamed</comment>
</data>
<data name="Unknown (sold to)" xml:space="preserve">
<value>Unknown</value>
<comment>Unknown, referring to another company name</comment>
</data>
</root>

View File

@@ -314,4 +314,92 @@
<value>Volver a la lista</value>
<comment>Back to list</comment>
</data>
<data name="Save" xml:space="preserve">
<value>Guardar</value>
<comment>Save</comment>
</data>
<data name="Unknown (country)" xml:space="preserve">
<value>Desconocido</value>
<comment>Unknown, referring to a country</comment>
</data>
<data name="Unknown (foundation date)" xml:space="preserve">
<value>Desconocida</value>
<comment>Unknown, referring to the foundation date</comment>
</data>
<data name="Unknown (website)" xml:space="preserve">
<value>Desconocida</value>
<comment>Unknown, referring to a website</comment>
</data>
<data name="Unknown (twitter)" xml:space="preserve">
<value>Desconocido</value>
<comment>Unknown, referring to a twitter handle</comment>
</data>
<data name="Unknown (facebook)" xml:space="preserve">
<value>Desconocido</value>
<comment>Unknown, referring to a facebook username</comment>
</data>
<data name="Unknown (address)" xml:space="preserve">
<value>Desconocida</value>
<comment>Unknown, referring to a postal address</comment>
</data>
<data name="Unknown (city)" xml:space="preserve">
<value>Desconocida</value>
<comment>Unknown, referring to a city</comment>
</data>
<data name="Unknown (province)" xml:space="preserve">
<value>Desconocida</value>
<comment>Unknown, referring to a province</comment>
</data>
<data name="Unknown (postal code)" xml:space="preserve">
<value>Desconocido</value>
<comment>Unknown, referring to a postal code</comment>
</data>
<data name="Unknown (sold/merged/bankrupt date)" xml:space="preserve">
<value>Desconocida</value>
<comment>Unknown, referring to the date when the company was sold, merged, bankrupted, or renamed</comment>
</data>
<data name="Unknown (sold to)" xml:space="preserve">
<value>Desconocida</value>
<comment>Unknown, referring to another company name</comment>
</data>
<data name="Please enter a valid name." xml:space="preserve">
<value>Por favor introduce un nombre válido.</value>
<comment>Please enter a valid name.</comment>
</data>
<data name="Please enter a valid foundation date." xml:space="preserve">
<value>Por favor introduce una fecha de fundación válida.</value>
<comment>Please enter a valid foundation date.</comment>
</data>
<data name="Please enter a valid website." xml:space="preserve">
<value>Por favor introduce una página web válida.</value>
<comment>Please enter a valid website.</comment>
</data>
<data name="Please enter a valid Twitter handle." xml:space="preserve">
<value>Por favor introduce un indicador de Twitter válido.</value>
<comment>Please enter a valid Twitter handle.</comment>
</data>
<data name="Please enter a valid Facebook user name." xml:space="preserve">
<value>Por favor introduce un nombre de usuario de Facebook válido.</value>
<comment>Please enter a valid Facebook user name.</comment>
</data>
<data name="Please enter a valid address." xml:space="preserve">
<value>Por favor introduce una dirección válida.</value>
<comment>Please enter a valid address.</comment>
</data>
<data name="Please enter a valid city." xml:space="preserve">
<value>Por favor introduce una ciudad válida.</value>
<comment>Please enter a valid city.</comment>
</data>
<data name="Please enter a valid province." xml:space="preserve">
<value>Por favor introduce una provincia válida.</value>
<comment>Please enter a valid province.</comment>
</data>
<data name="Please enter a valid postal code." xml:space="preserve">
<value>Por favor introduce un código postal válido.</value>
<comment>Please enter a valid postal code.</comment>
</data>
<data name="Please enter a valid sold/merge/bankruptcy date." xml:space="preserve">
<value>Por favor introduce una fecha de venta, fusión, bancarrota o renombre válida.</value>
<comment>Please enter a valid sold/merge/bankruptcy date.</comment>
</data>
</root>

View File

@@ -57,12 +57,50 @@ namespace Marechai.Services
LastLogo = c.
Logos.OrderByDescending(l => l.Year).
FirstOrDefault().Guid,
Name = c.Name, Founded = c.Founded, Sold = c.Sold,
SoldTo = c.SoldTo.Name, Country = c.Country.Name,
Status = c.Status
Name = c.Name, Founded = c.Founded, Sold = c.Sold,
SoldToId = c.SoldToId, CountryId = c.CountryId,
Status = c.Status, Website = c.Website,
Twitter = c.Twitter, Facebook = c.Facebook,
Address = c.Address, City = c.City, Province = c.Province,
PostalCode = c.PostalCode, Country = c.Country.Name
}).ToListAsync();
public Task<Company> GetAsync(int id) => _context.Companies.FirstOrDefaultAsync(c => c.Id == id);
public Task<CompanyViewModel> GetAsync(int id) => _context.Companies.Where(c => c.Id == id).
Select(c => new CompanyViewModel
{
Id = c.Id, Name = c.Name, Founded = c.Founded,
Sold = c.Sold, SoldToId = c.SoldToId,
CountryId = c.CountryId, Status = c.Status,
Website = c.Website, Twitter = c.Twitter,
Facebook = c.Facebook, Address = c.Address,
City = c.City, Province = c.Province,
PostalCode = c.PostalCode,
Country = c.Country.Name
}).FirstOrDefaultAsync();
public async Task UpdateAsync(CompanyViewModel viewModel)
{
Company model = await _context.Companies.FindAsync(viewModel.Id);
if(model is null)
return;
model.Name = viewModel.Name;
model.Founded = viewModel.Founded;
model.Sold = viewModel.Sold;
model.SoldToId = viewModel.SoldToId;
model.CountryId = viewModel.CountryId;
model.Status = viewModel.Status;
model.Website = viewModel.Website;
model.Twitter = viewModel.Twitter;
model.Facebook = viewModel.Facebook;
model.Address = viewModel.Address;
model.City = viewModel.City;
model.Province = viewModel.Province;
model.PostalCode = viewModel.PostalCode;
await _context.SaveChangesAsync();
}
public async Task<List<Machine>> GetMachinesAsync(int id) =>
await _context.Machines.Where(m => m.CompanyId == id).OrderBy(m => m.Name).Select(m => new Machine

View File

@@ -99,5 +99,14 @@ namespace Marechai.Shared
e.Status = ValidationStatus.Error;
}
public static void ValidateDate(ValidatorEventArgs e)
{
if(!(e.Value is DateTime item) ||
item.Date >= DateTime.UtcNow.Date)
e.Status = ValidationStatus.Error;
else
e.Status = ValidationStatus.Success;
}
}
}

View File

@@ -5,19 +5,25 @@ namespace Marechai.ViewModels
{
public class CompanyViewModel : BaseViewModel<int>
{
public Guid? LastLogo { get; set; }
public string Name { get; set; }
public DateTime? Founded { get; set; }
public DateTime? Sold { get; set; }
public string SoldTo { get; set; }
public string Country { get; set; }
public CompanyStatus Status { get; set; }
public string Name { get; set; }
public DateTime? Founded { get; set; }
public string Website { get; set; }
public string Twitter { get; set; }
public string Facebook { get; set; }
public DateTime? Sold { get; set; }
public int? SoldToId { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string Province { get; set; }
public string PostalCode { get; set; }
public short? CountryId { get; set; }
public CompanyStatus Status { get; set; }
public Guid? LastLogo { get; set; }
public string SoldTo { get; set; }
public string Country { get; set; }
public string SoldView => Status != CompanyStatus.Active && Status != CompanyStatus.Unknown
? Sold?.ToShortDateString() ?? "Unknown"
: Sold?.ToShortDateString() ?? (SoldTo is null
? ""
: "Unknown");
: Sold?.ToShortDateString() ?? (SoldTo is null ? "" : "Unknown");
}
}