mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add CRUD pages for document companies.
This commit is contained in:
123
cicm_web/Areas/Admin/Controllers/DocumentCompaniesController.cs
Normal file
123
cicm_web/Areas/Admin/Controllers/DocumentCompaniesController.cs
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Cicm.Database.Models;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace cicm_web.Areas.Admin.Controllers
|
||||||
|
{
|
||||||
|
[Area("Admin")]
|
||||||
|
[Authorize]
|
||||||
|
public class DocumentCompaniesController : Controller
|
||||||
|
{
|
||||||
|
readonly cicmContext _context;
|
||||||
|
|
||||||
|
public DocumentCompaniesController(cicmContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: DocumentCompanies
|
||||||
|
public async Task<IActionResult> Index() => View(await _context.DocumentCompanies.ToListAsync());
|
||||||
|
|
||||||
|
// GET: DocumentCompanies/Details/5
|
||||||
|
public async Task<IActionResult> Details(int? id)
|
||||||
|
{
|
||||||
|
if(id == null) return NotFound();
|
||||||
|
|
||||||
|
DocumentCompany documentCompany = await _context.DocumentCompanies.FirstOrDefaultAsync(m => m.Id == id);
|
||||||
|
if(documentCompany == null) return NotFound();
|
||||||
|
|
||||||
|
return View(documentCompany);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: DocumentCompanies/Create
|
||||||
|
public IActionResult Create() => View();
|
||||||
|
|
||||||
|
// POST: DocumentCompanies/Create
|
||||||
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
||||||
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||||
|
[HttpPost]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> Create([Bind("Name,CompanyId,Id")] DocumentCompany documentCompany)
|
||||||
|
{
|
||||||
|
if(ModelState.IsValid)
|
||||||
|
{
|
||||||
|
_context.Add(documentCompany);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
|
||||||
|
return View(documentCompany);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: DocumentCompanies/Edit/5
|
||||||
|
public async Task<IActionResult> Edit(int? id)
|
||||||
|
{
|
||||||
|
if(id == null) return NotFound();
|
||||||
|
|
||||||
|
DocumentCompany documentCompany = await _context.DocumentCompanies.FindAsync(id);
|
||||||
|
if(documentCompany == null) return NotFound();
|
||||||
|
|
||||||
|
return View(documentCompany);
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: DocumentCompanies/Edit/5
|
||||||
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
||||||
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||||
|
[HttpPost]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> Edit(int id, [Bind("Name,CompanyId,Id")] DocumentCompany documentCompany)
|
||||||
|
{
|
||||||
|
if(id != documentCompany.Id) return NotFound();
|
||||||
|
|
||||||
|
if(ModelState.IsValid)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_context.Update(documentCompany);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch(DbUpdateConcurrencyException)
|
||||||
|
{
|
||||||
|
if(!DocumentCompanyExists(documentCompany.Id)) return NotFound();
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
|
||||||
|
return View(documentCompany);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: DocumentCompanies/Delete/5
|
||||||
|
public async Task<IActionResult> Delete(int? id)
|
||||||
|
{
|
||||||
|
if(id == null) return NotFound();
|
||||||
|
|
||||||
|
DocumentCompany documentCompany = await _context.DocumentCompanies.FirstOrDefaultAsync(m => m.Id == id);
|
||||||
|
if(documentCompany == null) return NotFound();
|
||||||
|
|
||||||
|
return View(documentCompany);
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: DocumentCompanies/Delete/5
|
||||||
|
[HttpPost]
|
||||||
|
[ActionName("Delete")]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> DeleteConfirmed(int id)
|
||||||
|
{
|
||||||
|
DocumentCompany documentCompany = await _context.DocumentCompanies.FindAsync(id);
|
||||||
|
_context.DocumentCompanies.Remove(documentCompany);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DocumentCompanyExists(int id)
|
||||||
|
{
|
||||||
|
return _context.DocumentCompanies.Any(e => e.Id == id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
48
cicm_web/Areas/Admin/Views/DocumentCompanies/Create.cshtml
Normal file
48
cicm_web/Areas/Admin/Views/DocumentCompanies/Create.cshtml
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
@model Cicm.Database.Models.DocumentCompany
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Create";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>Create</h1>
|
||||||
|
|
||||||
|
<h4>DocumentCompany</h4>
|
||||||
|
<hr />
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<form asp-action="Create">
|
||||||
|
<div asp-validation-summary="ModelOnly"
|
||||||
|
class="text-danger">
|
||||||
|
</div>
|
||||||
|
<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="CompanyId"
|
||||||
|
class="control-label">
|
||||||
|
</label>
|
||||||
|
<input asp-for="CompanyId"
|
||||||
|
class="form-control" />
|
||||||
|
<span asp-validation-for="CompanyId"
|
||||||
|
class="text-danger">
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<input class="btn btn-primary"
|
||||||
|
type="submit"
|
||||||
|
value="Create" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<a asp-action="Index">Back to List</a>
|
||||||
|
</div>
|
||||||
36
cicm_web/Areas/Admin/Views/DocumentCompanies/Delete.cshtml
Normal file
36
cicm_web/Areas/Admin/Views/DocumentCompanies/Delete.cshtml
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
@model Cicm.Database.Models.DocumentCompany
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Delete";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>Delete</h1>
|
||||||
|
|
||||||
|
<h3>Are you sure you want to delete this?</h3>
|
||||||
|
<div>
|
||||||
|
<h4>DocumentCompany</h4>
|
||||||
|
<hr />
|
||||||
|
<dl class="row">
|
||||||
|
<dt class="col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.Name)
|
||||||
|
</dt>
|
||||||
|
<dd class="col-sm-10">
|
||||||
|
@Html.DisplayFor(model => model.Name)
|
||||||
|
</dd>
|
||||||
|
<dt class="col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.CompanyId)
|
||||||
|
</dt>
|
||||||
|
<dd class="col-sm-10">
|
||||||
|
@Html.DisplayFor(model => model.CompanyId)
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<form asp-action="Delete">
|
||||||
|
<input type="hidden"
|
||||||
|
asp-for="Id" />
|
||||||
|
<input class="btn btn-danger"
|
||||||
|
type="submit"
|
||||||
|
value="Delete" /> |
|
||||||
|
<a asp-action="Index">Back to List</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
33
cicm_web/Areas/Admin/Views/DocumentCompanies/Details.cshtml
Normal file
33
cicm_web/Areas/Admin/Views/DocumentCompanies/Details.cshtml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
@model Cicm.Database.Models.DocumentCompany
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Details";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>Details</h1>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h4>DocumentCompany</h4>
|
||||||
|
<hr />
|
||||||
|
<dl class="row">
|
||||||
|
<dt class="col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.Name)
|
||||||
|
</dt>
|
||||||
|
<dd class="col-sm-10">
|
||||||
|
@Html.DisplayFor(model => model.Name)
|
||||||
|
</dd>
|
||||||
|
<dt class="col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.CompanyId)
|
||||||
|
</dt>
|
||||||
|
<dd class="col-sm-10">
|
||||||
|
@Html.DisplayFor(model => model.CompanyId)
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<a asp-action="Edit"
|
||||||
|
asp-route-id="@Model.Id">
|
||||||
|
Edit
|
||||||
|
</a> |
|
||||||
|
<a asp-action="Index">Back to List</a>
|
||||||
|
</div>
|
||||||
50
cicm_web/Areas/Admin/Views/DocumentCompanies/Edit.cshtml
Normal file
50
cicm_web/Areas/Admin/Views/DocumentCompanies/Edit.cshtml
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
@model Cicm.Database.Models.DocumentCompany
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Edit";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>Edit</h1>
|
||||||
|
|
||||||
|
<h4>DocumentCompany</h4>
|
||||||
|
<hr />
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<form asp-action="Edit">
|
||||||
|
<div asp-validation-summary="ModelOnly"
|
||||||
|
class="text-danger">
|
||||||
|
</div>
|
||||||
|
<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="CompanyId"
|
||||||
|
class="control-label">
|
||||||
|
</label>
|
||||||
|
<input asp-for="CompanyId"
|
||||||
|
class="form-control" />
|
||||||
|
<span asp-validation-for="CompanyId"
|
||||||
|
class="text-danger">
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<input type="hidden"
|
||||||
|
asp-for="Id" />
|
||||||
|
<div class="form-group">
|
||||||
|
<input class="btn btn-primary"
|
||||||
|
type="submit"
|
||||||
|
value="Save" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<a asp-action="Index">Back to List</a>
|
||||||
|
</div>
|
||||||
52
cicm_web/Areas/Admin/Views/DocumentCompanies/Index.cshtml
Normal file
52
cicm_web/Areas/Admin/Views/DocumentCompanies/Index.cshtml
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
@using Cicm.Database.Models
|
||||||
|
@model IEnumerable<Cicm.Database.Models.DocumentCompany>
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Index";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>Index</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<a asp-action="Create">Create New</a>
|
||||||
|
</p>
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
@Html.DisplayNameFor(model => model.Name)
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
@Html.DisplayNameFor(model => model.CompanyId)
|
||||||
|
</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach(DocumentCompany item in Model)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Name)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.CompanyId)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a asp-action="Edit"
|
||||||
|
asp-route-id="@item.Id">
|
||||||
|
Edit
|
||||||
|
</a> |
|
||||||
|
<a asp-action="Details"
|
||||||
|
asp-route-id="@item.Id">
|
||||||
|
Details
|
||||||
|
</a> |
|
||||||
|
<a asp-action="Delete"
|
||||||
|
asp-route-id="@item.Id">
|
||||||
|
Delete
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
@@ -64,6 +64,11 @@
|
|||||||
<a asp-controller="StorageByMachines">Storage by machines</a><br />
|
<a asp-controller="StorageByMachines">Storage by machines</a><br />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="content">
|
||||||
|
<h3>Administrative pages for documents</h3>
|
||||||
|
<a asp-controller="DocumentCompanies">Document companies</a><br />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h3>Administrative pages for owned machines</h3>
|
<h3>Administrative pages for owned machines</h3>
|
||||||
<a asp-controller="OwnedMachine">Owned machines</a><br />
|
<a asp-controller="OwnedMachine">Owned machines</a><br />
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
<Version>3.0.99.836</Version>
|
<Version>3.0.99.840</Version>
|
||||||
<Company>Canary Islands Computer Museum</Company>
|
<Company>Canary Islands Computer Museum</Company>
|
||||||
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
||||||
<Product>Canary Islands Computer Museum Website</Product>
|
<Product>Canary Islands Computer Museum Website</Product>
|
||||||
|
|||||||
Reference in New Issue
Block a user