Skip to content

Commit 6905680

Browse files
committed
Users actions
1 parent e3e3c66 commit 6905680

20 files changed

+105
-18
lines changed

EPAM.MyBlog.DAL.DB/DAL.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,5 +828,72 @@ public bool AddFavorite(string name, Guid Id)
828828
}
829829
}
830830
}
831+
832+
833+
public void AddUser(List<string> names)
834+
{
835+
foreach (var item in names)
836+
{
837+
838+
using (SqlConnection con = new SqlConnection(ConnectionString))
839+
{
840+
SqlCommand command = new SqlCommand("UPDATE dbo.Users SET Role_Id = '3' WHERE Login = @Login", con);
841+
command.Parameters.Add(new SqlParameter("@Login", item));
842+
con.Open();
843+
command.ExecuteNonQuery();
844+
con.Close();
845+
}
846+
847+
}
848+
}
849+
850+
public void AddModer(List<string> names)
851+
{
852+
foreach (var item in names)
853+
{
854+
855+
using (SqlConnection con = new SqlConnection(ConnectionString))
856+
{
857+
SqlCommand command = new SqlCommand("UPDATE dbo.Users SET Role_Id = '2' WHERE Login = @Login", con);
858+
command.Parameters.Add(new SqlParameter("@Login", item));
859+
con.Open();
860+
command.ExecuteNonQuery();
861+
con.Close();
862+
}
863+
864+
}
865+
}
866+
867+
public void AddAdmin(List<string> names)
868+
{
869+
foreach (var item in names)
870+
{
871+
using (SqlConnection con = new SqlConnection(ConnectionString))
872+
{
873+
SqlCommand command = new SqlCommand("UPDATE dbo.Users SET Role_Id = '1' WHERE Login = @Login", con);
874+
command.Parameters.Add(new SqlParameter("@Login", item));
875+
con.Open();
876+
command.ExecuteNonQuery();
877+
con.Close();
878+
}
879+
}
880+
}
881+
882+
public void DeleteUser(List<string> names)
883+
{
884+
foreach (var item in names)
885+
{
886+
using (SqlConnection con = new SqlConnection(ConnectionString))
887+
{
888+
SqlCommand command = new SqlCommand("Delete FROM dbo.Users WHERE Login = @Login", con);
889+
command.Parameters.Add(new SqlParameter("@Login", item));
890+
con.Open();
891+
command.ExecuteNonQuery();
892+
con.Close();
893+
}
894+
}
895+
}
896+
897+
831898
}
832899
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,32 @@ public ActionResult Users()
4343
[HttpPost]
4444
public ActionResult Users(string action)
4545
{
46+
string exist;
47+
var list = new List<UserAdminModel>(UserAdminModel.GetAllUsers());
48+
List<string> names = new List<string>();
49+
50+
foreach (var item in list)
51+
{
52+
exist = Request.Form[item.Name];
53+
if (exist == "on")
54+
{
55+
names.Add(item.Name);
56+
}
57+
}
58+
4659
switch (action)
4760
{
4861
case "addUser":
49-
UserAdminModel.AddUser();
62+
UserAdminModel.AddUser(names);
5063
break;
5164
case "addModer":
52-
UserAdminModel.AddModer();
65+
UserAdminModel.AddModer(names);
5366
break;
5467
case "addAdmin":
55-
UserAdminModel.AddAdmin();
68+
UserAdminModel.AddAdmin(names);
5669
break;
5770
case "Delete":
71+
UserAdminModel.DeleteUsers(names);
5872
break;
5973
default:
6074
break;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class CommentController : Controller
1111
{
1212
//
1313
// GET: /Comment/
14-
14+
1515
public ActionResult AddComment(Guid Post_Id)
1616
{
1717
var list = CommentModel.GetAllComments(Post_Id);
@@ -20,7 +20,7 @@ public ActionResult AddComment(Guid Post_Id)
2020
return PartialView();
2121
}
2222

23-
[ChildActionOnly]
23+
2424
[ValidateAntiForgeryToken]
2525
[HttpPost]
2626
public ActionResult AddComment(CommentModel comment)
@@ -34,18 +34,18 @@ public ActionResult AddComment(CommentModel comment)
3434
CommentModel.Comments.Add(comment);
3535
ViewData["List"] = CommentModel.Comments;
3636
ModelState.Clear();
37-
return PartialView();
37+
return RedirectToAction("Posts", "Post", new { Id = comment.Post_ID });
3838
}
3939
else
4040
{
4141
ViewData["List"] = CommentModel.Comments;
42-
return PartialView(comment);
42+
return RedirectToAction("Posts", "Post", new { Id = comment.Post_ID });
4343
}
4444
}
4545
else
4646
{
4747
ViewData["List"] = CommentModel.Comments;
48-
return PartialView(comment);
48+
return RedirectToAction("Posts", "Post", new { Id = comment.Post_ID });
4949
}
5050
}
5151
}

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

Whitespace-only changes.

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

Whitespace-only changes.

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,24 @@ internal static IEnumerable<UserAdminModel> GetAllUsers()
3939
return Users;
4040
}
4141

42-
internal static void AddUser()
42+
internal static void AddUser(List<string> names)
4343
{
44-
throw new NotImplementedException();
44+
GetDAL.dal.AddUser(names);
4545
}
4646

47-
internal static void AddModer()
47+
internal static void AddModer(List<string> names)
4848
{
49-
throw new NotImplementedException();
49+
GetDAL.dal.AddModer(names);
5050
}
5151

52-
internal static void AddAdmin()
52+
internal static void AddAdmin(List<string> names)
5353
{
54-
throw new NotImplementedException();
54+
GetDAL.dal.AddAdmin(names);
55+
}
56+
57+
internal static void DeleteUsers(List<string> names)
58+
{
59+
GetDAL.dal.DeleteUser(names);
5560
}
5661
}
5762
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
<p>
44
@Html.ActionLink("Create New", "Create")
55
</p>
6-
7-
<form action="@Url.Action("ChangeUser")">
6+
@using (Html.BeginForm("Users", "Admin", FormMethod.Post))
7+
{
8+
//<form action="@Url.Action("ChangeUser")">
89
<table class="table table-condensed">
910
<tr>
1011
<th>
@@ -46,4 +47,4 @@
4647
<button type="submit" name="action" value="addModer" id="addModer">Сделать Moderом </button>
4748
<button type="submit" name="action" value="addAdmin" id="addAdmin">Сделать Adminом </button>
4849
<button type="submit" name="action" value="Delete" id="Delete">Удалить </button>
49-
</form>
50+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
}
3333
}
3434

35-
@{ Html.RenderAction("AddComment", "Comment", new { Post_Id = Model.Id });}
35+
@Html.Action("AddComment", "Comment", new { Post_Id = Model.Id })
3636

3737
@Html.ActionLink("К списку", "Index", "Post")
1.5 KB
Binary file not shown.
Binary file not shown.
512 Bytes
Binary file not shown.
14 KB
Binary file not shown.
512 Bytes
Binary file not shown.
Binary file not shown.

EPAM.MyBlog.v11.suo

10.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)