add edit users for admin
This commit is contained in:
@ -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)
|
||||
{
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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,6 +282,51 @@ 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
|
||||
|
||||
BIN
Media/news/kmcZj0sRbt.jpg
Normal file
BIN
Media/news/kmcZj0sRbt.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 297 KiB |
@ -34,7 +34,7 @@
|
||||
</td>
|
||||
<td>
|
||||
@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 })
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
<td>
|
||||
|
||||
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
|
||||
@if (ViewBag.role == 1)
|
||||
@if (ViewBag.role > 0)
|
||||
{
|
||||
@Html.ActionLink("Edit", "Edit", new { id = item.ID })
|
||||
<span>|</span>
|
||||
|
||||
@ -59,7 +59,7 @@
|
||||
<td>
|
||||
|
||||
@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 })
|
||||
|
||||
@ -42,9 +42,7 @@
|
||||
@Html.DisplayFor(modelItem => item.views)
|
||||
</td>
|
||||
<td>
|
||||
@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 })
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
</td>
|
||||
<td>
|
||||
@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 })
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
</td>
|
||||
<td>
|
||||
@Html.ActionLink("Details", "Details", new { id = item.code }) |
|
||||
@if (ViewBag.role == 1)
|
||||
@if (ViewBag.role > 0)
|
||||
{
|
||||
@Html.ActionLink("Edit", "Edit", new { id = item.code })
|
||||
<span>|</span>
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.password, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
<input type="password", name="password" , class="form-control"/>
|
||||
<input type="password" name="password" class="form-control"/>
|
||||
@Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
49
Views/users/Edituser.cshtml
Normal file
49
Views/users/Edituser.cshtml
Normal file
@ -0,0 +1,49 @@
|
||||
@model WebApplication1.Models.user
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Edituser";
|
||||
}
|
||||
|
||||
<h2>Edituser</h2>
|
||||
|
||||
@using (Html.BeginForm())
|
||||
{
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
<div class="form-horizontal">
|
||||
<h4>user</h4>
|
||||
<hr />
|
||||
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
|
||||
@Html.HiddenFor(model => model.ID)
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.displayname, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.displayname, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.displayname, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.role, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
<select name="role" class="form-control">
|
||||
<option value="0">User</option>
|
||||
<option value="2">Admin</option>
|
||||
</select>
|
||||
@Html.ValidationMessageFor(model => model.role, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<input type="submit" value="Save" class="btn btn-default" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div>
|
||||
@Html.ActionLink("Back to List", "Index")
|
||||
</div>
|
||||
@ -14,9 +14,6 @@
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.usename)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.password)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.displayname)
|
||||
</th>
|
||||
@ -28,9 +25,6 @@
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.usename)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.password)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.displayname)
|
||||
</td>
|
||||
|
||||
@ -295,6 +295,7 @@
|
||||
<Content Include="Views\responses\Respond.cshtml" />
|
||||
<Content Include="Views\responses\Index.cshtml" />
|
||||
<Content Include="Views\responses\test.cshtml" />
|
||||
<Content Include="Views\users\Edituser.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
|
||||
Reference in New Issue
Block a user