diff --git a/MyWebsite/MyWebsite/Areas/Admin/Controllers/ContactsController.cs b/MyWebsite/MyWebsite/Areas/Admin/Controllers/ContactsController.cs index 82a44e2..424e28d 100644 --- a/MyWebsite/MyWebsite/Areas/Admin/Controllers/ContactsController.cs +++ b/MyWebsite/MyWebsite/Areas/Admin/Controllers/ContactsController.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using MyWebsite.Models; @@ -30,5 +26,37 @@ namespace MyWebsite.Areas.Admin.Controllers return RedirectToAction("Index"); } + + [HttpGet] + public IActionResult Delete(string id) => + View(Startup.Database.Links.Find(id)); + + [HttpPost] + public IActionResult Delete(Link link) + { + Startup.Database.Links.Remove(link); + Startup.Database.SaveChanges(); + + return RedirectToAction("Index"); + } + + [HttpGet] + public IActionResult Create() => + View(); + + [HttpPost] + public IActionResult Create(Link link) + { + if (!ModelState.IsValid) + { + ModelState.AddModelError("Authorization error", "Invalid data"); + return View(link); + } + + Startup.Database.Links.Add(link); + Startup.Database.SaveChanges(); + + return RedirectToAction("Index"); + } } } \ No newline at end of file diff --git a/MyWebsite/MyWebsite/Areas/Admin/Views/Contacts/Create.cshtml b/MyWebsite/MyWebsite/Areas/Admin/Views/Contacts/Create.cshtml new file mode 100644 index 0000000..b51c15e --- /dev/null +++ b/MyWebsite/MyWebsite/Areas/Admin/Views/Contacts/Create.cshtml @@ -0,0 +1,51 @@ +@model MyWebsite.Models.Link + +@{ + ViewData["Title"] = "Create link"; +} + +
+

Back to the list

+

Create link

+
+ +
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+ + + + +
+
+ + \ No newline at end of file diff --git a/MyWebsite/MyWebsite/Areas/Admin/Views/Contacts/Delete.cshtml b/MyWebsite/MyWebsite/Areas/Admin/Views/Contacts/Delete.cshtml new file mode 100644 index 0000000..45dcdee --- /dev/null +++ b/MyWebsite/MyWebsite/Areas/Admin/Views/Contacts/Delete.cshtml @@ -0,0 +1,30 @@ +@model MyWebsite.Models.Link + +@{ + ViewData["Title"] = "Delete link"; +} + +
+

Back to the list

+

Delete link

+

Are you sure you want to delete this?

+
+ +
+

+ @Html.DisplayNameFor(model => model.Name): @Html.DisplayFor(model => model.Name)
+ @Html.DisplayNameFor(model => model.Order): @Html.DisplayFor(model => model.Order)
+ @Html.DisplayNameFor(model => model.Title): @Html.DisplayFor(model => model.Title)
+ @Html.DisplayNameFor(model => model.Username): @Html.DisplayFor(model => model.Username)
+ @Html.DisplayNameFor(model => model.Url): @Html.DisplayFor(model => model.Url)
+ @Html.DisplayNameFor(model => model.CanContactMe): @Html.DisplayFor(model => model.CanContactMe)
+ @Html.DisplayNameFor(model => model.DisplayInFooter): @Html.DisplayFor(model => model.DisplayInFooter) +

+ +
+ + +
+
+ + \ No newline at end of file diff --git a/MyWebsite/MyWebsite/Areas/Admin/Views/Contacts/Edit.cshtml b/MyWebsite/MyWebsite/Areas/Admin/Views/Contacts/Edit.cshtml new file mode 100644 index 0000000..22c7a7d --- /dev/null +++ b/MyWebsite/MyWebsite/Areas/Admin/Views/Contacts/Edit.cshtml @@ -0,0 +1,51 @@ +@model MyWebsite.Models.Link + +@{ + ViewData["Title"] = "Edit link"; +} + +
+

Back to the list

+

Edit link

+
+ +
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+ + + + +
+
+ + \ No newline at end of file diff --git a/MyWebsite/MyWebsite/Areas/Admin/Views/Contacts/Index.cshtml b/MyWebsite/MyWebsite/Areas/Admin/Views/Contacts/Index.cshtml index 1632ec9..2464352 100644 --- a/MyWebsite/MyWebsite/Areas/Admin/Views/Contacts/Index.cshtml +++ b/MyWebsite/MyWebsite/Areas/Admin/Views/Contacts/Index.cshtml @@ -1,11 +1,12 @@ @model IEnumerable @{ - ViewData["Title"] = "Index"; + ViewData["Title"] = "Links list"; }
-

Index

+

Back to main menu

+

Links list

// + Create New

@@ -16,7 +17,7 @@ - @Html.DisplayNameFor(model => model.Id) + @Html.DisplayNameFor(model => model.Order) @Html.DisplayNameFor(model => model.Name) @@ -40,11 +41,11 @@ - @foreach (var item in Model) + @foreach (var item in Model.OrderBy(i => i.Order)) { - @Html.DisplayFor(modelItem => item.Id) + @Html.DisplayFor(modelItem => item.Order) @Html.DisplayFor(modelItem => item.Name) @@ -65,8 +66,8 @@ @Html.DisplayFor(modelItem => item.DisplayInFooter) - @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) | - @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ }) + @Html.ActionLink("Edit", "Edit", new { id=item.Name }) | + @Html.ActionLink("Delete", "Delete", new { id=item.Name }) } diff --git a/MyWebsite/MyWebsite/Models/Link.cs b/MyWebsite/MyWebsite/Models/Link.cs index 50cc1bb..b539d6b 100644 --- a/MyWebsite/MyWebsite/Models/Link.cs +++ b/MyWebsite/MyWebsite/Models/Link.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace MyWebsite.Models @@ -6,22 +7,30 @@ namespace MyWebsite.Models public class Link { [Key] - public int Id { get; set; } [Required] [Column(TypeName = "varchar(20)")] + [DisplayName("Name")] public string Name { get; set; } [Required] + [DisplayName("Order")] + public int Order { get; set; } + [Required] [Column(TypeName = "varchar(20)")] + [DisplayName("Title")] public string Title { get; set; } [Required] [Column(TypeName = "varchar(50)")] + [DisplayName("Username")] public string Username { get; set; } [Required] [Column(TypeName = "varchar(255)")] + [DisplayName("URL")] public string Url { get; set; } [Required] + [DisplayName("May contact")] public bool CanContactMe { get; set; } = false; [Required] + [DisplayName("Footer")] public bool DisplayInFooter { get; set; } = false; } } diff --git a/MyWebsite/MyWebsite/Views/Admin/Login.cshtml b/MyWebsite/MyWebsite/Views/Admin/Login.cshtml index c9f8811..fd4ced3 100644 --- a/MyWebsite/MyWebsite/Views/Admin/Login.cshtml +++ b/MyWebsite/MyWebsite/Views/Admin/Login.cshtml @@ -20,7 +20,7 @@ - + diff --git a/MyWebsite/MyWebsite/Views/Shared/Contacts.cshtml b/MyWebsite/MyWebsite/Views/Shared/Contacts.cshtml index 11476ad..6f56625 100644 --- a/MyWebsite/MyWebsite/Views/Shared/Contacts.cshtml +++ b/MyWebsite/MyWebsite/Views/Shared/Contacts.cshtml @@ -8,13 +8,13 @@

- @foreach (Link link in Startup.Database.Links.Where(i => i.CanContactMe).OrderBy(i => i.Id)) + @foreach (Link link in Startup.Database.Links.Where(i => i.CanContactMe).OrderBy(i => i.Order)) { @(link.Title) @(link.Username)
}

- @foreach (Link link in Startup.Database.Links.Where(i => !i.CanContactMe).OrderBy(i => i.Id)) + @foreach (Link link in Startup.Database.Links.Where(i => !i.CanContactMe).OrderBy(i => i.Order)) { @(link.Title) @(link.Username)
} diff --git a/MyWebsite/MyWebsite/Views/Shared/ContactsBlock.cshtml b/MyWebsite/MyWebsite/Views/Shared/ContactsBlock.cshtml index ef4776a..f7e719f 100644 --- a/MyWebsite/MyWebsite/Views/Shared/ContactsBlock.cshtml +++ b/MyWebsite/MyWebsite/Views/Shared/ContactsBlock.cshtml @@ -1,6 +1,6 @@ @{ Link email = Startup.Database.Links.FirstOrDefault(i => i.Name == "outlook"); - List links = Startup.Database.Links.Where(i => new string[] { "linkedin", "github", "twitter", "vkontakte" }.Contains(i.Name)).OrderBy(i => i.Id).ToList(); + List links = Startup.Database.Links.Where(i => new string[] { "linkedin", "github", "twitter", "vkontakte" }.Contains(i.Name)).OrderBy(i => i.Order).ToList(); }

diff --git a/MyWebsite/MyWebsite/Views/Shared/_Layout.cshtml b/MyWebsite/MyWebsite/Views/Shared/_Layout.cshtml index 884e55b..8810946 100644 --- a/MyWebsite/MyWebsite/Views/Shared/_Layout.cshtml +++ b/MyWebsite/MyWebsite/Views/Shared/_Layout.cshtml @@ -46,10 +46,12 @@ \ No newline at end of file diff --git a/MyWebsite/MyWebsite/wwwroot/css/Admin.css b/MyWebsite/MyWebsite/wwwroot/css/Admin.css index a063ed4..6ac92a8 100644 --- a/MyWebsite/MyWebsite/wwwroot/css/Admin.css +++ b/MyWebsite/MyWebsite/wwwroot/css/Admin.css @@ -76,6 +76,10 @@ table { width: 100%; } +.form-group input { + width: auto; +} + @media only screen and (max-width: 700px) { form { max-width: initial; diff --git a/MyWebsite/MyWebsite/wwwroot/css/Style.css b/MyWebsite/MyWebsite/wwwroot/css/Style.css index 2a82928..ecc1360 100644 --- a/MyWebsite/MyWebsite/wwwroot/css/Style.css +++ b/MyWebsite/MyWebsite/wwwroot/css/Style.css @@ -60,7 +60,7 @@ footer { padding: 10px; display: grid; align-items: center; - grid-template-columns: 1fr auto auto auto; + grid-template-columns: 1fr auto; grid-column-gap: 10px; } footer a { @@ -104,6 +104,24 @@ article a:visited, article a:link { color: blue; } +.btn { + background-color: #343434; + color: white; +} + +.btn-danger { + background-color: red; + color: white; +} + +.checkbox { + width: auto; +} + +.readonly { + background-color: lightgray; +} + .comment, .comment:visited { color: #57a64a !important; }