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,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)
|
||||
|
||||
Reference in New Issue
Block a user