diff --git a/Controllers/categoriesController.cs b/Controllers/categoriesController.cs index 555d33a..295134a 100644 --- a/Controllers/categoriesController.cs +++ b/Controllers/categoriesController.cs @@ -45,7 +45,7 @@ namespace WebApplication1.Controllers { if (Session["User"] != null) { - if (Convert.ToInt32(Session["Userrole"]) == 1) + if (Convert.ToInt32(Session["Userrole"]) > 0) { return View(); } @@ -81,7 +81,7 @@ namespace WebApplication1.Controllers { if (Session["User"] != null) { - if (Convert.ToInt32(Session["Userrole"]) == 1) + if (Convert.ToInt32(Session["Userrole"]) > 0) { if (id == null) { @@ -124,7 +124,7 @@ namespace WebApplication1.Controllers { if (Session["User"] != null) { - if (Convert.ToInt32(Session["Userrole"]) == 1) + if (Convert.ToInt32(Session["Userrole"]) > 0) { if (id == null) { diff --git a/Controllers/newsController.cs b/Controllers/newsController.cs index 945836d..264a34e 100644 --- a/Controllers/newsController.cs +++ b/Controllers/newsController.cs @@ -128,7 +128,10 @@ namespace WebApplication1.Controllers if (Request.Files.Count > 0) { setLists(); - + /* + string x = news.tag; + var y = news.tag[1]; + */ if (news.title != null && news.link != null && news.cat != null && news.tag != null) { var image = Request.Files[0]; @@ -202,7 +205,7 @@ namespace WebApplication1.Controllers { return HttpNotFound(); } - else if ( news.userID == Convert.ToInt32(Session["Userid"]) || Convert.ToInt32(Session["Userrole"]) == 1) + else if ( news.userID == Convert.ToInt32(Session["Userid"]) || Convert.ToInt32(Session["Userrole"]) > 0) { return View(news); } @@ -245,7 +248,7 @@ namespace WebApplication1.Controllers { return HttpNotFound(); } - else if (news.userID == Convert.ToInt32(Session["Userid"]) || Convert.ToInt32(Session["Userrole"]) == 1) + else if (news.userID == Convert.ToInt32(Session["Userid"]) || Convert.ToInt32(Session["Userrole"]) > 0) { return View(news); } diff --git a/Controllers/tagsController.cs b/Controllers/tagsController.cs index 88460bc..66d0aa8 100644 --- a/Controllers/tagsController.cs +++ b/Controllers/tagsController.cs @@ -44,7 +44,7 @@ namespace WebApplication1.Models { if (Session["User"] != null) { - if (Convert.ToInt32(Session["Userrole"]) == 1) + if (Convert.ToInt32(Session["Userrole"]) > 0) { return View(); } @@ -80,7 +80,7 @@ namespace WebApplication1.Models { if (Session["User"] != null) { - if (Convert.ToInt32(Session["Userrole"]) == 1) + if (Convert.ToInt32(Session["Userrole"]) > 0) { if (id == null) { @@ -123,7 +123,7 @@ namespace WebApplication1.Models { if (Session["User"] != null) { - if (Convert.ToInt32(Session["Userrole"]) == 1) + if (Convert.ToInt32(Session["Userrole"]) > 0) { if (id == null) { diff --git a/Controllers/usersController.cs b/Controllers/usersController.cs index c9b8746..e40b898 100644 --- a/Controllers/usersController.cs +++ b/Controllers/usersController.cs @@ -9,6 +9,7 @@ using System.Web.Mvc; using WebApplication1.Models; using System.Security.Cryptography; using System.Text; +using System.Web.UI.WebControls; namespace WebApplication1.Controllers { @@ -281,7 +282,52 @@ namespace WebApplication1.Controllers return View(user); } - + public ActionResult Edituser(int? id) + { + if (Session["User"] != null) + { + + if (Convert.ToInt32(Session["Userrole"]) == 1) + { + + if (id == null) + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + user user = db.users.Find(id); + if (user == null) + { + return HttpNotFound(); + } + return View(user); + } + else + return new HttpStatusCodeResult(HttpStatusCode.Unauthorized); + + } + else + return View("Login"); + } + + + // POST: tickets/Edit/5 + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details see https://go.microsoft.com/fwlink/?LinkId=317598. + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult Edituser([Bind(Include = "ID,usename,password,displayname,role")] user user) + { + if (ModelState.IsValid) + { + var currentuser = db.users.Find(user.ID); + currentuser.displayname = user.displayname; + currentuser.role = user.role; + db.SaveChanges(); + return RedirectToAction("Index"); + } + return View(user); + } + // GET: users/Delete/5 public ActionResult Delete(int? id) diff --git a/Media/news/kmcZj0sRbt.jpg b/Media/news/kmcZj0sRbt.jpg new file mode 100644 index 0000000..1d98158 Binary files /dev/null and b/Media/news/kmcZj0sRbt.jpg differ diff --git a/Views/categories/Details.cshtml b/Views/categories/Details.cshtml index c2fe6b4..7bacca0 100644 --- a/Views/categories/Details.cshtml +++ b/Views/categories/Details.cshtml @@ -34,7 +34,7 @@ @Html.ActionLink("Read", "../news/Details", new { id = item.ID })| - @if (ViewBag.role == 1 || ViewBag.uid == item.userID) + @if (ViewBag.role > 0 || ViewBag.uid == item.userID) { @Html.ActionLink("Edit", "../news/Edit", new { id = item.ID }) diff --git a/Views/categories/Index.cshtml b/Views/categories/Index.cshtml index c42a6e2..cba5787 100644 --- a/Views/categories/Index.cshtml +++ b/Views/categories/Index.cshtml @@ -31,7 +31,7 @@ @Html.ActionLink("Details", "Details", new { id = item.ID }) | - @if (ViewBag.role == 1) + @if (ViewBag.role > 0) { @Html.ActionLink("Edit", "Edit", new { id = item.ID }) | diff --git a/Views/news/Index.cshtml b/Views/news/Index.cshtml index 91ca705..5a771b1 100644 --- a/Views/news/Index.cshtml +++ b/Views/news/Index.cshtml @@ -59,7 +59,7 @@ @Html.ActionLink("Read", "Details", new { id = item.NewsID })| - @if (ViewBag.role == 1 || ViewBag.uid == item.userID) + @if (ViewBag.role > 0 || ViewBag.uid == item.userID) { @Html.ActionLink("Edit", "Edit", new { id = item.NewsID }) diff --git a/Views/news/Latest.cshtml b/Views/news/Latest.cshtml index 9f65eaa..b6057f1 100644 --- a/Views/news/Latest.cshtml +++ b/Views/news/Latest.cshtml @@ -42,9 +42,7 @@ @Html.DisplayFor(modelItem => item.views) - @Html.ActionLink("Edit", "Edit", new { id = item.ID }) | - @Html.ActionLink("Details", "Details", new { id = item.ID }) | - @Html.ActionLink("Delete", "Delete", new { id = item.ID }) + @Html.ActionLink("Details", "Details", new { id = item.ID }) } diff --git a/Views/tags/Details.cshtml b/Views/tags/Details.cshtml index 7a9acf7..05b42d7 100644 --- a/Views/tags/Details.cshtml +++ b/Views/tags/Details.cshtml @@ -34,7 +34,7 @@ @Html.ActionLink("Read", "../news/Details", new { id = item.ID })| - @if (ViewBag.role == 1 || ViewBag.uid == item.userID) + @if (ViewBag.role > 0 || ViewBag.uid == item.userID) { @Html.ActionLink("Edit", "../news/Edit", new { id = item.ID }) diff --git a/Views/tags/Index.cshtml b/Views/tags/Index.cshtml index b2e19a8..6ecd61f 100644 --- a/Views/tags/Index.cshtml +++ b/Views/tags/Index.cshtml @@ -30,7 +30,7 @@ @Html.ActionLink("Details", "Details", new { id = item.code }) | - @if (ViewBag.role == 1) + @if (ViewBag.role > 0) { @Html.ActionLink("Edit", "Edit", new { id = item.code }) | diff --git a/Views/users/Edit.cshtml b/Views/users/Edit.cshtml index f8dbbf2..ed2ef77 100644 --- a/Views/users/Edit.cshtml +++ b/Views/users/Edit.cshtml @@ -27,7 +27,7 @@
@Html.LabelFor(model => model.password, htmlAttributes: new { @class = "control-label col-md-2" })
- + @Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" })
diff --git a/Views/users/Edituser.cshtml b/Views/users/Edituser.cshtml new file mode 100644 index 0000000..6f2654a --- /dev/null +++ b/Views/users/Edituser.cshtml @@ -0,0 +1,49 @@ +@model WebApplication1.Models.user + +@{ + ViewBag.Title = "Edituser"; +} + +

Edituser

+ +@using (Html.BeginForm()) +{ + @Html.AntiForgeryToken() + +
+

user

+
+ @Html.ValidationSummary(true, "", new { @class = "text-danger" }) + @Html.HiddenFor(model => model.ID) + + +
+ @Html.LabelFor(model => model.displayname, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.displayname, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.displayname, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.role, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ + @Html.ValidationMessageFor(model => model.role, "", new { @class = "text-danger" }) +
+
+ +
+
+ +
+
+
+} + +
+ @Html.ActionLink("Back to List", "Index") +
diff --git a/Views/users/allusers.cshtml b/Views/users/allusers.cshtml index 1094a3b..85c00b6 100644 --- a/Views/users/allusers.cshtml +++ b/Views/users/allusers.cshtml @@ -14,9 +14,6 @@ @Html.DisplayNameFor(model => model.usename) - - @Html.DisplayNameFor(model => model.password) - @Html.DisplayNameFor(model => model.displayname) @@ -28,9 +25,6 @@ @Html.DisplayFor(modelItem => item.usename) - - @Html.DisplayFor(modelItem => item.password) - @Html.DisplayFor(modelItem => item.displayname) diff --git a/WebApplication1.csproj b/WebApplication1.csproj index 99fbb06..4c8b748 100644 --- a/WebApplication1.csproj +++ b/WebApplication1.csproj @@ -295,6 +295,7 @@ +