From 6fcc621f20894b5c842f82b68717b0b692fd484b Mon Sep 17 00:00:00 2001 From: Michael Gordeev Date: Thu, 17 Oct 2019 20:29:59 +0300 Subject: [PATCH] Links --- .../Controllers/ContactsController.cs | 15 ++++- MyWebsite/MyWebsite/Models/Link.cs | 1 + .../MyWebsite/Views/Contacts/Index.cshtml | 26 +++++---- .../MyWebsite/Views/Shared/_Layout.cshtml | 17 ++++-- MyWebsite/MyWebsite/wwwroot/Links.json | 55 +++++++++++-------- 5 files changed, 75 insertions(+), 39 deletions(-) diff --git a/MyWebsite/MyWebsite/Controllers/ContactsController.cs b/MyWebsite/MyWebsite/Controllers/ContactsController.cs index 95735d6..c0fbcf6 100644 --- a/MyWebsite/MyWebsite/Controllers/ContactsController.cs +++ b/MyWebsite/MyWebsite/Controllers/ContactsController.cs @@ -1,10 +1,21 @@ using Microsoft.AspNetCore.Mvc; +using MyWebsite.Models; +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Linq; +using System.Net; namespace MyWebsite.Controllers { public class ContactsController : Controller { - public IActionResult Index() => - View(); + public IActionResult Index() + { + Dictionary links = JsonConvert.DeserializeObject>(new WebClient().DownloadString($"https://{Request.Host}/Links.json")); + ViewData["contactLinks"] = links.Values.ToList().FindAll(i => i.CanContactMe); + ViewData["otherLinks"] = links.Values.ToList().FindAll(i => !i.CanContactMe); + + return View(); + } } } \ No newline at end of file diff --git a/MyWebsite/MyWebsite/Models/Link.cs b/MyWebsite/MyWebsite/Models/Link.cs index 97afd86..6a9f5ca 100644 --- a/MyWebsite/MyWebsite/Models/Link.cs +++ b/MyWebsite/MyWebsite/Models/Link.cs @@ -11,5 +11,6 @@ namespace MyWebsite.Models public string Socicon { get; set; } public string Username { get; set; } public string Url { get; set; } + public bool CanContactMe { get; set; } } } diff --git a/MyWebsite/MyWebsite/Views/Contacts/Index.cshtml b/MyWebsite/MyWebsite/Views/Contacts/Index.cshtml index 3686d4e..fa26ec4 100644 --- a/MyWebsite/MyWebsite/Views/Contacts/Index.cshtml +++ b/MyWebsite/MyWebsite/Views/Contacts/Index.cshtml @@ -9,18 +9,24 @@

- Email: michael.xfox@outlook.com
- LinkedIn: @@xfox
- - Vkontakte: @@xfox.mike
- Telegram: @@xfox111
- Skype: @@mag48gordeev + @foreach(Link link in ViewData["contactLinks"] as List) + { + @(link.Title) @(link.Username) + @if((ViewData["contactLinks"] as List).LastOrDefault() != link) + { +
+ } + }

- Twitter: @@xfox111
- Twitch: @@xfox111
- YouTube: @@UC3H2q5Ss_CR3wP_S1zV8joA
- GitHub: @@xfox111
+ @foreach (Link link in ViewData["otherLinks"] as List) + { + @(link.Title) @(link.Username) + @if ((ViewData["otherLinks"] as List).LastOrDefault() != link) + { +
+ } + }

diff --git a/MyWebsite/MyWebsite/Views/Shared/_Layout.cshtml b/MyWebsite/MyWebsite/Views/Shared/_Layout.cshtml index 6d53078..137d996 100644 --- a/MyWebsite/MyWebsite/Views/Shared/_Layout.cshtml +++ b/MyWebsite/MyWebsite/Views/Shared/_Layout.cshtml @@ -1,4 +1,10 @@ - +@using Newtonsoft.Json +@using System.Net +@{ + Dictionary links = JsonConvert.DeserializeObject>(new WebClient().DownloadString("Links.json")); +} + + @ViewData["Title"] - XFox111.NET @@ -54,9 +60,12 @@ diff --git a/MyWebsite/MyWebsite/wwwroot/Links.json b/MyWebsite/MyWebsite/wwwroot/Links.json index 4502ff9..5048e19 100644 --- a/MyWebsite/MyWebsite/wwwroot/Links.json +++ b/MyWebsite/MyWebsite/wwwroot/Links.json @@ -3,54 +3,63 @@ "Title": "Email", "Socicon": "outlook", "Username": "michael.xfox@outlook.com", - "Url": "mailto:michael.xfox@outlook.com" + "Url": "mailto:michael.xfox@outlook.com", + "CanContactMe": "true" }, "linkedin": { "Title": "LinkedIn", "Socicon": "linkedin", "Username": "@xfox", - "Url": "//linkedin.com/in/xfox" + "Url": "//linkedin.com/in/xfox", + "CanContactMe": "true" }, "vk": { "Title": "Vkontakte", - "Socicon": "linkedin", - "Username": "@xfox", - "Url": "//linkedin.com/in/xfox" + "Socicon": "vkontakte", + "Username": "@xfox.mike", + "Url": "//vk.com/xfox.mike", + "CanContactMe": "true" }, "telegram": { "Title": "Telegram", - "Socicon": "linkedin", - "Username": "@xfox", - "Url": "//linkedin.com/in/xfox" + "Socicon": "telegram", + "Username": "@xfox111", + "Url": "//t.me/xfox111", + "CanContactMe": "true" }, "skype": { "Title": "Skype", - "Socicon": "linkedin", - "Username": "@xfox", - "Url": "//linkedin.com/in/xfox" + "Socicon": "skype", + "Username": "@mag48gordeev", + "Url": "//join.skype.com/invite/eVp6BISfcmNz", + "CanContactMe": "true" }, "twitter": { "Title": "Twitter", - "Socicon": "linkedin", - "Username": "@xfox", - "Url": "//linkedin.com/in/xfox" + "Socicon": "twitter", + "Username": "@xfox111", + "Url": "//twitter.com/xfox111", + "CanContactMe": "false" }, "twitch": { "Title": "Twitch", - "Socicon": "linkedin", - "Username": "@xfox", - "Url": "//linkedin.com/in/xfox" + "Socicon": "twitch", + "Username": "@xfox111", + "Url": "//twitch.com/xfox111", + "CanContactMe": "false" }, "youtube": { "Title": "YouTube", - "Socicon": "linkedin", - "Username": "@xfox", - "Url": "//linkedin.com/in/xfox" + "Socicon": "youtube", + "Username": "@UC3H2q5Ss_CR3wP_S1zV8joA", + "Url": "//www.youtube.com/channel/UC3H2q5Ss_CR3wP_S1zV8joA", + "CanContactMe": "false" }, "github": { "Title": "GitHub", - "Socicon": "linkedin", - "Username": "@xfox", - "Url": "//linkedin.com/in/xfox" + "Socicon": "github", + "Username": "@xfox111", + "Url": "//github.com/xfox111", + "CanContactMe": "false" } } \ No newline at end of file