mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Optimize view of company admin page.
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Cicm.Database.Models;
|
||||
using cicm_web.Areas.Admin.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
@@ -55,7 +56,16 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
{
|
||||
IIncludableQueryable<Company, Company> cicmContext =
|
||||
_context.Companies.Include(c => c.Country).Include(c => c.SoldTo);
|
||||
return View(await cicmContext.OrderBy(c => c.Name).ToListAsync());
|
||||
return View(cicmContext.OrderBy(c => c.Name).Select(c => new CompanyViewModel
|
||||
{
|
||||
Id = c.Id,
|
||||
Name = c.Name,
|
||||
Founded = c.Founded,
|
||||
Status = c.Status,
|
||||
Country = c.Country.Name,
|
||||
Sold = c.Sold,
|
||||
SoldTo = c.SoldTo.Name
|
||||
}));
|
||||
}
|
||||
|
||||
// GET: Admin/Companies/Details/5
|
||||
@@ -95,8 +105,10 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
ViewData["CountryId"] = new SelectList(_context.Iso31661Numeric.OrderBy(c => c.Name), "Id", "Name", company.CountryId);
|
||||
ViewData["SoldToId"] = new SelectList(_context.Companies.OrderBy(c => c.Name), "Id", "Name", company.SoldToId);
|
||||
ViewData["CountryId"] =
|
||||
new SelectList(_context.Iso31661Numeric.OrderBy(c => c.Name), "Id", "Name", company.CountryId);
|
||||
ViewData["SoldToId"] =
|
||||
new SelectList(_context.Companies.OrderBy(c => c.Name), "Id", "Name", company.SoldToId);
|
||||
return View(company);
|
||||
}
|
||||
|
||||
@@ -108,8 +120,10 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
Company company = await _context.Companies.FindAsync(id);
|
||||
if(company == null) return NotFound();
|
||||
|
||||
ViewData["CountryId"] = new SelectList(_context.Iso31661Numeric.OrderBy(c => c.Name), "Id", "Name", company.CountryId);
|
||||
ViewData["SoldToId"] = new SelectList(_context.Companies.OrderBy(c => c.Name), "Id", "Name", company.SoldToId);
|
||||
ViewData["CountryId"] =
|
||||
new SelectList(_context.Iso31661Numeric.OrderBy(c => c.Name), "Id", "Name", company.CountryId);
|
||||
ViewData["SoldToId"] =
|
||||
new SelectList(_context.Companies.OrderBy(c => c.Name), "Id", "Name", company.SoldToId);
|
||||
return View(company);
|
||||
}
|
||||
|
||||
@@ -142,8 +156,10 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
ViewData["CountryId"] = new SelectList(_context.Iso31661Numeric.OrderBy(c => c.Name), "Id", "Name", company.CountryId);
|
||||
ViewData["SoldToId"] = new SelectList(_context.Companies.OrderBy(c => c.Name), "Id", "Name", company.SoldToId);
|
||||
ViewData["CountryId"] =
|
||||
new SelectList(_context.Iso31661Numeric.OrderBy(c => c.Name), "Id", "Name", company.CountryId);
|
||||
ViewData["SoldToId"] =
|
||||
new SelectList(_context.Companies.OrderBy(c => c.Name), "Id", "Name", company.SoldToId);
|
||||
return View(company);
|
||||
}
|
||||
|
||||
|
||||
37
cicm_web/Areas/Admin/Models/CompanyViewModel.cs
Normal file
37
cicm_web/Areas/Admin/Models/CompanyViewModel.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Cicm.Database;
|
||||
|
||||
namespace cicm_web.Areas.Admin.Models
|
||||
{
|
||||
public class CompanyViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
[DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
|
||||
[DataType(DataType.Date)]
|
||||
public DateTime? Founded { get; set; }
|
||||
[DisplayFormat(DataFormatString = "{0:d}")]
|
||||
[DataType(DataType.Date)]
|
||||
public DateTime? Sold { get; set; }
|
||||
public string SoldTo { get; set; }
|
||||
public string Country { get; set; }
|
||||
[Required]
|
||||
public CompanyStatus Status { get; set; }
|
||||
|
||||
[DisplayName("Sold")]
|
||||
[NotMapped]
|
||||
public string SoldView =>
|
||||
Status != CompanyStatus.Active && Status != CompanyStatus.Unknown
|
||||
? Sold is null
|
||||
? "Unknown"
|
||||
: Sold.Value.ToShortDateString()
|
||||
: Sold is null
|
||||
? SoldTo is null
|
||||
? ""
|
||||
: "Unknown"
|
||||
: Sold.Value.ToShortDateString();
|
||||
}
|
||||
}
|
||||
@@ -29,8 +29,8 @@
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
}
|
||||
@using Cicm.Database.Models
|
||||
@model IEnumerable<Cicm.Database.Models.Company>
|
||||
@using cicm_web.Areas.Admin.Models
|
||||
@model IEnumerable<cicm_web.Areas.Admin.Models.CompanyViewModel>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Companies (Admin)";
|
||||
@@ -69,7 +69,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach(Company item in Model)
|
||||
@foreach(CompanyViewModel item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@@ -82,13 +82,13 @@
|
||||
@Html.DisplayFor(modelItem => item.Status)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Country.Name)
|
||||
@Html.DisplayFor(modelItem => item.Country)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.SoldView)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.SoldTo.Name)
|
||||
@Html.DisplayFor(modelItem => item.SoldTo)
|
||||
</td>
|
||||
<td>
|
||||
<a asp-action="Details"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<Version>3.0.99.533</Version>
|
||||
<Version>3.0.99.535</Version>
|
||||
<Company>Canary Islands Computer Museum</Company>
|
||||
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
||||
<Product>Canary Islands Computer Museum Website</Product>
|
||||
|
||||
Reference in New Issue
Block a user