Skip to content

Commit 7f9e8a2

Browse files
committed
add contacts section to about me page
1 parent 42aa1e7 commit 7f9e8a2

20 files changed

+33
-19
lines changed

Blog/Blog/Controllers/BlogController.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Blog.Models;
99
using Blog.Models.Repositories;
1010
using Blog.Models.ViewModels;
11+
using Microsoft.AspNetCore.Identity;
1112

1213
namespace Blog.Controllers
1314
{
@@ -62,7 +63,7 @@ private IEnumerable<Post> GetPosts(string tag = "", string title = "")
6263
return postsRepository.Get();
6364
}
6465

65-
public IActionResult Details(int? id)
66+
public IActionResult Post(int? id)
6667
{
6768
if (id == null)
6869
return NotFound();
@@ -77,8 +78,11 @@ public IActionResult Details(int? id)
7778
Comments = commentRepository.GetByPost(post.Id)
7879
};
7980

80-
++post.Views;
81-
postsRepository.SaveAsync();
81+
if (!User.IsInRole(Roles.Administrator) && !User.IsInRole(Roles.Editor))
82+
{
83+
++post.Views;
84+
postsRepository.SaveAsync();
85+
}
8286
return View(view);
8387
}
8488

Blog/Blog/Views/AboutMe/Index.cshtml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@
4848
<h3>@Model.Title</h3>
4949
</div>
5050
<p>@Html.Raw(@Model.Description)</p>
51+
52+
@if (Model.Contacts != null)
53+
{
54+
<div id="contacts" class="mt-5">
55+
<h4>Contacts</h4>
56+
<hr />
57+
<p>Email: <a href="mailto:@Model.Contacts?.Email">@Model.Contacts?.Email</a></p>
58+
<p>Phone: <a href="tel:@Model.Contacts?.Phone">@Model.Contacts?.Phone</a></p>
59+
<p>City: @Model.Contacts?.City</p>
60+
<p>Country: @Model.Contacts?.Country</p>
61+
</div>
62+
}
5163
</div>
5264
</section>
5365

Blog/Blog/Views/Blog/Index.cshtml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
</div>
2222
</section>
2323

24-
25-
2624
<section id="posts">
2725
<div class="container">
2826
<div class="row">
@@ -53,12 +51,12 @@
5351
<p class="card-text mb-2"><small>@post.Tags</small></p>
5452
<hr class="my-2 w-25 mx-0 mr-auto" />
5553
<div class="mt-3">
56-
<a asp-controller="Blog" asp-action="Details" asp-route-id="@post.Id" class="text-dark"><h4 class="card-title">@post.Title</h4></a>
54+
<a asp-controller="Blog" asp-action="Post" asp-route-id="@post.Id" class="text-dark"><h4 class="card-title">@post.Title</h4></a>
5755
<p class="card-text mb-4">@post.Excerpt</p>
5856
<div class="row col-12">
5957
<p class="card-text"><small class="text-muted">Posted: @post.Created.ToShortDateString()</small></p>
6058
<p class="card-text ml-2"><small class="text-muted"><i class="fas fa-eye"></i> @post.Views</small></p>
61-
<a asp-controller="Blog" asp-action="Details" asp-route-id="@post.Id" class="ml-auto text-dark float-right">Show more &#x2192;</a>
59+
<a asp-controller="Blog" asp-action="Post" asp-route-id="@post.Id" class="ml-auto text-dark float-right">Show more &#x2192;</a>
6260
</div>
6361
</div>
6462
</div>

Blog/Blog/Views/Comments/Details.cshtml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,18 @@
1010
<h4>Comment</h4>
1111
<hr />
1212
<dl class="row">
13+
@if (Model.Post != null)
14+
{
15+
<dt class="col-sm-2">
16+
<label>Post Title</label>
17+
</dt>
18+
<dd class="col-sm-10">
19+
<a href="/Blog/Post/@Model.PostId">@Html.DisplayFor(model => model.Post.Title)</a>
20+
</dd>
21+
}
22+
1323
<dt class="col-sm-2">
14-
@Html.DisplayNameFor(model => model.UserName)
24+
<label>User Name</label>
1525
</dt>
1626
<dd class="col-sm-10">
1727
@Html.DisplayFor(model => model.UserName)
@@ -23,16 +33,6 @@
2333
@Html.DisplayFor(model => model.Message)
2434
</dd>
2535

26-
@if (Model.Post != null)
27-
{
28-
<dt class="col-sm-2">
29-
@Html.DisplayNameFor(model => model.Post.Title)
30-
</dt>
31-
<dd class="col-sm-10">
32-
@Html.DisplayFor(model => model.Post.Title)
33-
</dd>
34-
}
35-
3636
<dt class="col-sm-2">
3737
@Html.DisplayNameFor(model => model.Created)
3838
</dt>

Blog/Blog/Views/Posts/Details.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@Html.DisplayNameFor(model => model.Title)
1515
</dt>
1616
<dd class="col-sm-10">
17-
@Html.DisplayFor(model => model.Title)
17+
<a href="/Blog/Post/@Model.Id">@Html.DisplayFor(model => model.Title)</a>
1818
</dd>
1919
<dt class="col-sm-2">
2020
@Html.DisplayNameFor(model => model.Excerpt)
110 KB
Loading
110 KB
Loading
Binary file not shown.
110 KB
Loading

0 commit comments

Comments
 (0)