Skip to content

Commit e3e3c66

Browse files
committed
Comment problems
1 parent bbe505a commit e3e3c66

24 files changed

+151
-24
lines changed

EPAM.MyBlog.DAL.DB/DAL.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,5 +783,50 @@ public IEnumerable<string> GetTopTags()
783783
return Tags;
784784
}
785785
}
786+
787+
public bool CheckFavorite(string name, Guid Id)
788+
{
789+
using (SqlConnection con = new SqlConnection(ConnectionString))
790+
{
791+
SqlCommand command = new SqlCommand("SELECT COUNT(*) AS C FROM Blog.dbo.Favorite WHERE Post_Id = @Id AND Login=@Login", con);
792+
command.Parameters.Add(new SqlParameter("@Id", Id));
793+
command.Parameters.Add(new SqlParameter("@Login", name));
794+
con.Open();
795+
var reader = command.ExecuteReader();
796+
int count = 0;
797+
while (reader.Read())
798+
{
799+
count = (int)reader["C"];
800+
}
801+
if (count > 0)
802+
{
803+
return true;
804+
}
805+
else
806+
{
807+
return false;
808+
}
809+
}
810+
}
811+
812+
public bool AddFavorite(string name, Guid Id)
813+
{
814+
using (SqlConnection con = new SqlConnection(ConnectionString))
815+
{
816+
SqlCommand command = new SqlCommand("INSERT INTO Blog.dbo.Favorite (Blog.dbo.Favorite.Login, Blog.dbo.Favorite.Post_Id) VALUES (@Login, @Id)", con);
817+
command.Parameters.Add(new SqlParameter("@Id", Id));
818+
command.Parameters.Add(new SqlParameter("@Login", name));
819+
con.Open();
820+
int count = command.ExecuteNonQuery();
821+
if (count > 0)
822+
{
823+
return true;
824+
}
825+
else
826+
{
827+
return false;
828+
}
829+
}
830+
}
786831
}
787832
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

EPAM.MyBlog.UI.Web/Content/css/style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,9 @@ p {
130130
{
131131
overflow:auto;
132132
max-height: 500px;
133+
}
134+
135+
.post{
136+
margin-bottom: 40px;
137+
margin-top: 40px;
133138
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ public ActionResult Users()
4040
return View(UserAdminModel.GetAllUsers());
4141
}
4242

43+
[HttpPost]
44+
public ActionResult Users(string action)
45+
{
46+
switch (action)
47+
{
48+
case "addUser":
49+
UserAdminModel.AddUser();
50+
break;
51+
case "addModer":
52+
UserAdminModel.AddModer();
53+
break;
54+
case "addAdmin":
55+
UserAdminModel.AddAdmin();
56+
break;
57+
case "Delete":
58+
break;
59+
default:
60+
break;
61+
}
62+
63+
return View(UserAdminModel.GetAllUsers());
64+
}
4365

4466
[Authorize(Roles = "Admin")]
4567
public ActionResult UserPosts(string name)

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ public class CommentController : Controller
1212
//
1313
// GET: /Comment/
1414

15-
public ActionResult AddComment(Guid Post_ID)
15+
public ActionResult AddComment(Guid Post_Id)
1616
{
17-
var list = CommentModel.GetAllComments(Post_ID);
17+
var list = CommentModel.GetAllComments(Post_Id);
1818
ViewData["List"] = list;
19+
ViewData["ID"] = Post_Id;
1920
return PartialView();
2021
}
2122

22-
23+
[ChildActionOnly]
2324
[ValidateAntiForgeryToken]
2425
[HttpPost]
2526
public ActionResult AddComment(CommentModel comment)

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,24 @@ public ActionResult MyPosts()
5050

5151
public ActionResult Posts(Guid Id)
5252
{
53+
ViewData["Check"] = PostModel.CheckFavorite(User.Identity.Name, Id).ToString();
5354
var post = PostModel.GetPostById(Id);
5455
return View(post);
5556
}
5657

58+
[HttpPost]
59+
public ActionResult Posts(PostModel model, string action)
60+
{
61+
if(action == "AddFav")
62+
{
63+
PostModel.AddFavorite(User.Identity.Name, model.Id);
64+
return RedirectToAction("Posts", new {Id = model.Id});
65+
}
66+
else
67+
{
68+
return RedirectToAction("Posts", new {Id = model.Id});
69+
}
70+
}
5771

5872
public ActionResult Edit(Guid Id)
5973
{

EPAM.MyBlog.UI.Web/Logs/Debug/2015.01.14.log

Whitespace-only changes.

EPAM.MyBlog.UI.Web/Logs/Errors/2015.01.14.log

Whitespace-only changes.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,15 @@ internal static bool Delete(Guid id)
9090
{
9191
return GetDAL.dal.DeletePostById(id);
9292
}
93+
94+
internal static bool CheckFavorite(string name, Guid Id)
95+
{
96+
return GetDAL.dal.CheckFavorite(name, Id);
97+
}
98+
99+
internal static bool AddFavorite(string name, Guid Id)
100+
{
101+
return GetDAL.dal.AddFavorite(name, Id);
102+
}
93103
}
94104
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,20 @@ internal static IEnumerable<UserAdminModel> GetAllUsers()
3838
}
3939
return Users;
4040
}
41+
42+
internal static void AddUser()
43+
{
44+
throw new NotImplementedException();
45+
}
46+
47+
internal static void AddModer()
48+
{
49+
throw new NotImplementedException();
50+
}
51+
52+
internal static void AddAdmin()
53+
{
54+
throw new NotImplementedException();
55+
}
4156
}
4257
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
}
4343
</tbody>
4444
</table>
45-
<input type="submit" class="btn btn-success" value="Сделать User'ом" id="addUser"/>
46-
<input type="submit" class="btn btn-success" value="Сделать Moder'ом" id="addModer"/>
47-
<input type="submit" class="btn btn-success" value="Сделать Admin'ом" id="addAdmin"/>
48-
<input type="submit" class="btn btn-success" value="Удалить" id="Delete"/>
45+
<button type="submit" name="action" value="addUser" id="addUser"> Сделать Userом </button>
46+
<button type="submit" name="action" value="addModer" id="addModer">Сделать Moderом </button>
47+
<button type="submit" name="action" value="addAdmin" id="addAdmin">Сделать Adminом </button>
48+
<button type="submit" name="action" value="Delete" id="Delete">Удалить </button>
4949
</form>

EPAM.MyBlog.UI.Web/Views/Comment/AddComment.cshtml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,23 @@
1313
<div>Сказал: @item.Text </div>
1414
}
1515

16-
@using (Html.BeginForm()) {
16+
@using (Html.BeginForm("AddComment", "Comment", FormMethod.Post)) {
1717
@Html.ValidationSummary(true)
1818
@Html.AntiForgeryToken()
1919

20+
2021
<fieldset>
2122

22-
23+
@Html.HiddenFor(model => model.Post_ID, new { @Value = ViewData["ID"] });
24+
25+
2326
<div class="editor-label">
2427
@Html.LabelFor(model => model.Text)
2528
</div>
2629
<div class="editor-field">
2730
@Html.EditorFor(model => model.Text)
2831
@Html.ValidationMessageFor(model => model.Text)
29-
</div>
32+
</div>
3033
<p>
3134
<input type="submit" value="Добавить" />
3235
</p>

EPAM.MyBlog.UI.Web/Views/Post/Posts.cshtml

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,35 @@
33
@{
44
ViewBag.Title = "Posts";
55
}
6-
7-
<legend>@Html.DisplayFor(model => model.Title)</legend>
8-
9-
<div>
6+
@using (Html.BeginForm("Posts", "Post", FormMethod.Post))
7+
{
8+
<div class ="row">
9+
<div class="col-md-12 col-sm-12 col-lg-12 col-sx-12 title">@Html.DisplayFor(model => model.Title)</div>
10+
</div>
11+
<div class ="row">
12+
<div class="col-md-12 col-sm-12 col-lg-12 col-sx-12 post">
1013
@Html.DisplayFor(model => model.Text)
1114
</div>
15+
</div>
1216
<div>
13-
Теги: @Html.DisplayFor(model => model.Tags)
17+
<p>Теги: @Html.DisplayFor(model => model.Tags)</p>
1418
</div>
15-
<div>
16-
Автор: @Html.DisplayFor(model => model.Author)
17-
</div>
18-
<div>
19-
Дата: @Html.DisplayFor(model => model.Time)
20-
</div>
19+
<div>
20+
<p>Автор: @Html.ActionLink(Model.Author,"UserInfo", "Account", new {name = Model.Author}, null)</p>
21+
</div>
22+
<div>
23+
<p>Дата: @Html.DisplayFor(model => model.Time)</p>
24+
</div>
25+
if((string)ViewData["Check"] == "True")
26+
{
27+
<button type="submit" name="action" value="AddFav" hidden="hidden">В избранное</button>
28+
<p>Данная статья находится в @Html.ActionLink(" избранном","Favorite", "Post")</p>
29+
}
30+
else{
31+
<button type="submit" name="action" value="AddFav">В избранное</button>
32+
}
33+
}
34+
35+
@{ Html.RenderAction("AddComment", "Comment", new { Post_Id = Model.Id });}
2136

22-
<p>
23-
</p>
24-
@Html.Action("AddComment", "Comment", new { Post_Id = Model.Id })
2537
@Html.ActionLink("К списку", "Index", "Post")
Binary file not shown.
Binary file not shown.
1.5 KB
Binary file not shown.
-12 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

EPAM.MyBlog.v11.suo

-142 KB
Binary file not shown.

0 commit comments

Comments
 (0)