Skip to content

Commit 9b5c59b

Browse files
committed
Links to users
1 parent 8564a29 commit 9b5c59b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+200
-13
lines changed

EPAM.MyBlog.DAL.DB/DAL.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@ public bool DeleteUser(string name)
134134
#region Posts
135135
public bool AddPost(Entities.PostText post, string login)
136136
{
137+
string[] split = post.Tags.Split(new Char[] { ' ', ','});
138+
for (int i = 0; i < split.Length; i++)
139+
{
140+
using (SqlConnection con = new SqlConnection(ConnectionString))
141+
{
142+
SqlCommand command = new SqlCommand("INSERT INTO dbo.Tags (Post_Id, Tag) VALUES (CAST(@ID AS NVARCHAR(36)), @Tag)", con);
143+
144+
command.Parameters.Add(new SqlParameter("@ID", post.Id));
145+
command.Parameters.Add(new SqlParameter("@Tag", split[i]));
146+
con.Open();
147+
command.ExecuteNonQuery();
148+
}
149+
}
150+
137151
using (SqlConnection con = new SqlConnection(ConnectionString))
138152
{
139153
SqlCommand command = new SqlCommand("INSERT INTO dbo.Posts (User_Name, Post_Id, Post_Title, Post_Text, Time) VALUES (@Login,CAST(@ID AS NVARCHAR(36)), @Title, @Text, @Time)", con);
@@ -181,17 +195,23 @@ public bool AddPost(Entities.PostText post, string login)
181195

182196
public Entities.PostText GetPostById(Guid Id)
183197
{
198+
StringBuilder s = new StringBuilder();
199+
200+
201+
184202
using (SqlConnection con = new SqlConnection(ConnectionString))
185203
{
186-
SqlCommand command = new SqlCommand("SELECT Post_Title, Post_Text, User_Name, Time FROM dbo.Posts WHERE Post_Id = @Id", con);
204+
SqlCommand command = new SqlCommand("SELECT Post_Id, Post_Title, Post_Text, User_Name, Time FROM dbo.Posts WHERE Post_Id = @Id", con);
187205
command.Parameters.Add(new SqlParameter("@Id", Id));
188206
con.Open();
189207
Entities.PostText post = new Entities.PostText() { Id = Id };
190208
int count = 0;
191209
var reader = command.ExecuteReader();
210+
string post_id = "";
192211

193212
while (reader.Read())
194213
{
214+
post_id = (string)reader["Post_Id"];
195215
post.Title = (string)reader["Post_Title"];
196216
post.Text = (string)reader["Post_Text"];
197217
post.Author = (string)reader["User_Name"];
@@ -204,6 +224,20 @@ public Entities.PostText GetPostById(Guid Id)
204224
}
205225
else
206226
{
227+
reader.Close();
228+
using (SqlConnection con2 = new SqlConnection(ConnectionString))
229+
{
230+
SqlCommand command2 = new SqlCommand("SELECT Tag FROM dbo.Tags WHERE Post_Id = @Id", con);
231+
command2.Parameters.Add(new SqlParameter("@Id", post_id));
232+
con2.Open();
233+
var reader2 = command2.ExecuteReader();
234+
while (reader2.Read())
235+
{
236+
s.Append((string)reader2["Tag"]);
237+
s.Append(", ");
238+
}
239+
}
240+
post.Tags = s.ToString();
207241
return post;
208242
}
209243

512 Bytes
Binary file not shown.
Binary file not shown.
512 Bytes
Binary file not shown.
4 KB
Binary file not shown.
512 Bytes
Binary file not shown.
Binary file not shown.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,5 @@ p {
129129
.table-condensed tbody
130130
{
131131
overflow:auto;
132+
max-height: 500px;
132133
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,15 @@ public ActionResult DeleteAc(ConfirmModel model)
166166
return View();
167167
}
168168

169-
public ActionResult Avatar()
169+
public ActionResult Avatar(string name)
170170
{
171-
var info = AvatarModel.GetInfo(User.Identity.Name);
171+
var info = AvatarModel.GetInfo(name);
172+
return PartialView(info);
173+
}
174+
175+
public ActionResult UserAvatar(string name)
176+
{
177+
var info = AvatarModel.GetInfo(name);
172178
return PartialView(info);
173179
}
174180

@@ -178,6 +184,13 @@ public ActionResult AboutMe()
178184
return View(info);
179185
}
180186

187+
public ActionResult UserInfo(string name)
188+
{
189+
var info = UserAboutModel.GetInfo(name);
190+
return View(info);
191+
}
192+
193+
181194
public ActionResult EditSex()
182195
{
183196
var info = UserAboutModel.GetInfo(User.Identity.Name);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public ActionResult AdminMenu()
2828
}
2929

3030

31+
[Authorize(Roles = "Moder")]
32+
public ActionResult PostComment()
33+
{
34+
return View(UserAdminModel.GetAllUsers());
35+
}
36+
3137
[Authorize(Roles = "Admin")]
3238
public ActionResult Users()
3339
{

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@
287287
<Content Include="Views\Account\EditAbout.cshtml" />
288288
<Content Include="Views\Files\EditInfoAvatar.cshtml" />
289289
<Content Include="Views\Account\Avatar.cshtml" />
290+
<Content Include="Views\Admin\PostComment.cshtml" />
291+
<Content Include="Views\Account\UserInfo.cshtml" />
292+
<Content Include="Views\Account\UserAvatar.cshtml" />
290293
</ItemGroup>
291294
<ItemGroup>
292295
<Folder Include="App_Data\" />

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

Whitespace-only changes.

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

Whitespace-only changes.

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,26 @@ public class PostModel
2828
public string Author { get { return author; } set { author = value; } }
2929
public DateTime Time { get { return time; } set { time = value; } }
3030

31+
[Display(Name = "Теги")]
32+
[Required(ErrorMessage = "Поле {0} не заполнено")]
33+
[StringLength(100, MinimumLength = 1, ErrorMessage = "Поле {0} должно быть от {2} до {1} символов")]
34+
public string Tags { get { return tags; } set { tags = value; } }
35+
3136
private string text;
3237
private string title;
3338
private string author;
3439
private Guid id;
3540
private DateTime time;
36-
41+
private string tags;
3742

3843
public static explicit operator Entities.PostText(PostModel Post)
3944
{
40-
return new Entities.PostText() { Id = Post.Id, Text = Post.Text, Title = Post.Title, Author = Post.Author, Time = Post.Time };
45+
return new Entities.PostText() { Id = Post.Id, Text = Post.Text, Title = Post.Title, Author = Post.Author, Time = Post.Time, Tags = Post.Tags };
4146
}
4247

4348
public static explicit operator PostModel(Entities.PostText Post)
4449
{
45-
return new PostModel() { Id = Post.Id, Text = Post.Text, Title = Post.Title, Author = Post.Author, Time = Post.Time };
50+
return new PostModel() { Id = Post.Id, Text = Post.Text, Title = Post.Title, Author = Post.Author, Time = Post.Time, Tags = Post.Tags };
4651
}
4752

4853

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@
4848
@Html.ActionLink("Изменить", "EditAbout", null, new { @class="btn btn-default"})
4949
</fieldset>
5050

51-
@Html.Action("Avatar")
51+
@Html.Action("Avatar", new { name = User.Identity.Name})
5252

5353

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
else
1313
{
1414
<div>
15-
<img src="@Url.Action("GetImage","Files", new { name = User.Identity.Name})" width="250" />
15+
<img src="@Url.Action("GetImage","Files", new { name = Model.Login })" width="250" />
1616
</div>
1717
}
1818

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@model EPAM.MyBlog.UI.Web.Models.AvatarModel
2+
3+
4+
<p>@Model.Login</p>
5+
6+
@if (Model.Avatar == null)
7+
{
8+
<div>
9+
<img src="~/Content/img/User-icon.png" />
10+
</div>
11+
}
12+
else
13+
{
14+
<div>
15+
<img src="@Url.Action("GetImage","Files", new { name = Model.Login })" width="250" />
16+
</div>
17+
}
18+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
@model EPAM.MyBlog.UI.Web.Models.UserAboutModel
2+
3+
@{
4+
ViewBag.Title = "UserInfo";
5+
}
6+
7+
<fieldset>
8+
<legend>@Model.Login</legend>
9+
10+
<div class="display-label">
11+
@Html.DisplayNameFor(model => model.Sex)
12+
13+
</div>
14+
@if(Model.Sex != null){
15+
<div class="display-field">
16+
@Html.DisplayFor(model => model.Sex)
17+
18+
</div>
19+
}
20+
21+
<div class="display-label">
22+
@Html.DisplayNameFor(model => model.Birthday)
23+
24+
</div>
25+
@if(Model.Birthday != null){
26+
<div class="display-field">
27+
@Html.DisplayFor(model => model.Birthday)
28+
</div>
29+
}
30+
31+
<div class="display-label">
32+
@Html.DisplayNameFor(model => model.Name)
33+
</div>
34+
@if(Model.Name != null){
35+
<div class="display-field">
36+
@Html.DisplayFor(model => model.Name)
37+
</div>
38+
}
39+
40+
<div class="display-label">
41+
@Html.DisplayNameFor(model => model.AboutMe)
42+
</div>
43+
@if(Model.AboutMe != null){
44+
<div class="display-field">
45+
@Html.DisplayFor(model => model.AboutMe)
46+
</div>
47+
}
48+
49+
</fieldset>
50+
51+
@Html.Action("UserAvatar", new {name = Model.Login})
52+
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Модерирование <span class="caret"></span></a>
22
<ul class="dropdown-menu" role="menu">
3-
<li><a href="@Url.Action("Posts", "Admin")">Посты</a></li>
4-
<li><a href="@Url.Action("Comments", "Admin")">Посты</a></li>
3+
<li><a href="@Url.Action("PostComment", "Admin")">Посты/Комментарии</a></li>
54
</ul>
65
</li>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@model IEnumerable<EPAM.MyBlog.UI.Web.Models.UserAdminModel>
2+
3+
<table class="table table-condensed">
4+
<tr>
5+
<th>
6+
@Html.DisplayNameFor(model => model.Name)
7+
</th>
8+
<th>
9+
@Html.DisplayNameFor(model => model.Email)
10+
</th>
11+
<th>
12+
@Html.DisplayNameFor(model => model.Role)
13+
</th>
14+
<th></th>
15+
</tr>
16+
<tbody>
17+
@foreach (var item in Model) {
18+
<tr>
19+
<td>
20+
@Html.DisplayFor(modelItem => item.Name)
21+
</td>
22+
<td>
23+
@Html.DisplayFor(modelItem => item.Email)
24+
</td>
25+
<td>
26+
@Html.DisplayFor(modelItem => item.Role)
27+
</td>
28+
<td>
29+
@Html.ActionLink("Посты", "UserPosts", new { name=item.Name }) |
30+
@Html.ActionLink("Комменты", "UserComments", new { name=item.Name }) |
31+
</td>
32+
</tr>
33+
}
34+
</tbody>
35+
</table>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@Html.DisplayFor(model => model.Text)
1212
</div>
1313
<div>
14-
Автор: @Html.DisplayFor(model => model.Author)
14+
Автор: @Html.ActionLink(Model.Author, "UserInfo", "Account",new {name = Model.Author}, null)
1515
</div>
1616
<div>
1717
Дата: @Html.DisplayFor(model => model.Time)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
@foreach (var item in Model) {
2323
<tr>
2424
<td>
25-
@Html.DisplayFor(modelItem => item.Name)
25+
@Html.ActionLink(item.Name, "UserInfo","Account",new {name = item.Name}, null)
2626
</td>
2727
<td>
2828
@Html.DisplayFor(modelItem => item.Email)

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,20 @@
2828
@Html.ValidationMessageFor(model => model.Text)
2929
</div>
3030

31+
<div class="editor-label">
32+
@Html.LabelFor(model => model.Tags)
33+
</div>
34+
<div class="editor-field">
35+
@Html.EditorFor(model => model.Tags)
36+
@Html.ValidationMessageFor(model => model.Tags)
37+
</div>
38+
3139
<p>
3240
<input type="submit" value="Save" />
3341
</p>
3442
</fieldset>
3543
}
3644

3745
<div>
38-
@Html.ActionLink("Back to List", "Index")
46+
@Html.ActionLink("К списку записей", "Index")
3947
</div>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
@Html.ValidationMessageFor(model => model.Text)
2424
</div>
2525

26+
<div class="editor-label">
27+
@Html.LabelFor(model => model.Tags)
28+
</div>
29+
<div class="editor-field">
30+
@Html.EditorFor(model => model.Tags)
31+
@Html.ValidationMessageFor(model => model.Tags)
32+
</div>
2633
<p>
2734
<input type="submit" value="Создать" />
2835
</p>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
<div>
1010
@Html.DisplayFor(model => model.Text)
1111
</div>
12+
<div>
13+
Теги: @Html.DisplayFor(model => model.Tags)
14+
</div>
1215
<div>
1316
Автор: @Html.DisplayFor(model => model.Author)
1417
</div>
512 Bytes
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

EPAM.MyBlog.UI.Web/bin/Entities.dll

512 Bytes
Binary file not shown.

EPAM.MyBlog.UI.Web/bin/Entities.pdb

4 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

EPAM.MyBlog.v11.suo

-12 KB
Binary file not shown.

Entities/PostText.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ public class PostText
1313
public string Title { get { return title; } set { title = value; } }
1414
public string Author { get { return author; } set { author = value; } }
1515
public DateTime Time { get { return time; } set { time = value; } }
16+
public string Tags { get { return tags; } set { tags = value; } }
1617

1718
private string text;
1819
private string title;
1920
private string author;
2021
private Guid id;
2122
private DateTime time;
23+
private string tags;
2224

2325
public PostText()
2426
{

Entities/bin/Debug/Entities.dll

512 Bytes
Binary file not shown.

Entities/bin/Debug/Entities.pdb

4 KB
Binary file not shown.

Entities/obj/Debug/Entities.csproj.FileListAbsolute.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ C:\Users\Jem\Documents\Visual Studio 2012\Projects\Blog\Entities\bin\Debug\log4n
1010
C:\Users\Jem\Documents\Visual Studio 2012\Projects\Blog\Entities\bin\Debug\log4net.xml
1111
C:\Users\Jem\Documents\Visual Studio 2012\Projects\Blog\Entities\obj\Debug\Entities.dll
1212
C:\Users\Jem\Documents\Visual Studio 2012\Projects\Blog\Entities\obj\Debug\Entities.pdb
13+
C:\Users\Jem\Documents\Visual Studio 2012\Projects\Blog\Entities\obj\Debug\Entities.csprojResolveAssemblyReference.cache

Entities/obj/Debug/Entities.dll

512 Bytes
Binary file not shown.

Entities/obj/Debug/Entities.pdb

4 KB
Binary file not shown.

0 commit comments

Comments
 (0)