diff --git a/Cicm.Database/Models/DocumentCompany.cs b/Cicm.Database/Models/DocumentCompany.cs index f32c907a..bb970ff4 100644 --- a/Cicm.Database/Models/DocumentCompany.cs +++ b/Cicm.Database/Models/DocumentCompany.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.ComponentModel; using System.ComponentModel.DataAnnotations; namespace Cicm.Database.Models @@ -9,7 +10,8 @@ namespace Cicm.Database.Models public string Name { get; set; } public int? CompanyId { get; set; } - public virtual Company Company { get; set; } + [DisplayName("Linked company")] + public virtual Company Company { get; set; } public virtual ICollection Documents { get; set; } public virtual ICollection Books { get; set; } public virtual ICollection Magazines { get; set; } diff --git a/Cicm.Database/Models/DocumentPerson.cs b/Cicm.Database/Models/DocumentPerson.cs index a0fe6a2b..bbd87591 100644 --- a/Cicm.Database/Models/DocumentPerson.cs +++ b/Cicm.Database/Models/DocumentPerson.cs @@ -20,7 +20,8 @@ namespace Cicm.Database.Models [DisplayName("Name")] public string FullName => DisplayName ?? Alias ?? $"{Name} {Surname}"; - public virtual Person Person { get; set; } + [DisplayName("Linked person")] + public virtual Person Person { get; set; } public virtual ICollection Documents { get; set; } public virtual ICollection Books { get; set; } public virtual ICollection Magazines { get; set; } diff --git a/cicm_web/Areas/Admin/Controllers/DocumentPeopleController.cs b/cicm_web/Areas/Admin/Controllers/DocumentPeopleController.cs new file mode 100644 index 00000000..d4e47b99 --- /dev/null +++ b/cicm_web/Areas/Admin/Controllers/DocumentPeopleController.cs @@ -0,0 +1,149 @@ +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; +using Microsoft.EntityFrameworkCore; + +namespace cicm_web.Areas.Admin.Controllers +{ + [Area("Admin")] + [Authorize] + public class DocumentPeopleController : Controller + { + readonly cicmContext _context; + + public DocumentPeopleController(cicmContext context) + { + _context = context; + } + + // GET: DocumentPeople + public async Task Index() + { + return View(await _context.DocumentPeople.OrderBy(d => d.FullName) + .Select(d => new DocumentPersonViewModel + { + Id = d.Id, + Name = d.FullName, + Person = d.Person.FullName, + PersonId = d.PersonId + }).ToListAsync()); + } + + // GET: DocumentPeople/Details/5 + public async Task Details(int? id) + { + if(id == null) return NotFound(); + + DocumentPerson documentPerson = await _context.DocumentPeople.FirstOrDefaultAsync(m => m.Id == id); + if(documentPerson == null) return NotFound(); + + return View(documentPerson); + } + + // GET: DocumentPeople/Create + public IActionResult Create() + { + ViewData["PersonId"] = + new SelectList(_context.People.OrderBy(c => c.FullName).Select(c => new {c.Id, Name = c.FullName}), + "Id", "Name"); + return View(); + } + + // POST: DocumentPeople/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,Surname,Alias,DisplayName,PersonId,Id")] + DocumentPerson documentPerson) + { + if(!ModelState.IsValid) return View(documentPerson); + + _context.Add(documentPerson); + await _context.SaveChangesAsync(); + return RedirectToAction(nameof(Index)); + } + + // GET: DocumentPeople/Edit/5 + public async Task Edit(int? id) + { + if(id == null) return NotFound(); + + DocumentPerson documentPerson = await _context.DocumentPeople.FindAsync(id); + + if(documentPerson == null) return NotFound(); + + ViewData["PersonId"] = + new SelectList(_context.People.OrderBy(c => c.FullName).Select(c => new {c.Id, Name = c.FullName}), + "Id", "Name", documentPerson.PersonId); + + return View(documentPerson); + } + + // POST: DocumentPeople/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,Surname,Alias,DisplayName,PersonId,Id")] + DocumentPerson documentPerson) + { + if(id != documentPerson.Id) return NotFound(); + + if(ModelState.IsValid) + { + try + { + _context.Update(documentPerson); + await _context.SaveChangesAsync(); + } + catch(DbUpdateConcurrencyException) + { + if(!DocumentPersonExists(documentPerson.Id)) return NotFound(); + + throw; + } + + return RedirectToAction(nameof(Index)); + } + + ViewData["PersonId"] = + new SelectList(_context.People.OrderBy(c => c.FullName).Select(c => new {c.Id, Name = c.FullName}), + "Id", "Name", documentPerson.PersonId); + + return View(documentPerson); + } + + // GET: DocumentPeople/Delete/5 + public async Task Delete(int? id) + { + if(id == null) return NotFound(); + + DocumentPerson documentPerson = await _context.DocumentPeople.FirstOrDefaultAsync(m => m.Id == id); + if(documentPerson == null) return NotFound(); + + return View(documentPerson); + } + + // POST: DocumentPeople/Delete/5 + [HttpPost] + [ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + DocumentPerson documentPerson = await _context.DocumentPeople.FindAsync(id); + _context.DocumentPeople.Remove(documentPerson); + await _context.SaveChangesAsync(); + return RedirectToAction(nameof(Index)); + } + + bool DocumentPersonExists(int id) + { + return _context.DocumentPeople.Any(e => e.Id == id); + } + } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Models/DocumentPersonViewModel.cs b/cicm_web/Areas/Admin/Models/DocumentPersonViewModel.cs new file mode 100644 index 00000000..c9d70426 --- /dev/null +++ b/cicm_web/Areas/Admin/Models/DocumentPersonViewModel.cs @@ -0,0 +1,12 @@ +using System.ComponentModel; + +namespace cicm_web.Areas.Admin.Models +{ + public class DocumentPersonViewModel : BaseViewModel + { + public string Name { get; set; } + [DisplayName("Linked person")] + public string Person { get; set; } + public int? PersonId { get; set; } + } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/DocumentPeople/Create.cshtml b/cicm_web/Areas/Admin/Views/DocumentPeople/Create.cshtml new file mode 100644 index 00000000..1e1820dd --- /dev/null +++ b/cicm_web/Areas/Admin/Views/DocumentPeople/Create.cshtml @@ -0,0 +1,85 @@ +@model Cicm.Database.Models.DocumentPerson + +@{ + ViewData["Title"] = "Create"; +} + +

Create

+ +

Document person

+
+
+
+
+
+
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + +
+ +
+
+
+ +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/DocumentPeople/Delete.cshtml b/cicm_web/Areas/Admin/Views/DocumentPeople/Delete.cshtml new file mode 100644 index 00000000..ac01a8cd --- /dev/null +++ b/cicm_web/Areas/Admin/Views/DocumentPeople/Delete.cshtml @@ -0,0 +1,60 @@ +@model Cicm.Database.Models.DocumentPerson + +@{ + ViewData["Title"] = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

Document person

+
+
+
+ @Html.DisplayNameFor(model => model.Name) +
+
+ @Html.DisplayFor(model => model.Name) +
+
+ @Html.DisplayNameFor(model => model.Surname) +
+
+ @Html.DisplayFor(model => model.Surname) +
+
+ @Html.DisplayNameFor(model => model.Alias) +
+
+ @Html.DisplayFor(model => model.Alias) +
+
+ @Html.DisplayNameFor(model => model.DisplayName) +
+
+ @Html.DisplayFor(model => model.DisplayName) +
+
+ @Html.DisplayNameFor(model => model.Person) +
+
+ + @Html.DisplayFor(modelItem => Model.Person.FullName) +
+
+ +
+ + + + Back to List + +
+
\ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/DocumentPeople/Details.cshtml b/cicm_web/Areas/Admin/Views/DocumentPeople/Details.cshtml new file mode 100644 index 00000000..f8a65089 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/DocumentPeople/Details.cshtml @@ -0,0 +1,58 @@ +@model Cicm.Database.Models.DocumentPerson + +@{ + ViewData["Title"] = "Details"; +} + +

Details

+ +
+

Document person

+
+
+
+ @Html.DisplayNameFor(model => model.Name) +
+
+ @Html.DisplayFor(model => model.Name) +
+
+ @Html.DisplayNameFor(model => model.Surname) +
+
+ @Html.DisplayFor(model => model.Surname) +
+
+ @Html.DisplayNameFor(model => model.Alias) +
+
+ @Html.DisplayFor(model => model.Alias) +
+
+ @Html.DisplayNameFor(model => model.DisplayName) +
+
+ @Html.DisplayFor(model => model.DisplayName) +
+
+ @Html.DisplayNameFor(model => model.Person) +
+
+ + @Html.DisplayFor(modelItem => Model.Person.FullName) +
+
+
+ \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/DocumentPeople/Edit.cshtml b/cicm_web/Areas/Admin/Views/DocumentPeople/Edit.cshtml new file mode 100644 index 00000000..fb765fb2 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/DocumentPeople/Edit.cshtml @@ -0,0 +1,87 @@ +@model Cicm.Database.Models.DocumentPerson + +@{ + ViewData["Title"] = "Edit"; +} + +

Edit

+ +

Document person

+
+
+
+
+
+
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + +
+ + +
+
+
+ +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/DocumentPeople/Index.cshtml b/cicm_web/Areas/Admin/Views/DocumentPeople/Index.cshtml new file mode 100644 index 00000000..450c9347 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/DocumentPeople/Index.cshtml @@ -0,0 +1,61 @@ +@using cicm_web.Areas.Admin.Models +@model IEnumerable + +@{ + ViewData["Title"] = "Index"; +} + +

Document people

+ +

+ + Create New + +

+ + + + + + + + + + @foreach(DocumentPersonViewModel item in Model) + { + + + + + + } + +
+ @Html.DisplayNameFor(model => model.Name) + + @Html.DisplayNameFor(model => model.Person) +
+ @Html.DisplayFor(modelItem => item.Name) + + + @Html.DisplayFor(modelItem => item.Person) + + + Details + + + Edit + + + 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 022f4291..1ed4a8ab 100644 --- a/cicm_web/Areas/Admin/Views/Home/Index.cshtml +++ b/cicm_web/Areas/Admin/Views/Home/Index.cshtml @@ -67,6 +67,7 @@

Administrative pages for documents

Document companies
+ Document people
diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index a017420b..4cf8c8e6 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.2 - 3.0.99.881 + 3.0.99.883 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website