Compare commits
10 Commits
be864f564b
...
4a5bfe58bf
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a5bfe58bf | |||
| eced31d841 | |||
| 4380d9da5c | |||
| d123ce205f | |||
| 4ffc4197aa | |||
| f71b11c131 | |||
| 07ffa3303d | |||
| 936222ab07 | |||
| f5dabbdcd8 | |||
| 0e30088405 |
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Entity;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
@ -14,7 +15,7 @@ namespace WebApplication1.Controllers
|
|||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
{
|
{
|
||||||
ViewBag.newsCount = db.news.Count();
|
ViewBag.newsCount = db.news.Count();
|
||||||
ViewBag.views = "";
|
ViewBag.views = db.viewlogs.Where(v => DbFunctions.TruncateTime(v.viewdate) == DateTime.Today).Count();
|
||||||
setTitle();
|
setTitle();
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,12 +17,24 @@ namespace WebApplication1.Controllers
|
|||||||
// GET: categories
|
// GET: categories
|
||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
{
|
{
|
||||||
|
string userrole = Convert.ToString(Session["Userrole"]);
|
||||||
|
|
||||||
|
if (userrole.Contains("tag&catManagment"))
|
||||||
|
ViewBag.role = 1;
|
||||||
|
else ViewBag.role = 0;
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
string userrole = Convert.ToString(Session["Userrole"]);
|
||||||
|
|
||||||
|
if (userrole.Contains("tag&catManagment"))
|
||||||
|
ViewBag.role = 1;
|
||||||
|
else ViewBag.role = 0;
|
||||||
|
|
||||||
|
ViewBag.uid = Convert.ToInt32(Session["Userid"]);
|
||||||
if (id == null)
|
if (id == null)
|
||||||
{
|
{
|
||||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||||
@ -42,7 +54,7 @@ namespace WebApplication1.Controllers
|
|||||||
{
|
{
|
||||||
if (Session["User"] != null)
|
if (Session["User"] != null)
|
||||||
{
|
{
|
||||||
if (Convert.ToInt32(Session["Userrole"]) == 1)
|
if (Convert.ToInt32(Session["Userrole"]) > 0)
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
@ -76,16 +88,30 @@ 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);
|
string userrole = Convert.ToString(Session["Userrole"]);
|
||||||
|
|
||||||
|
if (userrole.Contains("tag&catManagment"))
|
||||||
|
{
|
||||||
|
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 +133,30 @@ 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);
|
string userrole = Convert.ToString(Session["Userrole"]);
|
||||||
|
|
||||||
|
if (userrole.Contains("tag&catManagment"))
|
||||||
|
{
|
||||||
|
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
|
||||||
|
|||||||
@ -15,10 +15,26 @@ namespace WebApplication1.Controllers
|
|||||||
public class newsController : Controller
|
public class newsController : Controller
|
||||||
{
|
{
|
||||||
private newswebappEntities db = new newswebappEntities();
|
private newswebappEntities db = new newswebappEntities();
|
||||||
|
public static string GetUserIpAddress(HttpRequestBase request)
|
||||||
|
{
|
||||||
|
string ipAddress = request.ServerVariables["HTTP_X_FORWARDED_FOR"];
|
||||||
|
if (string.IsNullOrEmpty(ipAddress))
|
||||||
|
{
|
||||||
|
ipAddress = request.ServerVariables["REMOTE_ADDR"];
|
||||||
|
}
|
||||||
|
return ipAddress;
|
||||||
|
}
|
||||||
|
|
||||||
// GET: news
|
// GET: news
|
||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
{
|
{
|
||||||
|
string userrole = Convert.ToString(Session["Userrole"]);
|
||||||
|
|
||||||
|
if (userrole.Contains("tag&catManagment"))
|
||||||
|
ViewBag.role = 1;
|
||||||
|
else ViewBag.role = 0;
|
||||||
|
|
||||||
|
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
|
||||||
@ -26,6 +42,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,
|
||||||
@ -47,6 +64,9 @@ namespace WebApplication1.Controllers
|
|||||||
// GET: news/Details/5
|
// GET: news/Details/5
|
||||||
public ActionResult Details(int? id)
|
public ActionResult Details(int? id)
|
||||||
{
|
{
|
||||||
|
string userrole = Convert.ToString(Session["Userrole"]);
|
||||||
|
ViewBag.role = userrole.Contains("tag&catManagment") ? 1 : 0;
|
||||||
|
|
||||||
if (id == null)
|
if (id == null)
|
||||||
{
|
{
|
||||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||||
@ -58,21 +78,32 @@ namespace WebApplication1.Controllers
|
|||||||
}
|
}
|
||||||
var user = db.users.Find(news.userID);
|
var user = db.users.Find(news.userID);
|
||||||
ViewBag.user = user;
|
ViewBag.user = user;
|
||||||
news.views += 1;
|
|
||||||
db.SaveChanges();
|
|
||||||
/*
|
|
||||||
var key = Request.ServerVariables["REMOTE_ADDR"];
|
|
||||||
var now = DateTime.UtcNow;
|
|
||||||
|
|
||||||
if (now - View.LastVisited > _timeLimit)
|
// Get the user's IP address
|
||||||
|
string userIpAddress = GetUserIpAddress(Request);
|
||||||
|
|
||||||
|
// Check if this IP address has already viewed this article
|
||||||
|
DateTime thresholdDate = DateTime.Now.AddHours(-24);
|
||||||
|
bool hasViewed = db.viewlogs.Any(v => v.newsid == id && v.ipadd == userIpAddress && v.viewdate >= thresholdDate);
|
||||||
|
if (!hasViewed)
|
||||||
|
{
|
||||||
|
// Increment the view count
|
||||||
|
news.views++;
|
||||||
|
db.SaveChanges();
|
||||||
|
|
||||||
|
// Log the view
|
||||||
|
db.viewlogs.Add(new viewlog
|
||||||
{
|
{
|
||||||
pageView.LastVisited = now;
|
ipadd = userIpAddress,
|
||||||
_pageViews[key] = pageView;
|
newsid = news.ID,
|
||||||
return true; // View counted
|
viewdate = DateTime.Now
|
||||||
}
|
});
|
||||||
return false; // View within time limit, not counted
|
db.SaveChanges();
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
if (news.image == null) { news.image = "_"; }
|
||||||
return View(news);
|
return View(news);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET: news/Create
|
// GET: news/Create
|
||||||
@ -80,14 +111,17 @@ namespace WebApplication1.Controllers
|
|||||||
{
|
{
|
||||||
if (Session["User"] != null)
|
if (Session["User"] != null)
|
||||||
{
|
{
|
||||||
setLists();
|
string userrole = Convert.ToString(Session["Userrole"]);
|
||||||
//var models= new Tuple<List<category>, List<tag>>(cat, tags);
|
|
||||||
return View();
|
if (userrole.Contains("addNews"))
|
||||||
}
|
{
|
||||||
if (Session["User"] != null)
|
setLists();
|
||||||
{
|
return View();
|
||||||
ViewBag.categoryTitle = db.categories.ToList();
|
}
|
||||||
return View();
|
else
|
||||||
|
{
|
||||||
|
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return RedirectToAction("login", "users");
|
return RedirectToAction("login", "users");
|
||||||
@ -98,7 +132,7 @@ namespace WebApplication1.Controllers
|
|||||||
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
public ActionResult Create([Bind(Include = "ID,title,image,link,summary,cat,tag,publishDate,userID,Content,views")] news news)
|
public ActionResult Create([Bind(Include = "ID,title,image,link,summary,cat,tags,publishDate,userID,Content,views")] news news, List<string> Tags, List<string> Cat)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
@ -106,8 +140,31 @@ namespace WebApplication1.Controllers
|
|||||||
{
|
{
|
||||||
setLists();
|
setLists();
|
||||||
|
|
||||||
if (news.title != null && news.link != null && news.cat != null && news.tag != null)
|
if (news.title != null && news.link != null && Cat != null && Tags != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
news.tag = "";
|
||||||
|
foreach (string T in Tags)
|
||||||
|
{
|
||||||
|
if (T != Tags[0])
|
||||||
|
{
|
||||||
|
news.tag += " ,";
|
||||||
|
news.tag += T;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
news.tag += T;
|
||||||
|
}
|
||||||
|
news.cat = "";
|
||||||
|
foreach (string c in Cat)
|
||||||
|
{
|
||||||
|
if (c != Cat[0])
|
||||||
|
{
|
||||||
|
news.cat+= " ,";
|
||||||
|
news.cat += c;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
news.cat += c;
|
||||||
|
}
|
||||||
var image = Request.Files[0];
|
var image = Request.Files[0];
|
||||||
if (image.ContentLength > 1024 * 1024)
|
if (image.ContentLength > 1024 * 1024)
|
||||||
{
|
{
|
||||||
@ -122,6 +179,9 @@ namespace WebApplication1.Controllers
|
|||||||
if (!new[] { ".jpg", ".jpeg", ".png" }.Contains(fileExtension))
|
if (!new[] { ".jpg", ".jpeg", ".png" }.Contains(fileExtension))
|
||||||
{
|
{
|
||||||
ModelState.AddModelError("image", "Only JPG, JPEG, and PNG files are allowed.");
|
ModelState.AddModelError("image", "Only JPG, JPEG, and PNG files are allowed.");
|
||||||
|
news.image = "";
|
||||||
|
return View();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -166,16 +226,31 @@ 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);
|
string userrole = Convert.ToString(Session["Userrole"]);
|
||||||
|
setLists();
|
||||||
|
|
||||||
|
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"]) || userrole.Contains("newsManagement"))
|
||||||
|
{
|
||||||
|
return View(news);
|
||||||
|
}
|
||||||
|
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
|
||||||
@ -183,11 +258,82 @@ namespace WebApplication1.Controllers
|
|||||||
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
public ActionResult Edit([Bind(Include = "ID,title,image,link,summary,cat,tag,publishDate,userID,Content,views")] news news)
|
public ActionResult Edit([Bind(Include = "ID,title,image,link,summary,cat,tag,publishDate,userID,Content,views")] news news, List<string> Tags, List<string> Cat)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
db.Entry(news).State = EntityState.Modified;
|
|
||||||
|
news.cat = "";
|
||||||
|
if (Tags != null)
|
||||||
|
{
|
||||||
|
news.tag = "";
|
||||||
|
foreach (string T in Tags)
|
||||||
|
{
|
||||||
|
if (T != Tags[0])
|
||||||
|
{
|
||||||
|
news.tag += " ,";
|
||||||
|
news.tag += T;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
news.tag += T;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Cat != null){
|
||||||
|
foreach (string c in Cat)
|
||||||
|
{
|
||||||
|
if (c != Cat[0])
|
||||||
|
{
|
||||||
|
news.cat += " ,";
|
||||||
|
news.cat += c;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
news.cat += c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var image = Request.Files[0];
|
||||||
|
if (image.ContentLength > 1024 * 1024)
|
||||||
|
{
|
||||||
|
//check if fields are empty
|
||||||
|
ModelState.AddModelError("imageFile", "File size cannot exceed 1MB.");
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check file extension
|
||||||
|
string fileExtension = Path.GetExtension(image.FileName).ToLower();
|
||||||
|
//if (fileExtension != ".jpg" || fileExtension != ".jpeg" || fileExtension != ".png")
|
||||||
|
if (!new[] { ".jpg", ".jpeg", ".png" }.Contains(fileExtension))
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("image", "Only JPG, JPEG, and PNG files are allowed.");
|
||||||
|
news.image = "";
|
||||||
|
return View();
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int length = 10; // Desired length of the random string
|
||||||
|
string allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
|
char[] chars = new char[length];
|
||||||
|
Random rand = new Random();
|
||||||
|
string imgname = "";
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
chars[i] = allowedChars[rand.Next(0, allowedChars.Length)];
|
||||||
|
imgname += "" + chars[i];
|
||||||
|
}
|
||||||
|
var path = $"~/Media/news/" + imgname + fileExtension;
|
||||||
|
image.SaveAs(Server.MapPath(path));
|
||||||
|
news.image = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
//db op
|
||||||
|
var curnews = db.news.Find(news.ID);
|
||||||
|
curnews.title = news.title != null ? news.title : curnews.title;
|
||||||
|
curnews.image = news.image != null ? news.image : curnews.image;
|
||||||
|
curnews.summary = news.summary != null ? news.summary : curnews.summary;
|
||||||
|
curnews.Content = news.Content != null ? news.Content : curnews.Content;
|
||||||
|
curnews.link = news.link != null ? news.link : curnews.link;
|
||||||
|
curnews.tag = news.tag != null ? news.tag : curnews.tag;
|
||||||
|
curnews.cat = news.cat != null ? news.cat : curnews.cat;
|
||||||
db.SaveChanges();
|
db.SaveChanges();
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
@ -197,16 +343,27 @@ 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 (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"]) > 0)
|
||||||
|
{
|
||||||
|
return View(news);
|
||||||
|
}
|
||||||
|
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,25 @@ namespace WebApplication1.Models
|
|||||||
// GET: tags
|
// GET: tags
|
||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
{
|
{
|
||||||
|
string userrole = Convert.ToString(Session["Userrole"]);
|
||||||
|
|
||||||
|
if (userrole.Contains("tag&catManagment"))
|
||||||
|
ViewBag.role = 1;
|
||||||
|
else ViewBag.role = 0;
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
string userrole = Convert.ToString(Session["Userrole"]);
|
||||||
|
|
||||||
|
if (userrole.Contains("tag&catManagment"))
|
||||||
|
ViewBag.role = 1;
|
||||||
|
else ViewBag.role = 0;
|
||||||
|
|
||||||
|
ViewBag.uid = Convert.ToInt32(Session["Userid"]);
|
||||||
if (id == null)
|
if (id == null)
|
||||||
{
|
{
|
||||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||||
@ -41,7 +54,9 @@ namespace WebApplication1.Models
|
|||||||
{
|
{
|
||||||
if (Session["User"] != null)
|
if (Session["User"] != null)
|
||||||
{
|
{
|
||||||
if (Convert.ToInt32(Session["Userrole"]) == 1)
|
string userrole = Convert.ToString(Session["Userrole"]);
|
||||||
|
|
||||||
|
if (userrole.Contains("tag&catManagment"))
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
@ -75,16 +90,30 @@ 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);
|
string userrole = Convert.ToString(Session["Userrole"]);
|
||||||
|
|
||||||
|
if (userrole.Contains("tag&catManagment"))
|
||||||
|
{
|
||||||
|
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 +135,30 @@ 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);
|
string userrole = Convert.ToString(Session["Userrole"]);
|
||||||
|
|
||||||
|
if (userrole.Contains("tag&catManagment"))
|
||||||
|
{
|
||||||
|
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
|
||||||
|
|||||||
@ -7,6 +7,9 @@ using System.Net;
|
|||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using WebApplication1.Models;
|
using WebApplication1.Models;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using System.Web.UI.WebControls;
|
||||||
|
|
||||||
namespace WebApplication1.Controllers
|
namespace WebApplication1.Controllers
|
||||||
{
|
{
|
||||||
@ -14,9 +17,98 @@ namespace WebApplication1.Controllers
|
|||||||
{
|
{
|
||||||
private newswebappEntities db = new newswebappEntities();
|
private newswebappEntities db = new newswebappEntities();
|
||||||
|
|
||||||
|
private int ValidatePassword(string password, string confirmPassword)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(password))
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("", "Password cannot be empty");
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (password != confirmPassword)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("", "Passwords don't match");
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password.Length < 8)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("", "Password must be at least 8 characters long");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!password.Any(char.IsUpper))
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("", "Password must contain at least one uppercase letter");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!password.Any(char.IsLower))
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("", "Password must contain at least one lowercase letter");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!password.Any(char.IsDigit))
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("", "Password must contain at least one digit");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!password.Any(ch => !char.IsLetterOrDigit(ch)))
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("", "Password must contain at least one special character");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int ValidateUsername(string username)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(username))
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("", "Username cannot be empty");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (username.Length < 3)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("", "Username must be at least 3 characters long");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (username.Length > 20)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("", "Username must not exceed 20 characters");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!username.All(char.IsLetterOrDigit))
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("", "Username can only contain letters and digits");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// GET: users
|
// GET: users
|
||||||
public ActionResult Index()
|
public ActionResult Index() {
|
||||||
{ if (Convert.ToInt32(Session["Userrole"]) > 0)
|
|
||||||
|
string userrole = Convert.ToString(Session["Userrole"]);
|
||||||
|
if (userrole.Contains("addNews"))
|
||||||
|
{
|
||||||
|
@ViewBag.role = "jornalist";
|
||||||
|
}
|
||||||
|
if (userrole.Contains("newsManagement") || userrole.Contains("tag&catManagment") )
|
||||||
{
|
{
|
||||||
@ViewBag.role = "admin";
|
@ViewBag.role = "admin";
|
||||||
}
|
}
|
||||||
@ -46,7 +138,8 @@ namespace WebApplication1.Controllers
|
|||||||
{
|
{
|
||||||
if (Session["User"] != null)
|
if (Session["User"] != null)
|
||||||
{
|
{
|
||||||
if (Convert.ToInt32(Session["Userrole"]) == 1)
|
string userrole = Convert.ToString(Session["Userrole"]);
|
||||||
|
if (userrole.Contains("userManagment"))
|
||||||
{
|
{
|
||||||
return View(db.users.ToList());
|
return View(db.users.ToList());
|
||||||
}
|
}
|
||||||
@ -75,12 +168,20 @@ namespace WebApplication1.Controllers
|
|||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
|
var cpass = Request.Form["ConfirmPassword"];
|
||||||
|
var valpass = ValidatePassword(user.password, cpass);
|
||||||
|
var valuser = ValidateUsername(user.usename);
|
||||||
|
if (valpass == 1 || valuser == 1)
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
//check if the username exists
|
//check if the username exists
|
||||||
var check = db.users.FirstOrDefault(u => u.usename == user.usename);
|
var check = db.users.FirstOrDefault(u => u.usename == user.usename);
|
||||||
//checks username and password field in form
|
//checks username and password field in form
|
||||||
if (user.usename != null && user.password != null)
|
if (user.usename != null && user.password != null)
|
||||||
{
|
{
|
||||||
|
user.role = "none";
|
||||||
|
|
||||||
if (check != null)
|
if (check != null)
|
||||||
{
|
{
|
||||||
ModelState.AddModelError("", " username already exists");
|
ModelState.AddModelError("", " username already exists");
|
||||||
@ -88,6 +189,15 @@ namespace WebApplication1.Controllers
|
|||||||
//if username is valid create user add to db
|
//if username is valid create user add to db
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Hash the password
|
||||||
|
using (var sha256 = SHA256.Create())
|
||||||
|
{
|
||||||
|
var hashedBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(user.password));
|
||||||
|
user.password = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
db.users.Add(user);
|
db.users.Add(user);
|
||||||
db.SaveChanges();
|
db.SaveChanges();
|
||||||
|
|
||||||
@ -99,11 +209,6 @@ namespace WebApplication1.Controllers
|
|||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
ModelState.AddModelError("",
|
|
||||||
"username and password field can not be empty");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return View(user);
|
return View(user);
|
||||||
}
|
}
|
||||||
@ -134,6 +239,11 @@ namespace WebApplication1.Controllers
|
|||||||
{
|
{
|
||||||
//check if user exists
|
//check if user exists
|
||||||
var existingUser = db.users.FirstOrDefault(u => u.usename == user.usename );
|
var existingUser = db.users.FirstOrDefault(u => u.usename == user.usename );
|
||||||
|
using (var sha256 = SHA256.Create())
|
||||||
|
{
|
||||||
|
var hashedBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(user.password));
|
||||||
|
user.password = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
|
||||||
|
}
|
||||||
if (existingUser != null && existingUser.password == user.password)
|
if (existingUser != null && existingUser.password == user.password)
|
||||||
{
|
{
|
||||||
//session start
|
//session start
|
||||||
@ -182,14 +292,84 @@ namespace WebApplication1.Controllers
|
|||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
db.Entry(user).State = EntityState.Modified;
|
var u = db.users.Find(user.ID);
|
||||||
|
|
||||||
|
if (user.password != null){
|
||||||
|
// Hash the password
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
u.displayname = user.displayname;
|
||||||
|
|
||||||
|
db.SaveChanges();
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
return View(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionResult Edituser(int? id)
|
||||||
|
{
|
||||||
|
if (Session["User"] != null)
|
||||||
|
{
|
||||||
|
string userrole = Convert.ToString(Session["Userrole"]);
|
||||||
|
|
||||||
|
if (userrole.Contains("userManagment"))
|
||||||
|
{
|
||||||
|
|
||||||
|
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 RedirectToAction("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, List<string> roles)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
user.role = "";
|
||||||
|
foreach (string r in roles)
|
||||||
|
{
|
||||||
|
if (r != roles[0])
|
||||||
|
{
|
||||||
|
user.role += ",";
|
||||||
|
user.role += r;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
user.role += r;
|
||||||
|
}
|
||||||
|
var currentuser = db.users.Find(user.ID);
|
||||||
|
currentuser.displayname = user.displayname;
|
||||||
|
currentuser.role = user.role;
|
||||||
db.SaveChanges();
|
db.SaveChanges();
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
return View(user);
|
return View(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// GET: users/Delete/5
|
// GET: users/Delete/5
|
||||||
public ActionResult Delete(int? id)
|
public ActionResult Delete(int? id)
|
||||||
|
|||||||
BIN
Media/news/32wiF8mzgi.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
Media/news/5RCYg4F954.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
Media/news/AnaSQwnOHg.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
Media/news/DhunrFmH5e.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
Media/news/YoUypscYRW.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
Media/news/i08QfDIQ70.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
Media/news/kgeN7kkWJ0.jpg
Normal file
|
After Width: | Height: | Size: 297 KiB |
BIN
Media/news/kmcZj0sRbt.jpg
Normal file
|
After Width: | Height: | Size: 297 KiB |
BIN
Media/news/orYf1iXWSH.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
Media/news/rQISg2NRaA.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
Media/news/zF9LapiTFm.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
@ -31,5 +31,6 @@ namespace WebApplication1.Models
|
|||||||
public virtual DbSet<ticket> tickets { get; set; }
|
public virtual DbSet<ticket> tickets { get; set; }
|
||||||
public virtual DbSet<user> users { get; set; }
|
public virtual DbSet<user> users { get; set; }
|
||||||
public virtual DbSet<response> responses { get; set; }
|
public virtual DbSet<response> responses { get; set; }
|
||||||
|
public virtual DbSet<viewlog> viewlogs { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,9 +65,18 @@
|
|||||||
</Key>
|
</Key>
|
||||||
<Property Name="ID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
|
<Property Name="ID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
|
||||||
<Property Name="usename" Type="nvarchar" MaxLength="50" Nullable="false" />
|
<Property Name="usename" Type="nvarchar" MaxLength="50" Nullable="false" />
|
||||||
<Property Name="password" Type="nvarchar" MaxLength="50" Nullable="false" />
|
<Property Name="password" Type="nvarchar(max)" Nullable="false" />
|
||||||
<Property Name="displayname" Type="nvarchar" MaxLength="50" />
|
<Property Name="displayname" Type="nvarchar" MaxLength="50" />
|
||||||
<Property Name="role" Type="int" Nullable="false" />
|
<Property Name="role" Type="nvarchar" MaxLength="70" Nullable="false" />
|
||||||
|
</EntityType>
|
||||||
|
<EntityType Name="viewlog">
|
||||||
|
<Key>
|
||||||
|
<PropertyRef Name="ID" />
|
||||||
|
</Key>
|
||||||
|
<Property Name="ID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
|
||||||
|
<Property Name="ipadd" Type="nvarchar(max)" />
|
||||||
|
<Property Name="newsid" Type="int" />
|
||||||
|
<Property Name="viewdate" Type="datetime" />
|
||||||
</EntityType>
|
</EntityType>
|
||||||
<EntityContainer Name="newswebappModelStoreContainer">
|
<EntityContainer Name="newswebappModelStoreContainer">
|
||||||
<EntitySet Name="category" EntityType="Self.category" Schema="dbo" store:Type="Tables" />
|
<EntitySet Name="category" EntityType="Self.category" Schema="dbo" store:Type="Tables" />
|
||||||
@ -76,6 +85,7 @@
|
|||||||
<EntitySet Name="tag" EntityType="Self.tag" Schema="dbo" store:Type="Tables" />
|
<EntitySet Name="tag" EntityType="Self.tag" Schema="dbo" store:Type="Tables" />
|
||||||
<EntitySet Name="ticket" EntityType="Self.ticket" Schema="dbo" store:Type="Tables" />
|
<EntitySet Name="ticket" EntityType="Self.ticket" Schema="dbo" store:Type="Tables" />
|
||||||
<EntitySet Name="user" EntityType="Self.user" Schema="dbo" store:Type="Tables" />
|
<EntitySet Name="user" EntityType="Self.user" Schema="dbo" store:Type="Tables" />
|
||||||
|
<EntitySet Name="viewlog" EntityType="Self.viewlog" Schema="dbo" store:Type="Tables" />
|
||||||
</EntityContainer>
|
</EntityContainer>
|
||||||
</Schema></edmx:StorageModels>
|
</Schema></edmx:StorageModels>
|
||||||
<!-- CSDL content -->
|
<!-- CSDL content -->
|
||||||
@ -88,6 +98,7 @@
|
|||||||
<EntitySet Name="tickets" EntityType="newswebappModel.ticket" />
|
<EntitySet Name="tickets" EntityType="newswebappModel.ticket" />
|
||||||
<EntitySet Name="users" EntityType="newswebappModel.user" />
|
<EntitySet Name="users" EntityType="newswebappModel.user" />
|
||||||
<EntitySet Name="responses" EntityType="newswebappModel.response" />
|
<EntitySet Name="responses" EntityType="newswebappModel.response" />
|
||||||
|
<EntitySet Name="viewlogs" EntityType="newswebappModel.viewlog" />
|
||||||
</EntityContainer>
|
</EntityContainer>
|
||||||
<EntityType Name="category">
|
<EntityType Name="category">
|
||||||
<Key>
|
<Key>
|
||||||
@ -139,9 +150,9 @@
|
|||||||
</Key>
|
</Key>
|
||||||
<Property Name="ID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
|
<Property Name="ID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
|
||||||
<Property Name="usename" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
|
<Property Name="usename" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
|
||||||
<Property Name="password" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
|
<Property Name="password" Type="String" Nullable="false" MaxLength="Max" FixedLength="false" Unicode="true" />
|
||||||
<Property Name="displayname" Type="String" MaxLength="50" FixedLength="false" Unicode="true" />
|
<Property Name="displayname" Type="String" MaxLength="50" FixedLength="false" Unicode="true" />
|
||||||
<Property Name="role" Type="Int32" Nullable="false" />
|
<Property Name="role" Type="String" Nullable="false" />
|
||||||
</EntityType>
|
</EntityType>
|
||||||
<EntityType Name="response">
|
<EntityType Name="response">
|
||||||
<Key>
|
<Key>
|
||||||
@ -153,6 +164,15 @@
|
|||||||
<Property Name="adminid" Type="Int32" />
|
<Property Name="adminid" Type="Int32" />
|
||||||
<Property Name="ticketid" Type="Int32" />
|
<Property Name="ticketid" Type="Int32" />
|
||||||
</EntityType>
|
</EntityType>
|
||||||
|
<EntityType Name="viewlog">
|
||||||
|
<Key>
|
||||||
|
<PropertyRef Name="ID" />
|
||||||
|
</Key>
|
||||||
|
<Property Name="ID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
|
||||||
|
<Property Name="ipadd" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
|
||||||
|
<Property Name="newsid" Type="Int32" />
|
||||||
|
<Property Name="viewdate" Type="DateTime" Precision="3" />
|
||||||
|
</EntityType>
|
||||||
</Schema>
|
</Schema>
|
||||||
</edmx:ConceptualModels>
|
</edmx:ConceptualModels>
|
||||||
<!-- C-S mapping content -->
|
<!-- C-S mapping content -->
|
||||||
@ -229,6 +249,16 @@
|
|||||||
</MappingFragment>
|
</MappingFragment>
|
||||||
</EntityTypeMapping>
|
</EntityTypeMapping>
|
||||||
</EntitySetMapping>
|
</EntitySetMapping>
|
||||||
|
<EntitySetMapping Name="viewlogs">
|
||||||
|
<EntityTypeMapping TypeName="newswebappModel.viewlog">
|
||||||
|
<MappingFragment StoreEntitySet="viewlog">
|
||||||
|
<ScalarProperty Name="viewdate" ColumnName="viewdate" />
|
||||||
|
<ScalarProperty Name="newsid" ColumnName="newsid" />
|
||||||
|
<ScalarProperty Name="ipadd" ColumnName="ipadd" />
|
||||||
|
<ScalarProperty Name="ID" ColumnName="ID" />
|
||||||
|
</MappingFragment>
|
||||||
|
</EntityTypeMapping>
|
||||||
|
</EntitySetMapping>
|
||||||
</EntityContainerMapping>
|
</EntityContainerMapping>
|
||||||
</Mapping>
|
</Mapping>
|
||||||
</edmx:Mappings>
|
</edmx:Mappings>
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
<EntityTypeShape EntityType="newswebappModel.ticket" Width="1.5" PointX="0.75" PointY="4.75" />
|
<EntityTypeShape EntityType="newswebappModel.ticket" Width="1.5" PointX="0.75" PointY="4.75" />
|
||||||
<EntityTypeShape EntityType="newswebappModel.user" Width="1.5" PointX="2.75" PointY="4.75" />
|
<EntityTypeShape EntityType="newswebappModel.user" Width="1.5" PointX="2.75" PointY="4.75" />
|
||||||
<EntityTypeShape EntityType="newswebappModel.response" Width="1.5" PointX="4.75" PointY="4.625" />
|
<EntityTypeShape EntityType="newswebappModel.response" Width="1.5" PointX="4.75" PointY="4.625" />
|
||||||
|
<EntityTypeShape EntityType="newswebappModel.viewlog" Width="1.5" PointX="3.25" PointY="7.25" />
|
||||||
</Diagram>
|
</Diagram>
|
||||||
</edmx:Diagrams>
|
</edmx:Diagrams>
|
||||||
</edmx:Designer>
|
</edmx:Designer>
|
||||||
|
|||||||
@ -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; }
|
||||||
|
|||||||
@ -18,6 +18,6 @@ namespace WebApplication1.Models
|
|||||||
public string usename { get; set; }
|
public string usename { get; set; }
|
||||||
public string password { get; set; }
|
public string password { get; set; }
|
||||||
public string displayname { get; set; }
|
public string displayname { get; set; }
|
||||||
public int role { get; set; }
|
public string role { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
22
Models/viewlog.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// This code was generated from a template.
|
||||||
|
//
|
||||||
|
// Manual changes to this file may cause unexpected behavior in your application.
|
||||||
|
// Manual changes to this file will be overwritten if the code is regenerated.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace WebApplication1.Models
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
public partial class viewlog
|
||||||
|
{
|
||||||
|
public int ID { get; set; }
|
||||||
|
public string ipadd { get; set; }
|
||||||
|
public Nullable<int> newsid { get; set; }
|
||||||
|
public Nullable<System.DateTime> viewdate { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -19,15 +19,13 @@
|
|||||||
<a class="btn btn-outline-dark" href="/news"> Start Reading »</a>
|
<a class="btn btn-outline-dark" href="/news"> Start Reading »</a>
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
<section class="col-md-4" aria-labelledby="librariesTitle">
|
<section class="col-md-4" aria-labelledby="viewcount">
|
||||||
<h2 id="librariesTitle">Get more libraries</h2>
|
<h2 id="viewcount">View count</h2>
|
||||||
<p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p>
|
<p>
|
||||||
<p><a class="btn btn-outline-dark" href="https://go.microsoft.com/fwlink/?LinkId=301866">Learn more »</a></p>
|
@ViewBag.views
|
||||||
</section>
|
</p>
|
||||||
<section class="col-md-4" aria-labelledby="hostingTitle">
|
<p>
|
||||||
<h2 id="hostingTitle">Web Hosting</h2>
|
<a class="btn btn-outline-dark" href="/news"> Start Reading »</a></p>
|
||||||
<p>You can easily find a web hosting company that offers the right mix of features and price for your applications.</p>
|
|
||||||
<p><a class="btn btn-outline-dark" href="https://go.microsoft.com/fwlink/?LinkId=301867">Learn more »</a></p>
|
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
@ -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 > 0 || 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 > 0)
|
||||||
|
{
|
||||||
|
@Html.ActionLink("Edit", "Edit", new { id = item.ID })
|
||||||
|
<span>|</span>
|
||||||
|
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
|
||||||
|
|
||||||
|
}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,7 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label col-md-2">category</label>
|
<label class="control-label col-md-2">category</label>
|
||||||
<div>
|
<div>
|
||||||
<select id="cat" name="cat" class="form-control" multiple>
|
<select id="cat" name="Cat" class="form-control" multiple>
|
||||||
@foreach (var item in ViewBag.categoryTitle)
|
@foreach (var item in ViewBag.categoryTitle)
|
||||||
{
|
{
|
||||||
<option value="@item.title">@item.title</option>
|
<option value="@item.title">@item.title</option>
|
||||||
@ -54,7 +54,7 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@Html.LabelFor(model => model.tag, htmlAttributes: new { @class = "control-label col-md-2" })
|
@Html.LabelFor(model => model.tag, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||||
<div class="col-md-10">
|
<div class="col-md-10">
|
||||||
<select id="tag" name="tag" class="form-control" multiple>
|
<select id="tag" name="Tags" class="form-control" multiple>
|
||||||
@foreach (var item in ViewBag.tagTitle)
|
@foreach (var item in ViewBag.tagTitle)
|
||||||
{
|
{
|
||||||
<option value="@item.title">@item.title</option>
|
<option value="@item.title">@item.title</option>
|
||||||
|
|||||||
@ -24,7 +24,7 @@
|
|||||||
</dt>
|
</dt>
|
||||||
|
|
||||||
<dd>
|
<dd>
|
||||||
<img src="@Url.Content(Model.image)" height="270" width="200" />
|
<img src="@Url.Content(Model.image)" alt="@Model.title" height="270" width="200" />
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
<dt>
|
<dt>
|
||||||
@ -94,6 +94,12 @@
|
|||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
<p>
|
<p>
|
||||||
@Html.ActionLink("Edit", "Edit", new { id = Model.ID }) |
|
@if (@ViewBag.role == 1)
|
||||||
|
{
|
||||||
|
@Html.ActionLink("Edit", "Edit", new { id = Model.ID })
|
||||||
|
<span>
|
||||||
|
|
|
||||||
|
</span>
|
||||||
|
}
|
||||||
@Html.ActionLink("Back to List", "Index")
|
@Html.ActionLink("Back to List", "Index")
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@ -6,15 +6,14 @@
|
|||||||
|
|
||||||
<h2>Edit</h2>
|
<h2>Edit</h2>
|
||||||
|
|
||||||
@using (Html.BeginForm())
|
@using (Html.BeginForm("Edit", "news", FormMethod.Post, new { enctype = "multipart/form-data" }))
|
||||||
{
|
{
|
||||||
@Html.AntiForgeryToken()
|
@Html.AntiForgeryToken()
|
||||||
|
|
||||||
<div class="form-horizontal">
|
<div class="form">
|
||||||
<h4>news</h4>
|
<h4>news</h4>
|
||||||
<hr />
|
<hr />
|
||||||
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
|
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
|
||||||
@Html.HiddenFor(model => model.ID)
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" })
|
@Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||||
@ -24,14 +23,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
@Html.LabelFor(model => model.image, htmlAttributes: new { @class = "control-label col-md-2" })
|
|
||||||
<div class="col-md-10">
|
|
||||||
@Html.EditorFor(model => model.image, new { htmlAttributes = new { @class = "form-control" } })
|
|
||||||
@Html.ValidationMessageFor(model => model.image, "", new { @class = "text-danger" })
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@Html.LabelFor(model => model.link, htmlAttributes: new { @class = "control-label col-md-2" })
|
@Html.LabelFor(model => model.link, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||||
<div class="col-md-10">
|
<div class="col-md-10">
|
||||||
@ -41,17 +32,21 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@Html.LabelFor(model => model.summary, htmlAttributes: new { @class = "control-label col-md-2" })
|
@Html.LabelFor(model => model.image, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||||
<div class="col-md-10">
|
<div class="col-md-10">
|
||||||
@Html.EditorFor(model => model.summary, new { htmlAttributes = new { @class = "form-control" } })
|
@Html.EditorFor(model => model.image, new { htmlAttributes = new { @type = "file", @class = "form-control" } })
|
||||||
@Html.ValidationMessageFor(model => model.summary, "", new { @class = "text-danger" })
|
@Html.ValidationMessageFor(model => model.image, "", new { @class = "text-danger" })
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@Html.LabelFor(model => model.cat, htmlAttributes: new { @class = "control-label col-md-2" })
|
<label class="control-label col-md-2">category</label>
|
||||||
<div class="col-md-10">
|
<div>
|
||||||
@Html.EditorFor(model => model.cat, new { htmlAttributes = new { @class = "form-control" } })
|
<select id="cat" name="Cat" class="form-control" multiple>
|
||||||
|
@foreach (var item in ViewBag.categoryTitle)
|
||||||
|
{
|
||||||
|
<option value="@item.title">@item.title</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
@Html.ValidationMessageFor(model => model.cat, "", new { @class = "text-danger" })
|
@Html.ValidationMessageFor(model => model.cat, "", new { @class = "text-danger" })
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -59,46 +54,35 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@Html.LabelFor(model => model.tag, htmlAttributes: new { @class = "control-label col-md-2" })
|
@Html.LabelFor(model => model.tag, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||||
<div class="col-md-10">
|
<div class="col-md-10">
|
||||||
@Html.EditorFor(model => model.tag, new { htmlAttributes = new { @class = "form-control" } })
|
<select id="tag" name="Tags" class="form-control" multiple>
|
||||||
|
@foreach (var item in ViewBag.tagTitle)
|
||||||
|
{
|
||||||
|
<option value="@item.title">@item.title</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
@Html.ValidationMessageFor(model => model.tag, "", new { @class = "text-danger" })
|
@Html.ValidationMessageFor(model => model.tag, "", new { @class = "text-danger" })
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@Html.LabelFor(model => model.publishDate, htmlAttributes: new { @class = "control-label col-md-2" })
|
@Html.LabelFor(model => model.summary, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||||
<div class="col-md-10">
|
<div class="col-md-10">
|
||||||
@Html.EditorFor(model => model.publishDate, new { htmlAttributes = new { @class = "form-control" } })
|
@Html.TextAreaFor(model => model.summary, new { @class = "form-control" })
|
||||||
@Html.ValidationMessageFor(model => model.publishDate, "", new { @class = "text-danger" })
|
@Html.ValidationMessageFor(model => model.summary, "", new { @class = "text-danger" })
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
@Html.LabelFor(model => model.userID, htmlAttributes: new { @class = "control-label col-md-2" })
|
|
||||||
<div class="col-md-10">
|
|
||||||
@Html.EditorFor(model => model.userID, new { htmlAttributes = new { @class = "form-control" } })
|
|
||||||
@Html.ValidationMessageFor(model => model.userID, "", new { @class = "text-danger" })
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@Html.LabelFor(model => model.Content, htmlAttributes: new { @class = "control-label col-md-2" })
|
@Html.LabelFor(model => model.Content, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||||
<div class="col-md-10">
|
<div class="col-md-10">
|
||||||
@Html.EditorFor(model => model.Content, new { htmlAttributes = new { @class = "form-control" } })
|
@Html.TextAreaFor(model => model.Content, new { @class = "form-control" })
|
||||||
@Html.ValidationMessageFor(model => model.Content, "", new { @class = "text-danger" })
|
@Html.ValidationMessageFor(model => model.Content, "", new { @class = "text-danger" })
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<br />
|
||||||
<div class="form-group">
|
|
||||||
@Html.LabelFor(model => model.views, htmlAttributes: new { @class = "control-label col-md-2" })
|
|
||||||
<div class="col-md-10">
|
|
||||||
@Html.EditorFor(model => model.views, new { htmlAttributes = new { @class = "form-control" } })
|
|
||||||
@Html.ValidationMessageFor(model => model.views, "", new { @class = "text-danger" })
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-md-offset-2 col-md-10">
|
<div class="col-md-offset-2 col-md-10">
|
||||||
<input type="submit" value="Save" class="btn btn-default" />
|
<input type="submit" value="Create" class="btn btn-outline-dark" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -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 > 0 || 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>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,9 +42,7 @@
|
|||||||
@Html.DisplayFor(modelItem => item.views)
|
@Html.DisplayFor(modelItem => item.views)
|
||||||
</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 })
|
|
||||||
</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 > 0 || 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 > 0)
|
||||||
@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>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,7 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@Html.LabelFor(model => model.password, htmlAttributes: new { @class = "control-label col-md-2" })
|
@Html.LabelFor(model => model.password, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||||
<div class="col-md-10">
|
<div class="col-md-10">
|
||||||
@Html.EditorFor(model => model.password, new { htmlAttributes = new { @class = "form-control" } })
|
<input type="password" name="password" class="form-control"/>
|
||||||
@Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" })
|
@Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" })
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
58
Views/users/Edituser.cshtml
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
@model WebApplication1.Models.user
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewBag.Title = "Edituser";
|
||||||
|
var allRoles = "addNews ,newsManagement, userManagment, tag&catManagment".Split(',');
|
||||||
|
var Roles = Model.role.Split(',');
|
||||||
|
}
|
||||||
|
|
||||||
|
<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">
|
||||||
|
|
||||||
|
@foreach (var r in Roles) { @r}
|
||||||
|
@for (int i = 0; i < allRoles.Length; i++)
|
||||||
|
{
|
||||||
|
var r = allRoles[i];
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" value="@r" name="roles" id="flexCheckDefault_@i" @(Roles.Contains(r) ? "checked" : "")>
|
||||||
|
<label class="form-check-label" for="flexCheckDefault_@i">@r</label>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
@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>
|
||||||
@ -15,7 +15,7 @@
|
|||||||
<hr />
|
<hr />
|
||||||
<dl class="dl-horizontal">
|
<dl class="dl-horizontal">
|
||||||
<dt>
|
<dt>
|
||||||
@Html.DisplayNameFor(model => model.usename)
|
Username
|
||||||
</dt>
|
</dt>
|
||||||
|
|
||||||
<dd>
|
<dd>
|
||||||
@ -23,15 +23,7 @@
|
|||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
<dt>
|
<dt>
|
||||||
@Html.DisplayNameFor(model => model.password)
|
Display Name
|
||||||
</dt>
|
|
||||||
|
|
||||||
<dd>
|
|
||||||
@Html.DisplayFor(model => model.password)
|
|
||||||
</dd>
|
|
||||||
|
|
||||||
<dt>
|
|
||||||
@Html.DisplayNameFor(model => model.displayname)
|
|
||||||
</dt>
|
</dt>
|
||||||
|
|
||||||
<dd>
|
<dd>
|
||||||
@ -48,13 +40,19 @@
|
|||||||
</dl>
|
</dl>
|
||||||
<div class="col-md-offset-2 col-md-10">
|
<div class="col-md-offset-2 col-md-10">
|
||||||
@Html.ActionLink("edit account details", "Edit", null, new { @class = "btn btn-outline-dark" })
|
@Html.ActionLink("edit account details", "Edit", null, new { @class = "btn btn-outline-dark" })
|
||||||
|
|
||||||
@Html.ActionLink("Logout", "LogOut", null, new { @class = "btn btn-outline-dark" })
|
@Html.ActionLink("Logout", "LogOut", null, new { @class = "btn btn-outline-dark" })
|
||||||
|
|
||||||
|
@if (@ViewBag.role == "admin")
|
||||||
|
{
|
||||||
|
@Html.ActionLink("Manage users", "allusers", null, new { @class = "btn btn-outline-dark" })
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
<div class="col-md-offset-2 col-md-10">
|
<div class="col-md-offset-2 col-md-10">
|
||||||
@Html.ActionLink("Delete Account", "Delete", null, new { @class = "btn btn-outline-dark" })
|
@Html.ActionLink("Delete Account", "Delete", null, new { @class = "btn btn-outline-dark" })
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label col-md-2">Confirm password</label>
|
<label class="control-label col-md-2">Confirm password</label>
|
||||||
<input type="password" , id="ConfirmPassword", oninput="checkPasswords()" class="form-control" />
|
<input type="password" name="ConfirmPassword" id="ConfirmPassword" oninput="checkPasswords()" class="form-control" />
|
||||||
<span asp-validation-for="ConfirmPassword" class="text-danger"></span>
|
<span asp-validation-for="ConfirmPassword" class="text-danger"></span>
|
||||||
<span id="passwordMismatch" class="text-danger"></span>
|
<span id="passwordMismatch" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -14,9 +14,6 @@
|
|||||||
<th>
|
<th>
|
||||||
@Html.DisplayNameFor(model => model.usename)
|
@Html.DisplayNameFor(model => model.usename)
|
||||||
</th>
|
</th>
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.password)
|
|
||||||
</th>
|
|
||||||
<th>
|
<th>
|
||||||
@Html.DisplayNameFor(model => model.displayname)
|
@Html.DisplayNameFor(model => model.displayname)
|
||||||
</th>
|
</th>
|
||||||
@ -28,15 +25,11 @@
|
|||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.usename)
|
@Html.DisplayFor(modelItem => item.usename)
|
||||||
</td>
|
</td>
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.password)
|
|
||||||
</td>
|
|
||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.displayname)
|
@Html.DisplayFor(modelItem => item.displayname)
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
|
@Html.ActionLink("Edit", "Edituser", new { id=item.ID }) |
|
||||||
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
|
|
||||||
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
|
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@ -189,6 +189,9 @@
|
|||||||
<Compile Include="Models\user.cs">
|
<Compile Include="Models\user.cs">
|
||||||
<DependentUpon>Model1.tt</DependentUpon>
|
<DependentUpon>Model1.tt</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Models\viewlog.cs">
|
||||||
|
<DependentUpon>Model1.tt</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -292,6 +295,7 @@
|
|||||||
<Content Include="Views\responses\Respond.cshtml" />
|
<Content Include="Views\responses\Respond.cshtml" />
|
||||||
<Content Include="Views\responses\Index.cshtml" />
|
<Content Include="Views\responses\Index.cshtml" />
|
||||||
<Content Include="Views\responses\test.cshtml" />
|
<Content Include="Views\responses\test.cshtml" />
|
||||||
|
<Content Include="Views\users\Edituser.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="App_Data\" />
|
<Folder Include="App_Data\" />
|
||||||
|
|||||||