Skip to content

Commit 4ded0fe

Browse files
committed
Add News
1 parent 9b5c59b commit 4ded0fe

20 files changed

+93
-3
lines changed

EPAM.MyBlog.DAL.DB/DAL.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public bool AddPost(Entities.PostText post, string login)
145145
command.Parameters.Add(new SqlParameter("@Tag", split[i]));
146146
con.Open();
147147
command.ExecuteNonQuery();
148+
con.Close();
148149
}
149150
}
150151

@@ -257,6 +258,31 @@ public bool EditPostById(Entities.PostText post)
257258
int count = command.ExecuteNonQuery();
258259
if (count > 0)
259260
{
261+
using (SqlConnection con2 = new SqlConnection(ConnectionString))
262+
{
263+
SqlCommand command2 = new SqlCommand("DELETE FROM dbo.Tags WHERE Post_Id = @ID", con);
264+
265+
command2.Parameters.Add(new SqlParameter("@ID", post.Id));
266+
con2.Open();
267+
command2.ExecuteNonQuery();
268+
con2.Close();
269+
}
270+
271+
string[] split = post.Tags.Split(new Char[] { ' ', ',' });
272+
for (int i = 0; i < split.Length; i++)
273+
{
274+
using (SqlConnection con2 = new SqlConnection(ConnectionString))
275+
{
276+
SqlCommand command2 = new SqlCommand("INSERT INTO dbo.Tags (Post_Id, Tag) VALUES (CAST(@ID AS NVARCHAR(36)), @Tag)", con);
277+
278+
command2.Parameters.Add(new SqlParameter("@ID", post.Id));
279+
command2.Parameters.Add(new SqlParameter("@Tag", split[i]));
280+
con2.Open();
281+
command2.ExecuteNonQuery();
282+
con2.Close();
283+
}
284+
}
285+
260286
return true;
261287
}
262288
else
@@ -276,6 +302,16 @@ public bool DeletePostById(Guid Id)
276302
int count = command.ExecuteNonQuery();
277303
if (count > 0)
278304
{
305+
using (SqlConnection con2 = new SqlConnection(ConnectionString))
306+
{
307+
SqlCommand command2 = new SqlCommand("DELETE FROM dbo.Tags WHERE Post_Id = @ID", con);
308+
309+
command2.Parameters.Add(new SqlParameter("@ID", Id));
310+
con2.Open();
311+
command2.ExecuteNonQuery();
312+
con2.Close();
313+
}
314+
279315
return true;
280316
}
281317
else
@@ -667,5 +703,26 @@ public bool AddAvatar(Entities.Avatar avatar)
667703
}
668704
}
669705
}
706+
707+
public IEnumerable<Entities.PresentPost> GetAllPostsTitle()
708+
{
709+
using (SqlConnection con = new SqlConnection(ConnectionString))
710+
{
711+
SqlCommand command = new SqlCommand("SELECT Post_Title, Post_Id FROM dbo.Posts", con);
712+
con.Open();
713+
var reader = command.ExecuteReader();
714+
715+
while (reader.Read())
716+
{
717+
yield return new Entities.PresentPost()
718+
{
719+
Id = new Guid((string)reader["Post_Id"]),
720+
Title = (string)reader["Post_Title"]
721+
};
722+
723+
}
724+
}
725+
726+
}
670727
}
671728
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

EPAM.MyBlog.UI.Web/Controllers/PostController.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ public ActionResult Comments(Guid id)
111111
//
112112
return View();
113113
}
114-
114+
115+
public ActionResult News()
116+
{
117+
var posts = PresentPostModel.GetAllPostsTitle();
118+
return View(posts);
119+
}
115120
}
116121
}

EPAM.MyBlog.UI.Web/EPAM.MyBlog.UI.Web.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@
290290
<Content Include="Views\Admin\PostComment.cshtml" />
291291
<Content Include="Views\Account\UserInfo.cshtml" />
292292
<Content Include="Views\Account\UserAvatar.cshtml" />
293+
<Content Include="Views\Post\News.cshtml" />
293294
</ItemGroup>
294295
<ItemGroup>
295296
<Folder Include="App_Data\" />

EPAM.MyBlog.UI.Web/Models/PresentPostModel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ internal static IEnumerable<PresentPostModel> GetAllPostsTitle(string user)
3838
return TitleList;
3939
}
4040

41+
internal static IEnumerable<PresentPostModel> GetAllPostsTitle()
42+
{
43+
var list = GetDAL.dal.GetAllPostsTitle().ToList();
44+
List<PresentPostModel> TitleList = new List<PresentPostModel>();
45+
foreach (var item in list)
46+
{
47+
TitleList.Add((PresentPostModel)item);
48+
}
49+
return TitleList;
50+
}
4151

4252
}
4353
}

EPAM.MyBlog.UI.Web/Views/Account/MenuState.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ul class="dropdown-menu" role="menu">
77
<li><a href="@Url.Action("Index", "Post")">Мои посты</a></li>
88
<li><a href="@Url.Action("Favorite", "Post")">Избранное</a></li>
9-
<li><a href="#">Лента</a></li>
9+
<li><a href="@Url.Action("News", "Post")">Лента</a></li>
1010
</ul>
1111
</li>
1212
<li class="dropdown">

EPAM.MyBlog.UI.Web/Views/Admin/PostComment.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@foreach (var item in Model) {
1818
<tr>
1919
<td>
20-
@Html.DisplayFor(modelItem => item.Name)
20+
@Html.ActionLink(item.Name, "UserInfo","Account",new {name = item.Name}, null)
2121
</td>
2222
<td>
2323
@Html.DisplayFor(modelItem => item.Email)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@model IEnumerable<EPAM.MyBlog.UI.Web.Models.PresentPostModel>
2+
@{
3+
WebGrid grid = new WebGrid(Model);
4+
}
5+
6+
<h2> Лента </h2>
7+
8+
@grid.GetHtml(columns: new [] {
9+
grid.Column("Title",header: " "),
10+
grid.Column("",
11+
header: "",
12+
format: @<text>
13+
@Html.ActionLink("Читать", "Posts", new { id=item.Id })
14+
</text>
15+
)
16+
})
17+
Binary file not shown.
Binary file not shown.
512 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
512 Bytes
Binary file not shown.
Binary file not shown.

EPAM.MyBlog.v11.suo

3 KB
Binary file not shown.

0 commit comments

Comments
 (0)