1
0

Done resume management pages

This commit is contained in:
Michael Gordeev
2019-12-14 00:40:34 +03:00
parent f43739879b
commit 21f4021fa4
5 changed files with 120 additions and 2 deletions
@@ -0,0 +1,65 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MyWebsite.Models;
using System;
namespace MyWebsite.Areas.Admin.Controllers
{
[Authorize]
[Area("Admin")]
public class ResumeController : Controller
{
public ResumeController(DatabaseContext context) =>
Startup.Database = context;
public IActionResult Index() =>
View(Startup.Database.Resume);
[HttpGet]
public IActionResult Edit(string id) =>
View(Startup.Database.Resume.Find(id));
[HttpPost]
public IActionResult Edit(Resume model)
{
model.LastUpdate = DateTime.Now;
Startup.Database.Resume.Update(model);
Startup.Database.SaveChanges();
return RedirectToAction("Index");
}
[HttpGet]
public IActionResult Delete(string id) =>
View(Startup.Database.Resume.Find(id));
[HttpPost]
public IActionResult Delete(Resume model)
{
Startup.Database.Resume.Remove(model);
Startup.Database.SaveChanges();
return RedirectToAction("Index");
}
[HttpGet]
public IActionResult Create() =>
View();
[HttpPost]
public IActionResult Create(Resume model)
{
model.LastUpdate = DateTime.Now;
if (!ModelState.IsValid)
{
ModelState.AddModelError("Error", "Invalid data");
return View(model);
}
Startup.Database.Resume.Add(model);
Startup.Database.SaveChanges();
return RedirectToAction("Index");
}
}
}
@@ -12,7 +12,7 @@
</header> </header>
<article> <article>
<table class="table"> <table>
<thead> <thead>
<tr> <tr>
<th> <th>
@@ -0,0 +1,44 @@
@model IEnumerable<MyWebsite.Models.Resume>
@{
ViewData["Title"] = "Resumes";
}
<header>
<p>&#xE760; <a asp-action="Index" asp-controller="Admin" asp-area="">Back to main menu</a></p>
<h1>Resumes list</h1>
<p>
<a asp-action="Create" class="comment">// + Create New</a>
</p>
</header>
<article>
<table>
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Language)
</th>
<th>
@Html.DisplayNameFor(model => model.LastUpdate)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@item.Language</td>
<td>@item.LastUpdate</td>
<td>
<a asp-action="Edit" asp-route-id="@item.Language">Edit</a> |
<a asp-action="Delete" asp-route-id="@item.Language">Delete</a>
</td>
</tr>
}
</tbody>
</table>
</article>
<link type="text/css" rel="stylesheet" href="~/css/Admin.css" />
+9 -1
View File
@@ -1,4 +1,6 @@
using System.ComponentModel.DataAnnotations; using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
namespace MyWebsite.Models namespace MyWebsite.Models
@@ -6,10 +8,16 @@ namespace MyWebsite.Models
public class Resume public class Resume
{ {
[Key] [Key]
[Required]
[Column(TypeName = "varchar(10)")] [Column(TypeName = "varchar(10)")]
[DisplayName("Language")]
public string Language { get; set; } public string Language { get; set; }
[Required] [Required]
[Column(TypeName = "text")] [Column(TypeName = "text")]
[DisplayName("Content")]
public string Content { get; set; } public string Content { get; set; }
[DisplayName("Last chagnge")]
public DateTime LastUpdate { get; set; }
} }
} }
@@ -5,6 +5,7 @@
<header> <header>
<h1>My resume</h1> <h1>My resume</h1>
<p>Last update: @Model.LastUpdate</p>
<a class="comment" asp-action="Download">// Download CV (.pdf) &#xE118;</a><br /> <a class="comment" asp-action="Download">// Download CV (.pdf) &#xE118;</a><br />
<a class="comment" asp-action="Print">// Print CV &#xE749;</a> <a class="comment" asp-action="Print">// Print CV &#xE749;</a>