Done contact links management pages
This commit is contained in:
@@ -1,8 +1,4 @@
|
|||||||
using System;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using MyWebsite.Models;
|
using MyWebsite.Models;
|
||||||
|
|
||||||
@@ -30,5 +26,37 @@ namespace MyWebsite.Areas.Admin.Controllers
|
|||||||
|
|
||||||
return RedirectToAction("Index");
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
@model MyWebsite.Models.Link
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Create link";
|
||||||
|
}
|
||||||
|
|
||||||
|
<header>
|
||||||
|
<p> <a asp-action="Index">Back to the list</a></p>
|
||||||
|
<h1>Create link</h1>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<form asp-action="Create">
|
||||||
|
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||||
|
<div>
|
||||||
|
<label asp-for="Name"></label>
|
||||||
|
<input asp-for="Name" type="text"/>
|
||||||
|
<span asp-validation-for="Name" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label asp-for="Order"></label>
|
||||||
|
<input asp-for="Order" type="number" />
|
||||||
|
<span asp-validation-for="Order" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label asp-for="Title"></label>
|
||||||
|
<input asp-for="Title" type="text" />
|
||||||
|
<span asp-validation-for="Title" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label asp-for="Username"></label>
|
||||||
|
<input asp-for="Username" type="text" />
|
||||||
|
<span asp-validation-for="Username" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label asp-for="Url"></label>
|
||||||
|
<input asp-for="Url" type="text" />
|
||||||
|
<span asp-validation-for="Url" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" class="checkbox" asp-for="CanContactMe" /> @Html.DisplayNameFor(model => model.CanContactMe)
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" class="checkbox" asp-for="DisplayInFooter" /> @Html.DisplayNameFor(model => model.DisplayInFooter)
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<input type="submit" value="Create" class="btn" />
|
||||||
|
</form>
|
||||||
|
</article>
|
||||||
|
|
||||||
|
<link type="text/css" rel="stylesheet" href="~/css/Admin.css" />
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
@model MyWebsite.Models.Link
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Delete link";
|
||||||
|
}
|
||||||
|
|
||||||
|
<header>
|
||||||
|
<p> <a asp-action="Index">Back to the list</a></p>
|
||||||
|
<h1>Delete link</h1>
|
||||||
|
<h3>Are you sure you want to delete this?</h3>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<p class="form-group">
|
||||||
|
<b>@Html.DisplayNameFor(model => model.Name):</b> @Html.DisplayFor(model => model.Name)<br />
|
||||||
|
<b>@Html.DisplayNameFor(model => model.Order):</b> @Html.DisplayFor(model => model.Order)<br />
|
||||||
|
<b>@Html.DisplayNameFor(model => model.Title):</b> @Html.DisplayFor(model => model.Title)<br />
|
||||||
|
<b>@Html.DisplayNameFor(model => model.Username):</b> @Html.DisplayFor(model => model.Username)<br />
|
||||||
|
<b>@Html.DisplayNameFor(model => model.Url):</b> @Html.DisplayFor(model => model.Url)<br />
|
||||||
|
<b>@Html.DisplayNameFor(model => model.CanContactMe):</b> @Html.DisplayFor(model => model.CanContactMe)<br />
|
||||||
|
<b>@Html.DisplayNameFor(model => model.DisplayInFooter):</b> @Html.DisplayFor(model => model.DisplayInFooter)
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form asp-action="Delete">
|
||||||
|
<input hidden asp-for="Name" />
|
||||||
|
<input type="submit" value="Delete" class="btn-danger" />
|
||||||
|
</form>
|
||||||
|
</article>
|
||||||
|
|
||||||
|
<link type="text/css" rel="stylesheet" href="~/css/Admin.css" />
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
@model MyWebsite.Models.Link
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Edit link";
|
||||||
|
}
|
||||||
|
|
||||||
|
<header>
|
||||||
|
<p> <a asp-action="Index">Back to the list</a></p>
|
||||||
|
<h1>Edit link</h1>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<form asp-action="Edit">
|
||||||
|
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||||
|
<div>
|
||||||
|
<label asp-for="Name"></label>
|
||||||
|
<input asp-for="Name" type="text" class="readonly" readonly />
|
||||||
|
<span asp-validation-for="Name" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label asp-for="Order"></label>
|
||||||
|
<input asp-for="Order" type="number" />
|
||||||
|
<span asp-validation-for="Order" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label asp-for="Title"></label>
|
||||||
|
<input asp-for="Title" type="text" />
|
||||||
|
<span asp-validation-for="Title" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label asp-for="Username"></label>
|
||||||
|
<input asp-for="Username" type="text" />
|
||||||
|
<span asp-validation-for="Username" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label asp-for="Url"></label>
|
||||||
|
<input asp-for="Url" type="text" />
|
||||||
|
<span asp-validation-for="Url" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" class="checkbox" asp-for="CanContactMe" /> @Html.DisplayNameFor(model => model.CanContactMe)
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" class="checkbox" asp-for="DisplayInFooter" /> @Html.DisplayNameFor(model => model.DisplayInFooter)
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<input type="submit" value="Save" class="btn" />
|
||||||
|
</form>
|
||||||
|
</article>
|
||||||
|
|
||||||
|
<link type="text/css" rel="stylesheet" href="~/css/Admin.css" />
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
@model IEnumerable<MyWebsite.Models.Link>
|
@model IEnumerable<MyWebsite.Models.Link>
|
||||||
|
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Index";
|
ViewData["Title"] = "Links list";
|
||||||
}
|
}
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<h1>Index</h1>
|
<p> <a asp-action="Index" asp-controller="Admin" asp-area="">Back to main menu</a></p>
|
||||||
|
<h1>Links list</h1>
|
||||||
<p>
|
<p>
|
||||||
<a asp-action="Create" class="comment">// + Create New</a>
|
<a asp-action="Create" class="comment">// + Create New</a>
|
||||||
</p>
|
</p>
|
||||||
@@ -16,7 +17,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>
|
<th>
|
||||||
@Html.DisplayNameFor(model => model.Id)
|
@Html.DisplayNameFor(model => model.Order)
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
@Html.DisplayNameFor(model => model.Name)
|
@Html.DisplayNameFor(model => model.Name)
|
||||||
@@ -40,11 +41,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach (var item in Model)
|
@foreach (var item in Model.OrderBy(i => i.Order))
|
||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.Id)
|
@Html.DisplayFor(modelItem => item.Order)
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.Name)
|
@Html.DisplayFor(modelItem => item.Name)
|
||||||
@@ -65,8 +66,8 @@
|
|||||||
@Html.DisplayFor(modelItem => item.DisplayInFooter)
|
@Html.DisplayFor(modelItem => item.DisplayInFooter)
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
|
@Html.ActionLink("Edit", "Edit", new { id=item.Name }) |
|
||||||
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
|
@Html.ActionLink("Delete", "Delete", new { id=item.Name })
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace MyWebsite.Models
|
namespace MyWebsite.Models
|
||||||
@@ -6,22 +7,30 @@ namespace MyWebsite.Models
|
|||||||
public class Link
|
public class Link
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
public int Id { get; set; }
|
|
||||||
[Required]
|
[Required]
|
||||||
[Column(TypeName = "varchar(20)")]
|
[Column(TypeName = "varchar(20)")]
|
||||||
|
[DisplayName("Name")]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
|
[DisplayName("Order")]
|
||||||
|
public int Order { get; set; }
|
||||||
|
[Required]
|
||||||
[Column(TypeName = "varchar(20)")]
|
[Column(TypeName = "varchar(20)")]
|
||||||
|
[DisplayName("Title")]
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
[Column(TypeName = "varchar(50)")]
|
[Column(TypeName = "varchar(50)")]
|
||||||
|
[DisplayName("Username")]
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
[Column(TypeName = "varchar(255)")]
|
[Column(TypeName = "varchar(255)")]
|
||||||
|
[DisplayName("URL")]
|
||||||
public string Url { get; set; }
|
public string Url { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
|
[DisplayName("May contact")]
|
||||||
public bool CanContactMe { get; set; } = false;
|
public bool CanContactMe { get; set; } = false;
|
||||||
[Required]
|
[Required]
|
||||||
|
[DisplayName("Footer")]
|
||||||
public bool DisplayInFooter { get; set; } = false;
|
public bool DisplayInFooter { get; set; } = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<input type="password" asp-for="Password" />
|
<input type="password" asp-for="Password" />
|
||||||
<span asp-validation-for="Password"></span>
|
<span asp-validation-for="Password"></span>
|
||||||
</div>
|
</div>
|
||||||
<input style="margin-top:10px" type="submit" value="Login" />
|
<input class="btn" style="margin-top:10px" type="submit" value="Login" />
|
||||||
</form>
|
</form>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
|
|||||||
@@ -8,13 +8,13 @@
|
|||||||
|
|
||||||
<article>
|
<article>
|
||||||
<p>
|
<p>
|
||||||
@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))
|
||||||
{
|
{
|
||||||
<a class="socicon-@(link.Name)"></a> @(link.Title) <a href="@(link.Url)" target="_blank">@(link.Username)</a><br />
|
<a class="socicon-@(link.Name)"></a> @(link.Title) <a href="@(link.Url)" target="_blank">@(link.Username)</a><br />
|
||||||
}
|
}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
@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))
|
||||||
{
|
{
|
||||||
<a class="socicon-@(link.Name)"></a> @(link.Title) <a href="@(link.Url)" target="_blank">@(link.Username)</a><br />
|
<a class="socicon-@(link.Name)"></a> @(link.Title) <a href="@(link.Url)" target="_blank">@(link.Username)</a><br />
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
@{
|
@{
|
||||||
Link email = Startup.Database.Links.FirstOrDefault(i => i.Name == "outlook");
|
Link email = Startup.Database.Links.FirstOrDefault(i => i.Name == "outlook");
|
||||||
List<Link> links = Startup.Database.Links.Where(i => new string[] { "linkedin", "github", "twitter", "vkontakte" }.Contains(i.Name)).OrderBy(i => i.Id).ToList();
|
List<Link> links = Startup.Database.Links.Where(i => new string[] { "linkedin", "github", "twitter", "vkontakte" }.Contains(i.Name)).OrderBy(i => i.Order).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="contact-me">
|
<div class="contact-me">
|
||||||
|
|||||||
@@ -46,10 +46,12 @@
|
|||||||
<footer>
|
<footer>
|
||||||
<span class="comment">// Copyright ©@(DateTime.Today.Year) Michael "XFox" Gordeev</span>
|
<span class="comment">// Copyright ©@(DateTime.Today.Year) Michael "XFox" Gordeev</span>
|
||||||
|
|
||||||
@foreach (Link link in Startup.Database.Links.Where(i => i.DisplayInFooter).OrderBy(i => i.Id))
|
<div>
|
||||||
{
|
@foreach (Link link in Startup.Database.Links.Where(i => i.DisplayInFooter).OrderBy(i => i.Order))
|
||||||
<a class="socicon-@(link.Name)" href="@(link.Url)" target="_blank" title="@(link.Title)"></a>
|
{
|
||||||
}
|
<a class="socicon-@(link.Name)" href="@(link.Url)" target="_blank" title="@(link.Title)"></a>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -76,6 +76,10 @@ table {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.form-group input {
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
@media only screen and (max-width: 700px) {
|
@media only screen and (max-width: 700px) {
|
||||||
form {
|
form {
|
||||||
max-width: initial;
|
max-width: initial;
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ footer {
|
|||||||
padding: 10px;
|
padding: 10px;
|
||||||
display: grid;
|
display: grid;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
grid-template-columns: 1fr auto auto auto;
|
grid-template-columns: 1fr auto;
|
||||||
grid-column-gap: 10px;
|
grid-column-gap: 10px;
|
||||||
}
|
}
|
||||||
footer a {
|
footer a {
|
||||||
@@ -104,6 +104,24 @@ article a:visited, article a:link {
|
|||||||
color: blue;
|
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 {
|
.comment, .comment:visited {
|
||||||
color: #57a64a !important;
|
color: #57a64a !important;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user