diff --git a/Controllers/AccountController.cs b/Controllers/AccountController.cs deleted file mode 100644 index 256cdd5..0000000 --- a/Controllers/AccountController.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Mvc; -using WebApplication1.Models; - -namespace WebApplication1.Controllers -{ - public class AccountController : Controller - { - newswebappEntities db = new newswebappEntities(); - - // GET: Account - public ActionResult Index() - { - return View(); - } - public ActionResult Register() - { - ViewBag.Message = "Register page"; - - return View(); - } - public ActionResult Login() - { - ViewBag.Message = "Login page"; - - return View(); - } - - [HttpPost] - public ActionResult Login(Login model) - { - // Replace this with actual authentication logic - if (ModelState.IsValid) - { - var allusers = db.users.ToList(); - - foreach (var user in allusers) - { - if (model.username == user.usename && model.password == user.password) - { - // Successful login, redirect to home page or desired page - return RedirectToAction("Index", "Home"); - } - } - ModelState.AddModelError("", "Invalid username or password"); - } - return View(model); - } - [HttpPost] - public ActionResult Register(Register model) - { - if (ModelState.IsValid) - - { - - // Replace this with actual user creation logic, including password hashing - // and storing user information in a database - /*var allusers = db.users.ToList(); - - foreach (var user in allusers) - - { - if (model.username.ToString() == user.usename.ToString()) - { - ModelState.AddModelError("", "username already exists"); - return RedirectToAction("Register"); - } - }*/ - - db.users.Add( new user - { - usename = model.username, - password = model.password, - displayname = model.displayname - }); - db.SaveChanges(); - return RedirectToAction("Home","Index"); - - } - - - /*db.users.Add(new user - { - usename = model.username, - password = model.password, - displayname = model.displayname - }); - db.SaveChanges(); - }*/ - - // return RedirectToAction("Login"); - - return View(model); - } - } -} - \ No newline at end of file diff --git a/Controllers/categoriesController.cs b/Controllers/categoriesController.cs new file mode 100644 index 0000000..adc837d --- /dev/null +++ b/Controllers/categoriesController.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Entity; +using System.Linq; +using System.Net; +using System.Web; +using System.Web.Mvc; +using WebApplication1.Models; + +namespace WebApplication1.Controllers +{ + public class categoriesController : Controller + { + private newswebappEntities db = new newswebappEntities(); + + // GET: categories + public ActionResult Index() + { + return View(db.categories.ToList()); + } + + // GET: categories/Details/5 + public ActionResult Details(int? id) + { + if (id == null) + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + category category = db.categories.Find(id); + ViewBag.title = category.title; + if (category == null) + { + return HttpNotFound(); + } + return View(db.news.Where(n => n.title.Contains(category.title))); + } + + // GET: categories/Create + public ActionResult Create() + { + if (Session["User"] != null) + { + if (Convert.ToInt32(Session["Userrole"]) == 1) + { + return View(); + } + else + { + return new HttpStatusCodeResult(HttpStatusCode.Unauthorized); + } + } + else + return RedirectToAction("index","home"); + } + + // POST: categories/Create + // 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 Create([Bind(Include = "ID,link,title")] category category) + { + if (ModelState.IsValid) + { + category.link = "categories/"+category.title; + db.categories.Add(category); + db.SaveChanges(); + return RedirectToAction("Index"); + } + + return View(category); + } + + // GET: categories/Edit/5 + public ActionResult Edit(int? id) + { + if (id == null) + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + category category = db.categories.Find(id); + if (category == null) + { + return HttpNotFound(); + } + return View(category); + } + + // POST: categories/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 Edit([Bind(Include = "ID,link,title")] category category) + { + if (ModelState.IsValid) + { + db.Entry(category).State = EntityState.Modified; + db.SaveChanges(); + return RedirectToAction("Index"); + } + return View(category); + } + + // GET: categories/Delete/5 + public ActionResult Delete(int? id) + { + if (id == null) + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + category category = db.categories.Find(id); + if (category == null) + { + return HttpNotFound(); + } + return View(category); + } + + // POST: categories/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public ActionResult DeleteConfirmed(int id) + { + category category = db.categories.Find(id); + db.categories.Remove(category); + db.SaveChanges(); + return RedirectToAction("Index"); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + db.Dispose(); + } + base.Dispose(disposing); + } + } +} diff --git a/Controllers/newsController.cs b/Controllers/newsController.cs new file mode 100644 index 0000000..4a76f7c --- /dev/null +++ b/Controllers/newsController.cs @@ -0,0 +1,127 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Entity; +using System.Linq; +using System.Net; +using System.Web; +using System.Web.Mvc; +using WebApplication1.Models; + +namespace WebApplication1.Controllers +{ + public class newsController : Controller + { + private newswebappEntities db = new newswebappEntities(); + + // GET: news + public ActionResult Index() + { + return View(db.news.ToList()); + } + + // GET: news/Details/5 + public ActionResult Details(int? id) + { + if (id == null) + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + news news = db.news.Find(id); + if (news == null) + { + return HttpNotFound(); + } + return View(news); + } + + // GET: news/Create + public ActionResult Create() + { + return View(); + } + + // POST: news/Create + // 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 Create([Bind(Include = "ID,title,image,link,summary,cat,tag,publishDate,userID,Content,views")] news news) + { + if (ModelState.IsValid) + { + db.news.Add(news); + db.SaveChanges(); + return RedirectToAction("Index"); + } + + return View(news); + } + + // GET: news/Edit/5 + public ActionResult Edit(int? id) + { + if (id == null) + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + news news = db.news.Find(id); + if (news == null) + { + return HttpNotFound(); + } + return View(news); + } + + // POST: news/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 Edit([Bind(Include = "ID,title,image,link,summary,cat,tag,publishDate,userID,Content,views")] news news) + { + if (ModelState.IsValid) + { + db.Entry(news).State = EntityState.Modified; + db.SaveChanges(); + return RedirectToAction("Index"); + } + return View(news); + } + + // GET: news/Delete/5 + public ActionResult Delete(int? id) + { + if (id == null) + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + news news = db.news.Find(id); + if (news == null) + { + return HttpNotFound(); + } + return View(news); + } + + // POST: news/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public ActionResult DeleteConfirmed(int id) + { + news news = db.news.Find(id); + db.news.Remove(news); + db.SaveChanges(); + return RedirectToAction("Index"); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + db.Dispose(); + } + base.Dispose(disposing); + } + } +} diff --git a/Controllers/usersController.cs b/Controllers/usersController.cs index fa3c55e..553ed7a 100644 --- a/Controllers/usersController.cs +++ b/Controllers/usersController.cs @@ -16,7 +16,15 @@ namespace WebApplication1.Controllers // GET: users public ActionResult Index() - { + { if (Convert.ToInt32(Session["Userrole"]) > 0) + { + @ViewBag.role = "admin"; + } + else + { + @ViewBag.role = "user"; + } + if (Session["User"] != null) { if (Session["Userid"] == null) @@ -33,11 +41,18 @@ namespace WebApplication1.Controllers else return RedirectToAction("Login"); }// GET: users + public ActionResult allusers() { if (Session["User"] != null) { - return View(db.users.ToList()); + if (Convert.ToInt32(Session["Userrole"]) == 1) + { + return View(db.users.ToList()); + } + else { + return new HttpStatusCodeResult(HttpStatusCode.Unauthorized); + } } else return RedirectToAction("Login"); @@ -56,8 +71,8 @@ namespace WebApplication1.Controllers // more details see https://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] - public ActionResult Register([Bind(Include = "ID,usename,password,displayname")] user user) - { + public ActionResult Register([Bind(Include = "ID,usename,password,displayname,role")] user user) + { if (ModelState.IsValid) { @@ -79,6 +94,7 @@ namespace WebApplication1.Controllers //session start Session["User"] = user.usename; Session["Userid"] = user.ID; + Session["Userrole"] = user.role; return RedirectToAction("Index"); } @@ -123,6 +139,7 @@ namespace WebApplication1.Controllers //session start Session["User"] = existingUser.usename; Session["Userid"] = existingUser.ID; + Session["Userrole"] = existingUser.role; return RedirectToAction("Index"); } @@ -161,7 +178,7 @@ namespace WebApplication1.Controllers // more details see https://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] - public ActionResult Edit([Bind(Include = "ID,usename,password,displayname")] user user) + public ActionResult Edit([Bind(Include = "ID,usename,password,displayname,role")] user user) { if (ModelState.IsValid) { diff --git a/Models/Model1.edmx b/Models/Model1.edmx index ae30c22..4ab2a02 100644 --- a/Models/Model1.edmx +++ b/Models/Model1.edmx @@ -55,6 +55,7 @@ + @@ -124,6 +125,7 @@ + @@ -180,6 +182,7 @@ + diff --git a/Models/user.cs b/Models/user.cs index 6a4b753..dab0455 100644 --- a/Models/user.cs +++ b/Models/user.cs @@ -18,5 +18,6 @@ namespace WebApplication1.Models public string usename { get; set; } public string password { get; set; } public string displayname { get; set; } + public int role { get; set; } } } diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 69b8c0c..c2408e5 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -21,7 +21,9 @@
  • @Html.ActionLink("About", "About", "Home", new { area = "" }, new { @class = "nav-link" })
  • @Html.ActionLink("Contact", "Contact", "Home", new { area = "" }, new { @class = "nav-link" })
  • @Html.ActionLink("user setting", "index", "users", new { area = "" }, new { @class = "nav-link" })
  • - +
  • @Html.ActionLink("news", "index", "users", new { area = "" }, new { @class = "nav-link" })
  • +
  • @Html.ActionLink("categories", "index", "categories", new { area = "" }, new { @class = "nav-link" })
  • + diff --git a/Views/categories/Create.cshtml b/Views/categories/Create.cshtml new file mode 100644 index 0000000..a654788 --- /dev/null +++ b/Views/categories/Create.cshtml @@ -0,0 +1,36 @@ +@model WebApplication1.Models.category + +@{ + ViewBag.Title = "Create"; +} + +

    Create

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

    category

    +
    + @Html.ValidationSummary(true, "", new { @class = "text-danger" }) + +
    + @Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.title, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.title, "", new { @class = "text-danger" }) +
    +
    + +
    +
    + +
    +
    +
    +} + +
    + @Html.ActionLink("Back to List", "Index") +
    diff --git a/Views/categories/Delete.cshtml b/Views/categories/Delete.cshtml new file mode 100644 index 0000000..2a73e9a --- /dev/null +++ b/Views/categories/Delete.cshtml @@ -0,0 +1,40 @@ +@model WebApplication1.Models.category + +@{ + ViewBag.Title = "Delete"; +} + +

    Delete

    + +

    Are you sure you want to delete this?

    +
    +

    category

    +
    +
    +
    + @Html.DisplayNameFor(model => model.link) +
    + +
    + @Html.DisplayFor(model => model.link) +
    + +
    + @Html.DisplayNameFor(model => model.title) +
    + +
    + @Html.DisplayFor(model => model.title) +
    + +
    + + @using (Html.BeginForm()) { + @Html.AntiForgeryToken() + +
    + | + @Html.ActionLink("Back to List", "Index") +
    + } +
    diff --git a/Views/categories/Details.cshtml b/Views/categories/Details.cshtml new file mode 100644 index 0000000..043b08f --- /dev/null +++ b/Views/categories/Details.cshtml @@ -0,0 +1,49 @@ +@model IEnumerable + +@{ + ViewBag.Title = @ViewBag.title; +} + +

    @ViewBag.title

    + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + } + +
    + @Html.DisplayNameFor(model => model.title) + + @Html.DisplayNameFor(model => model.link) + + @Html.DisplayNameFor(model => model.tag) + + category +
    + @Html.DisplayFor(modelItem => item.title) + + @Html.DisplayFor(modelItem => item.link) + + @Html.DisplayFor(modelItem => item.tag) + + @Html.DisplayFor(modelItem => item.cat) + + @Html.ActionLink("Edit", "Edit", new { id = item.ID }) | + @Html.ActionLink("Details", "Details", new { id = item.ID }) | + @Html.ActionLink("Delete", "Delete", new { id = item.ID }) +
    diff --git a/Views/categories/Edit.cshtml b/Views/categories/Edit.cshtml new file mode 100644 index 0000000..035b499 --- /dev/null +++ b/Views/categories/Edit.cshtml @@ -0,0 +1,45 @@ +@model WebApplication1.Models.category + +@{ + ViewBag.Title = "Edit"; +} + +

    Edit

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

    category

    +
    + @Html.ValidationSummary(true, "", new { @class = "text-danger" }) + @Html.HiddenFor(model => model.ID) + +
    + @Html.LabelFor(model => model.link, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.link, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.link, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.title, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.title, "", new { @class = "text-danger" }) +
    +
    + +
    +
    + +
    +
    +
    +} + +
    + @Html.ActionLink("Back to List", "Index") +
    diff --git a/Views/categories/Index.cshtml b/Views/categories/Index.cshtml new file mode 100644 index 0000000..a2641ea --- /dev/null +++ b/Views/categories/Index.cshtml @@ -0,0 +1,39 @@ +@model IEnumerable + +@{ + ViewBag.Title = "Index"; +} + +

    Index

    + +

    + @Html.ActionLink("Create New", "Create") +

    + + + + + + + +@foreach (var item in Model) { + + + + + +} + +
    + @Html.DisplayNameFor(model => model.link) + + @Html.DisplayNameFor(model => model.title) +
    + @Html.DisplayFor(modelItem => item.link) + + @Html.DisplayFor(modelItem => item.title) + + @Html.ActionLink("Edit", "Edit", new { id=item.ID }) | + @Html.ActionLink("Details", "Details", new { id=item.ID }) | + @Html.ActionLink("Delete", "Delete", new { id=item.ID }) +
    diff --git a/Views/news/Create.cshtml b/Views/news/Create.cshtml new file mode 100644 index 0000000..8ef6239 --- /dev/null +++ b/Views/news/Create.cshtml @@ -0,0 +1,107 @@ +@model WebApplication1.Models.news + +@{ + ViewBag.Title = "Create"; +} + +

    Create

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

    news

    +
    + @Html.ValidationSummary(true, "", new { @class = "text-danger" }) +
    + @Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.title, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.title, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.image, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.image, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.image, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.link, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.link, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.link, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.summary, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.summary, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.summary, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.cat, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.cat, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.cat, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.tag, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.tag, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.tag, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.publishDate, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.publishDate, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.publishDate, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.userID, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.userID, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.userID, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.Content, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.Content, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.Content, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.views, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.views, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.views, "", new { @class = "text-danger" }) +
    +
    + +
    +
    + +
    +
    +
    +} + +
    + @Html.ActionLink("Back to List", "Index") +
    diff --git a/Views/news/Delete.cshtml b/Views/news/Delete.cshtml new file mode 100644 index 0000000..7813618 --- /dev/null +++ b/Views/news/Delete.cshtml @@ -0,0 +1,104 @@ +@model WebApplication1.Models.news + +@{ + ViewBag.Title = "Delete"; +} + +

    Delete

    + +

    Are you sure you want to delete this?

    +
    +

    news

    +
    +
    +
    + @Html.DisplayNameFor(model => model.title) +
    + +
    + @Html.DisplayFor(model => model.title) +
    + +
    + @Html.DisplayNameFor(model => model.image) +
    + +
    + @Html.DisplayFor(model => model.image) +
    + +
    + @Html.DisplayNameFor(model => model.link) +
    + +
    + @Html.DisplayFor(model => model.link) +
    + +
    + @Html.DisplayNameFor(model => model.summary) +
    + +
    + @Html.DisplayFor(model => model.summary) +
    + +
    + @Html.DisplayNameFor(model => model.cat) +
    + +
    + @Html.DisplayFor(model => model.cat) +
    + +
    + @Html.DisplayNameFor(model => model.tag) +
    + +
    + @Html.DisplayFor(model => model.tag) +
    + +
    + @Html.DisplayNameFor(model => model.publishDate) +
    + +
    + @Html.DisplayFor(model => model.publishDate) +
    + +
    + @Html.DisplayNameFor(model => model.userID) +
    + +
    + @Html.DisplayFor(model => model.userID) +
    + +
    + @Html.DisplayNameFor(model => model.Content) +
    + +
    + @Html.DisplayFor(model => model.Content) +
    + +
    + @Html.DisplayNameFor(model => model.views) +
    + +
    + @Html.DisplayFor(model => model.views) +
    + +
    + + @using (Html.BeginForm()) { + @Html.AntiForgeryToken() + +
    + | + @Html.ActionLink("Back to List", "Index") +
    + } +
    diff --git a/Views/news/Details.cshtml b/Views/news/Details.cshtml new file mode 100644 index 0000000..892f45c --- /dev/null +++ b/Views/news/Details.cshtml @@ -0,0 +1,98 @@ +@model WebApplication1.Models.news + +@{ + ViewBag.Title = "Details"; +} + +

    Details

    + +
    +

    news

    +
    +
    +
    + @Html.DisplayNameFor(model => model.title) +
    + +
    + @Html.DisplayFor(model => model.title) +
    + +
    + @Html.DisplayNameFor(model => model.image) +
    + +
    + @Html.DisplayFor(model => model.image) +
    + +
    + @Html.DisplayNameFor(model => model.link) +
    + +
    + @Html.DisplayFor(model => model.link) +
    + +
    + @Html.DisplayNameFor(model => model.summary) +
    + +
    + @Html.DisplayFor(model => model.summary) +
    + +
    + @Html.DisplayNameFor(model => model.cat) +
    + +
    + @Html.DisplayFor(model => model.cat) +
    + +
    + @Html.DisplayNameFor(model => model.tag) +
    + +
    + @Html.DisplayFor(model => model.tag) +
    + +
    + @Html.DisplayNameFor(model => model.publishDate) +
    + +
    + @Html.DisplayFor(model => model.publishDate) +
    + +
    + @Html.DisplayNameFor(model => model.userID) +
    + +
    + @Html.DisplayFor(model => model.userID) +
    + +
    + @Html.DisplayNameFor(model => model.Content) +
    + +
    + @Html.DisplayFor(model => model.Content) +
    + +
    + @Html.DisplayNameFor(model => model.views) +
    + +
    + @Html.DisplayFor(model => model.views) +
    + +
    +
    +

    + @Html.ActionLink("Edit", "Edit", new { id = Model.ID }) | + @Html.ActionLink("Back to List", "Index") +

    diff --git a/Views/news/Edit.cshtml b/Views/news/Edit.cshtml new file mode 100644 index 0000000..6471203 --- /dev/null +++ b/Views/news/Edit.cshtml @@ -0,0 +1,109 @@ +@model WebApplication1.Models.news + +@{ + ViewBag.Title = "Edit"; +} + +

    Edit

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

    news

    +
    + @Html.ValidationSummary(true, "", new { @class = "text-danger" }) + @Html.HiddenFor(model => model.ID) + +
    + @Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.title, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.title, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.image, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.image, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.image, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.link, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.link, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.link, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.summary, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.summary, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.summary, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.cat, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.cat, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.cat, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.tag, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.tag, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.tag, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.publishDate, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.publishDate, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.publishDate, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.userID, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.userID, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.userID, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.Content, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.Content, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.Content, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.views, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.views, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.views, "", new { @class = "text-danger" }) +
    +
    + +
    +
    + +
    +
    +
    +} + +
    + @Html.ActionLink("Back to List", "Index") +
    diff --git a/Views/news/Index.cshtml b/Views/news/Index.cshtml new file mode 100644 index 0000000..876ca8d --- /dev/null +++ b/Views/news/Index.cshtml @@ -0,0 +1,87 @@ +@model IEnumerable + +@{ + ViewBag.Title = "Index"; +} + +

    Index

    + +

    + @Html.ActionLink("Create New", "Create") +

    + + + + + + + + + + + + + + + +@foreach (var item in Model) { + + + + + + + + + + + + + +} + +
    + @Html.DisplayNameFor(model => model.title) + + @Html.DisplayNameFor(model => model.image) + + @Html.DisplayNameFor(model => model.link) + + @Html.DisplayNameFor(model => model.summary) + + @Html.DisplayNameFor(model => model.cat) + + @Html.DisplayNameFor(model => model.tag) + + @Html.DisplayNameFor(model => model.publishDate) + + @Html.DisplayNameFor(model => model.userID) + + @Html.DisplayNameFor(model => model.Content) + + @Html.DisplayNameFor(model => model.views) +
    + @Html.DisplayFor(modelItem => item.title) + + @Html.DisplayFor(modelItem => item.image) + + @Html.DisplayFor(modelItem => item.link) + + @Html.DisplayFor(modelItem => item.summary) + + @Html.DisplayFor(modelItem => item.cat) + + @Html.DisplayFor(modelItem => item.tag) + + @Html.DisplayFor(modelItem => item.publishDate) + + @Html.DisplayFor(modelItem => item.userID) + + @Html.DisplayFor(modelItem => item.Content) + + @Html.DisplayFor(modelItem => item.views) + + @Html.ActionLink("Edit", "Edit", new { id=item.ID }) | + @Html.ActionLink("Details", "Details", new { id=item.ID }) | + @Html.ActionLink("Delete", "Delete", new { id=item.ID }) +
    diff --git a/Views/users/Edit.cshtml b/Views/users/Edit.cshtml index 30fbacf..4a5f2a2 100644 --- a/Views/users/Edit.cshtml +++ b/Views/users/Edit.cshtml @@ -10,46 +10,46 @@ { @Html.AntiForgeryToken() -
    -

    user

    -
    - @Html.ValidationSummary(true, "", new { @class = "text-danger" }) - @Html.HiddenFor(model => model.ID) +
    +

    user

    +
    + @Html.ValidationSummary(true, "", new { @class = "text-danger" }) + @Html.HiddenFor(model => model.ID) -
    - @Html.LabelFor(model => model.usename, htmlAttributes: new { @class = "control-label col-md-2" }) -
    - @Html.EditorFor(model => model.usename, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } }) - @Html.ValidationMessageFor(model => model.usename, "", new { @class = "text-danger" }) -
    -
    - -
    - @Html.LabelFor(model => model.password, htmlAttributes: new { @class = "control-label col-md-2" }) -
    - @Html.EditorFor(model => model.password, new { htmlAttributes = new { @class = "form-control" } }) - @Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" }) -
    -
    - -
    - @Html.LabelFor(model => model.displayname, htmlAttributes: new { @class = "control-label col-md-2" }) -
    - @Html.EditorFor(model => model.displayname, new { htmlAttributes = new { @class = "form-control" } }) - @Html.ValidationMessageFor(model => model.displayname, "", new { @class = "text-danger" }) -
    -
    -
    - -
    -
    - - @Html.ActionLink("back to account managment", "index", null, new { @class = "btn btn-outline-dark" }) - - - -
    +
    + @Html.LabelFor(model => model.usename, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.usename, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } }) + @Html.ValidationMessageFor(model => model.usename, "", new { @class = "text-danger" })
    + +
    + @Html.LabelFor(model => model.password, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.password, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" }) +
    +
    + +
    + @Html.LabelFor(model => model.displayname, htmlAttributes: new { @class = "control-label col-md-2" }) +
    + @Html.EditorFor(model => model.displayname, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.displayname, "", new { @class = "text-danger" }) +
    +
    +
    + +
    +
    + + @Html.ActionLink("back to account managment", "index", null, new { @class = "btn btn-outline-dark" }) + + + +
    +
    +
    } diff --git a/Views/users/Index.cshtml b/Views/users/Index.cshtml index 9ae891f..f03129e 100644 --- a/Views/users/Index.cshtml +++ b/Views/users/Index.cshtml @@ -37,6 +37,13 @@
    @Html.DisplayFor(model => model.displayname)
    +
    + @Html.DisplayNameFor(model => model.role) +
    + +
    + @ViewBag.role +
    diff --git a/Views/users/Login.cshtml b/Views/users/Login.cshtml index 103d33e..e3a5cea 100644 --- a/Views/users/Login.cshtml +++ b/Views/users/Login.cshtml @@ -25,7 +25,7 @@
    @Html.LabelFor(model => model.password, htmlAttributes: new { @class = "control-label col-md-2" })
    - @Html.EditorFor(model => model.password, new { htmlAttributes = new { @class = "form-control" } }) + @Html.EditorFor(model => model.password, new { htmlAttributes = new {@type="password", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" })
    diff --git a/Views/users/Register.cshtml b/Views/users/Register.cshtml index 89d465f..863eb95 100644 --- a/Views/users/Register.cshtml +++ b/Views/users/Register.cshtml @@ -9,7 +9,22 @@ @using (Html.BeginForm()) { @Html.AntiForgeryToken() - +

    user


    @@ -25,11 +40,17 @@
    @Html.LabelFor(model => model.password, htmlAttributes: new { @class = "control-label col-md-2" })
    - @Html.PasswordFor(model => model.password, new { htmlAttributes = new { @class = "form-control" } }) + @Html.EditorFor(model => model.password, new { htmlAttributes = new {@id="password", @type = "password", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" })
    +
    + + + + +
    diff --git a/WebApplication1.csproj b/WebApplication1.csproj index a7f9555..a666ed9 100644 --- a/WebApplication1.csproj +++ b/WebApplication1.csproj @@ -142,8 +142,9 @@ - + + Global.asax @@ -257,6 +258,16 @@ + + + + + + + + + +