fix category,tag, news list
fix edit account details bug
This commit is contained in:
@ -17,12 +17,15 @@ namespace WebApplication1.Controllers
|
|||||||
// GET: categories
|
// GET: categories
|
||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
{
|
{
|
||||||
|
ViewBag.role = Convert.ToInt32(Session["Userrole"]);
|
||||||
return View(db.categories.ToList());
|
return View(db.categories.ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET: categories/Details/5
|
// GET: categories/Details/5
|
||||||
public ActionResult Details(int? id)
|
public ActionResult Details(int? id)
|
||||||
{
|
{
|
||||||
|
ViewBag.role = Convert.ToInt32(Session["Userrole"]);
|
||||||
|
ViewBag.uid = Convert.ToInt32(Session["Userid"]);
|
||||||
if (id == null)
|
if (id == null)
|
||||||
{
|
{
|
||||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||||
@ -76,16 +79,28 @@ namespace WebApplication1.Controllers
|
|||||||
// GET: categories/Edit/5
|
// GET: categories/Edit/5
|
||||||
public ActionResult Edit(int? id)
|
public ActionResult Edit(int? id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
if (Session["User"] != null)
|
||||||
{
|
{
|
||||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
if (Convert.ToInt32(Session["Userrole"]) == 1)
|
||||||
|
{
|
||||||
|
if (id == null)
|
||||||
|
{
|
||||||
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||||
|
}
|
||||||
|
category category = db.categories.Find(id);
|
||||||
|
if (category == null)
|
||||||
|
{
|
||||||
|
return HttpNotFound();
|
||||||
|
}
|
||||||
|
return View(category);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
category category = db.categories.Find(id);
|
else
|
||||||
if (category == null)
|
return RedirectToAction("index", "home");
|
||||||
{
|
|
||||||
return HttpNotFound();
|
|
||||||
}
|
|
||||||
return View(category);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST: categories/Edit/5
|
// POST: categories/Edit/5
|
||||||
@ -107,16 +122,28 @@ namespace WebApplication1.Controllers
|
|||||||
// GET: categories/Delete/5
|
// GET: categories/Delete/5
|
||||||
public ActionResult Delete(int? id)
|
public ActionResult Delete(int? id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
if (Session["User"] != null)
|
||||||
{
|
{
|
||||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
if (Convert.ToInt32(Session["Userrole"]) == 1)
|
||||||
|
{
|
||||||
|
if (id == null)
|
||||||
|
{
|
||||||
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||||
|
}
|
||||||
|
category category = db.categories.Find(id);
|
||||||
|
if (category == null)
|
||||||
|
{
|
||||||
|
return HttpNotFound();
|
||||||
|
}
|
||||||
|
return View(category);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
category category = db.categories.Find(id);
|
else
|
||||||
if (category == null)
|
return RedirectToAction("index", "home");
|
||||||
{
|
|
||||||
return HttpNotFound();
|
|
||||||
}
|
|
||||||
return View(category);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST: categories/Delete/5
|
// POST: categories/Delete/5
|
||||||
|
|||||||
@ -28,6 +28,8 @@ namespace WebApplication1.Controllers
|
|||||||
// GET: news
|
// GET: news
|
||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
{
|
{
|
||||||
|
ViewBag.role = Convert.ToInt32(Session["Userrole"]);
|
||||||
|
ViewBag.uid = Convert.ToInt32(Session["Userid"]);
|
||||||
var models = (from user in db.users // Access Users DbSet
|
var models = (from user in db.users // Access Users DbSet
|
||||||
join news in db.news on user.ID equals news.userID into newsGroup // Join News DbSet
|
join news in db.news on user.ID equals news.userID into newsGroup // Join News DbSet
|
||||||
from news in newsGroup.DefaultIfEmpty() // Left outer join
|
from news in newsGroup.DefaultIfEmpty() // Left outer join
|
||||||
@ -35,6 +37,7 @@ namespace WebApplication1.Controllers
|
|||||||
select new newsModel
|
select new newsModel
|
||||||
{
|
{
|
||||||
DisplayName = user != null ? user.displayname : null,
|
DisplayName = user != null ? user.displayname : null,
|
||||||
|
userID = user != null ? user.ID : 0,
|
||||||
NewsID = news.ID, // Use null-conditional operator for missing news
|
NewsID = news.ID, // Use null-conditional operator for missing news
|
||||||
Title = news.title,
|
Title = news.title,
|
||||||
Image = news.image,
|
Image = news.image,
|
||||||
@ -185,16 +188,34 @@ namespace WebApplication1.Controllers
|
|||||||
// GET: news/Edit/5
|
// GET: news/Edit/5
|
||||||
public ActionResult Edit(int? id)
|
public ActionResult Edit(int? id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
if (Session["User"] != null)
|
||||||
{
|
{
|
||||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
if (Convert.ToInt32(Session["Userrole"]) == 1)
|
||||||
|
{
|
||||||
|
if (id == null)
|
||||||
|
{
|
||||||
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||||
|
}
|
||||||
|
news news = db.news.Find(id);
|
||||||
|
if (news == null)
|
||||||
|
{
|
||||||
|
return HttpNotFound();
|
||||||
|
}
|
||||||
|
else if ( news.userID == Convert.ToInt32(Session["Userid"]) || Convert.ToInt32(Session["Userrole"]) == 1)
|
||||||
|
{
|
||||||
|
return View(news);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
news news = db.news.Find(id);
|
else
|
||||||
if (news == null)
|
return RedirectToAction("index", "home");
|
||||||
{
|
|
||||||
return HttpNotFound();
|
|
||||||
}
|
|
||||||
return View(news);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST: news/Edit/5
|
// POST: news/Edit/5
|
||||||
@ -216,16 +237,33 @@ namespace WebApplication1.Controllers
|
|||||||
// GET: news/Delete/5
|
// GET: news/Delete/5
|
||||||
public ActionResult Delete(int? id)
|
public ActionResult Delete(int? id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
if (Session["User"] != null)
|
||||||
{
|
{
|
||||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
if (Convert.ToInt32(Session["Userrole"]) == 1)
|
||||||
|
{
|
||||||
|
if (id == null)
|
||||||
|
{
|
||||||
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||||
|
}
|
||||||
|
news news = db.news.Find(id);
|
||||||
|
if (news == null)
|
||||||
|
{
|
||||||
|
return HttpNotFound();
|
||||||
|
}
|
||||||
|
else if (news.userID == Convert.ToInt32(Session["Userid"]) || Convert.ToInt32(Session["Userrole"]) == 1)
|
||||||
|
{
|
||||||
|
return View(news);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
news news = db.news.Find(id);
|
else
|
||||||
if (news == null)
|
return RedirectToAction("index", "home");
|
||||||
{
|
|
||||||
return HttpNotFound();
|
|
||||||
}
|
|
||||||
return View(news);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST: news/Delete/5
|
// POST: news/Delete/5
|
||||||
|
|||||||
@ -16,12 +16,15 @@ namespace WebApplication1.Models
|
|||||||
// GET: tags
|
// GET: tags
|
||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
{
|
{
|
||||||
|
ViewBag.role = Convert.ToInt32(Session["Userrole"]);
|
||||||
return View(db.tags.ToList());
|
return View(db.tags.ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET: tags/Details/5
|
// GET: tags/Details/5
|
||||||
public ActionResult Details(int? id)
|
public ActionResult Details(int? id)
|
||||||
{
|
{
|
||||||
|
ViewBag.role = Convert.ToInt32(Session["Userrole"]);
|
||||||
|
ViewBag.uid = Convert.ToInt32(Session["Userid"]);
|
||||||
if (id == null)
|
if (id == null)
|
||||||
{
|
{
|
||||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||||
@ -75,16 +78,28 @@ namespace WebApplication1.Models
|
|||||||
// GET: tags/Edit/5
|
// GET: tags/Edit/5
|
||||||
public ActionResult Edit(int? id)
|
public ActionResult Edit(int? id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
if (Session["User"] != null)
|
||||||
{
|
{
|
||||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
if (Convert.ToInt32(Session["Userrole"]) == 1)
|
||||||
|
{
|
||||||
|
if (id == null)
|
||||||
|
{
|
||||||
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||||
|
}
|
||||||
|
tag tags = db.tags.Find(id);
|
||||||
|
if (tags == null)
|
||||||
|
{
|
||||||
|
return HttpNotFound();
|
||||||
|
}
|
||||||
|
return View(tags);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tag tag = db.tags.Find(id);
|
else
|
||||||
if (tag == null)
|
return RedirectToAction("index", "home");
|
||||||
{
|
|
||||||
return HttpNotFound();
|
|
||||||
}
|
|
||||||
return View(tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST: tags/Edit/5
|
// POST: tags/Edit/5
|
||||||
@ -106,16 +121,28 @@ namespace WebApplication1.Models
|
|||||||
// GET: tags/Delete/5
|
// GET: tags/Delete/5
|
||||||
public ActionResult Delete(int? id)
|
public ActionResult Delete(int? id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
if (Session["User"] != null)
|
||||||
{
|
{
|
||||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
if (Convert.ToInt32(Session["Userrole"]) == 1)
|
||||||
|
{
|
||||||
|
if (id == null)
|
||||||
|
{
|
||||||
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||||
|
}
|
||||||
|
tag tags = db.tags.Find(id);
|
||||||
|
if (tags == null)
|
||||||
|
{
|
||||||
|
return HttpNotFound();
|
||||||
|
}
|
||||||
|
return View(tags);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tag tag = db.tags.Find(id);
|
else
|
||||||
if (tag == null)
|
return RedirectToAction("index", "home");
|
||||||
{
|
|
||||||
return HttpNotFound();
|
|
||||||
}
|
|
||||||
return View(tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST: tags/Delete/5
|
// POST: tags/Delete/5
|
||||||
|
|||||||
@ -261,15 +261,20 @@ namespace WebApplication1.Controllers
|
|||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
// Hash the password
|
var u = db.users.Find(user.ID);
|
||||||
using (var sha256 = SHA256.Create())
|
|
||||||
{
|
if (user.password != null){
|
||||||
var hashedBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(user.password));
|
// Hash the password
|
||||||
user.password = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
|
using (var sha256 = SHA256.Create())
|
||||||
|
{
|
||||||
|
var hashedBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(user.password));
|
||||||
|
user.password = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
|
||||||
|
u.password = user.password;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var u= db.users.Find(user.ID);
|
|
||||||
u.password = user.password;
|
|
||||||
u.displayname = user.displayname;
|
u.displayname = user.displayname;
|
||||||
|
|
||||||
db.SaveChanges();
|
db.SaveChanges();
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ namespace WebApplication1.Models
|
|||||||
{
|
{
|
||||||
public string DisplayName { get; set; }
|
public string DisplayName { get; set; }
|
||||||
public int NewsID { get; set; }
|
public int NewsID { get; set; }
|
||||||
|
public int userID { get; set; }
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public string Image { get; set; }
|
public string Image { get; set; }
|
||||||
public string category { get; set; }
|
public string category { get; set; }
|
||||||
|
|||||||
@ -11,9 +11,6 @@
|
|||||||
<th>
|
<th>
|
||||||
@Html.DisplayNameFor(model => model.title)
|
@Html.DisplayNameFor(model => model.title)
|
||||||
</th>
|
</th>
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.link)
|
|
||||||
</th>
|
|
||||||
<th>
|
<th>
|
||||||
@Html.DisplayNameFor(model => model.tag)
|
@Html.DisplayNameFor(model => model.tag)
|
||||||
</th>
|
</th>
|
||||||
@ -29,9 +26,6 @@
|
|||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.title)
|
@Html.DisplayFor(modelItem => item.title)
|
||||||
</td>
|
</td>
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.link)
|
|
||||||
</td>
|
|
||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.tag)
|
@Html.DisplayFor(modelItem => item.tag)
|
||||||
</td>
|
</td>
|
||||||
@ -39,9 +33,14 @@
|
|||||||
@Html.DisplayFor(modelItem => item.cat)
|
@Html.DisplayFor(modelItem => item.cat)
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
|
@Html.ActionLink("Read", "../news/Details", new { id = item.ID })|
|
||||||
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
|
@if (ViewBag.role == 1 || ViewBag.uid == item.userID)
|
||||||
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
|
{
|
||||||
|
|
||||||
|
@Html.ActionLink("Edit", "../news/Edit", new { id = item.ID })
|
||||||
|
<span>|</span>
|
||||||
|
@Html.ActionLink("Delete", "../news/Delete", new { id = item.ID })
|
||||||
|
}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,9 +29,15 @@
|
|||||||
@Html.DisplayFor(modelItem => item.title)
|
@Html.DisplayFor(modelItem => item.title)
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
|
|
||||||
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
|
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
|
||||||
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
|
@if (ViewBag.role == 1)
|
||||||
|
{
|
||||||
|
@Html.ActionLink("Edit", "Edit", new { id = item.ID })
|
||||||
|
<span>|</span>
|
||||||
|
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
|
||||||
|
|
||||||
|
}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
@{
|
@{
|
||||||
ViewBag.Title = "Index";
|
ViewBag.Title = "Index";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<h2>Index</h2>
|
<h2>Index</h2>
|
||||||
@ -56,9 +57,17 @@
|
|||||||
@Html.DisplayFor(modelItem => item.views)
|
@Html.DisplayFor(modelItem => item.views)
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@Html.ActionLink("Edit", "Edit", new { id = item.NewsID }) |
|
|
||||||
@Html.ActionLink("Details", "Details", new { id = item.NewsID }) |
|
@Html.ActionLink("Read", "Details", new { id = item.NewsID })|
|
||||||
@Html.ActionLink("Delete", "Delete", new { id = item.NewsID })
|
@if (ViewBag.role == 1 || ViewBag.uid == item.userID)
|
||||||
|
{
|
||||||
|
|
||||||
|
@Html.ActionLink("Edit", "Edit", new { id = item.NewsID })
|
||||||
|
<span>|</span>
|
||||||
|
@Html.ActionLink("Delete", "Delete", new { id = item.NewsID })
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,9 +11,6 @@
|
|||||||
<th>
|
<th>
|
||||||
@Html.DisplayNameFor(model => model.title)
|
@Html.DisplayNameFor(model => model.title)
|
||||||
</th>
|
</th>
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.link)
|
|
||||||
</th>
|
|
||||||
<th>
|
<th>
|
||||||
@Html.DisplayNameFor(model => model.tag)
|
@Html.DisplayNameFor(model => model.tag)
|
||||||
</th>
|
</th>
|
||||||
@ -29,9 +26,6 @@
|
|||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.title)
|
@Html.DisplayFor(modelItem => item.title)
|
||||||
</td>
|
</td>
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.link)
|
|
||||||
</td>
|
|
||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.tag)
|
@Html.DisplayFor(modelItem => item.tag)
|
||||||
</td>
|
</td>
|
||||||
@ -39,9 +33,15 @@
|
|||||||
@Html.DisplayFor(modelItem => item.cat)
|
@Html.DisplayFor(modelItem => item.cat)
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
|
@Html.ActionLink("Read", "../news/Details", new { id = item.ID })|
|
||||||
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
|
@if (ViewBag.role == 1 || ViewBag.uid == item.userID)
|
||||||
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
|
{
|
||||||
|
|
||||||
|
@Html.ActionLink("Edit", "../news/Edit", new { id = item.ID })
|
||||||
|
<span>|</span>
|
||||||
|
@Html.ActionLink("Delete", "../news/Delete", new { id = item.ID })
|
||||||
|
|
||||||
|
}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,9 +29,14 @@
|
|||||||
@Html.DisplayFor(modelItem => item.title)
|
@Html.DisplayFor(modelItem => item.title)
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@Html.ActionLink("Edit", "Edit", new { id=item.code }) |
|
@Html.ActionLink("Details", "Details", new { id = item.code }) |
|
||||||
@Html.ActionLink("Details", "Details", new { id=item.code }) |
|
@if (ViewBag.role == 1)
|
||||||
@Html.ActionLink("Delete", "Delete", new { id=item.code })
|
{
|
||||||
|
@Html.ActionLink("Edit", "Edit", new { id = item.code })
|
||||||
|
<span>|</span>
|
||||||
|
@Html.ActionLink("Delete", "Delete", new { id = item.code })
|
||||||
|
|
||||||
|
}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user