From 4eccef6647af6899077bee4c61b6c3215e9a618f Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 30 Jun 2019 01:26:03 +0100 Subject: [PATCH] Add CRUD pages for document companies. --- .../DocumentCompaniesController.cs | 123 ++++++++++++++++++ .../Views/DocumentCompanies/Create.cshtml | 48 +++++++ .../Views/DocumentCompanies/Delete.cshtml | 36 +++++ .../Views/DocumentCompanies/Details.cshtml | 33 +++++ .../Admin/Views/DocumentCompanies/Edit.cshtml | 50 +++++++ .../Views/DocumentCompanies/Index.cshtml | 52 ++++++++ cicm_web/Areas/Admin/Views/Home/Index.cshtml | 5 + cicm_web/cicm_web.csproj | 2 +- 8 files changed, 348 insertions(+), 1 deletion(-) create mode 100644 cicm_web/Areas/Admin/Controllers/DocumentCompaniesController.cs create mode 100644 cicm_web/Areas/Admin/Views/DocumentCompanies/Create.cshtml create mode 100644 cicm_web/Areas/Admin/Views/DocumentCompanies/Delete.cshtml create mode 100644 cicm_web/Areas/Admin/Views/DocumentCompanies/Details.cshtml create mode 100644 cicm_web/Areas/Admin/Views/DocumentCompanies/Edit.cshtml create mode 100644 cicm_web/Areas/Admin/Views/DocumentCompanies/Index.cshtml diff --git a/cicm_web/Areas/Admin/Controllers/DocumentCompaniesController.cs b/cicm_web/Areas/Admin/Controllers/DocumentCompaniesController.cs new file mode 100644 index 00000000..ea19b2ea --- /dev/null +++ b/cicm_web/Areas/Admin/Controllers/DocumentCompaniesController.cs @@ -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 Index() => View(await _context.DocumentCompanies.ToListAsync()); + + // GET: DocumentCompanies/Details/5 + public async Task 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 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 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 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 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 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); + } + } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/DocumentCompanies/Create.cshtml b/cicm_web/Areas/Admin/Views/DocumentCompanies/Create.cshtml new file mode 100644 index 00000000..0043cf13 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/DocumentCompanies/Create.cshtml @@ -0,0 +1,48 @@ +@model Cicm.Database.Models.DocumentCompany + +@{ + ViewData["Title"] = "Create"; +} + +

Create

+ +

DocumentCompany

+
+
+
+
+
+
+
+ + + + +
+
+ + + + +
+
+ +
+
+
+
+ + \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/DocumentCompanies/Delete.cshtml b/cicm_web/Areas/Admin/Views/DocumentCompanies/Delete.cshtml new file mode 100644 index 00000000..e5f963bc --- /dev/null +++ b/cicm_web/Areas/Admin/Views/DocumentCompanies/Delete.cshtml @@ -0,0 +1,36 @@ +@model Cicm.Database.Models.DocumentCompany + +@{ + ViewData["Title"] = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

DocumentCompany

+
+
+
+ @Html.DisplayNameFor(model => model.Name) +
+
+ @Html.DisplayFor(model => model.Name) +
+
+ @Html.DisplayNameFor(model => model.CompanyId) +
+
+ @Html.DisplayFor(model => model.CompanyId) +
+
+ +
+ + | + Back to List +
+
\ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/DocumentCompanies/Details.cshtml b/cicm_web/Areas/Admin/Views/DocumentCompanies/Details.cshtml new file mode 100644 index 00000000..dac00b45 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/DocumentCompanies/Details.cshtml @@ -0,0 +1,33 @@ +@model Cicm.Database.Models.DocumentCompany + +@{ + ViewData["Title"] = "Details"; +} + +

Details

+ +
+

DocumentCompany

+
+
+
+ @Html.DisplayNameFor(model => model.Name) +
+
+ @Html.DisplayFor(model => model.Name) +
+
+ @Html.DisplayNameFor(model => model.CompanyId) +
+
+ @Html.DisplayFor(model => model.CompanyId) +
+
+
+ \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/DocumentCompanies/Edit.cshtml b/cicm_web/Areas/Admin/Views/DocumentCompanies/Edit.cshtml new file mode 100644 index 00000000..d689821b --- /dev/null +++ b/cicm_web/Areas/Admin/Views/DocumentCompanies/Edit.cshtml @@ -0,0 +1,50 @@ +@model Cicm.Database.Models.DocumentCompany + +@{ + ViewData["Title"] = "Edit"; +} + +

Edit

+ +

DocumentCompany

+
+
+
+
+
+
+
+ + + + +
+
+ + + + +
+ +
+ +
+
+
+
+ + \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/DocumentCompanies/Index.cshtml b/cicm_web/Areas/Admin/Views/DocumentCompanies/Index.cshtml new file mode 100644 index 00000000..bf6b18f6 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/DocumentCompanies/Index.cshtml @@ -0,0 +1,52 @@ +@using Cicm.Database.Models +@model IEnumerable + +@{ + ViewData["Title"] = "Index"; +} + +

Index

+ +

+ Create New +

+ + + + + + + + + + @foreach(DocumentCompany item in Model) + { + + + + + + } + +
+ @Html.DisplayNameFor(model => model.Name) + + @Html.DisplayNameFor(model => model.CompanyId) +
+ @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.CompanyId) + + + Edit + | + + Details + | + + Delete + +
\ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/Home/Index.cshtml b/cicm_web/Areas/Admin/Views/Home/Index.cshtml index 05a0f4ab..022f4291 100644 --- a/cicm_web/Areas/Admin/Views/Home/Index.cshtml +++ b/cicm_web/Areas/Admin/Views/Home/Index.cshtml @@ -64,6 +64,11 @@ Storage by machines
+
+

Administrative pages for documents

+ Document companies
+
+

Administrative pages for owned machines

Owned machines
diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index 908c71ff..f8469db6 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.2 - 3.0.99.836 + 3.0.99.840 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website