add categories(add, list, list news)

minor form changes
add news controller and views
This commit is contained in:
2024-07-28 18:35:11 +03:30
parent 30ac6724ca
commit a74072b491
22 changed files with 1092 additions and 148 deletions

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -16,7 +16,15 @@ namespace WebApplication1.Controllers
// GET: users // GET: users
public ActionResult Index() public ActionResult Index()
{ if (Convert.ToInt32(Session["Userrole"]) > 0)
{ {
@ViewBag.role = "admin";
}
else
{
@ViewBag.role = "user";
}
if (Session["User"] != null) if (Session["User"] != null)
{ {
if (Session["Userid"] == null) if (Session["Userid"] == null)
@ -33,12 +41,19 @@ namespace WebApplication1.Controllers
else else
return RedirectToAction("Login"); return RedirectToAction("Login");
}// GET: users }// GET: users
public ActionResult allusers() public ActionResult allusers()
{ {
if (Session["User"] != null) if (Session["User"] != null)
{
if (Convert.ToInt32(Session["Userrole"]) == 1)
{ {
return View(db.users.ToList()); return View(db.users.ToList());
} }
else {
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
}
}
else else
return RedirectToAction("Login"); return RedirectToAction("Login");
} }
@ -56,7 +71,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 Register([Bind(Include = "ID,usename,password,displayname")] user user) public ActionResult Register([Bind(Include = "ID,usename,password,displayname,role")] user user)
{ {
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
@ -79,6 +94,7 @@ namespace WebApplication1.Controllers
//session start //session start
Session["User"] = user.usename; Session["User"] = user.usename;
Session["Userid"] = user.ID; Session["Userid"] = user.ID;
Session["Userrole"] = user.role;
return RedirectToAction("Index"); return RedirectToAction("Index");
} }
@ -123,6 +139,7 @@ namespace WebApplication1.Controllers
//session start //session start
Session["User"] = existingUser.usename; Session["User"] = existingUser.usename;
Session["Userid"] = existingUser.ID; Session["Userid"] = existingUser.ID;
Session["Userrole"] = existingUser.role;
return RedirectToAction("Index"); return RedirectToAction("Index");
} }
@ -161,7 +178,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 Edit([Bind(Include = "ID,usename,password,displayname")] user user) public ActionResult Edit([Bind(Include = "ID,usename,password,displayname,role")] user user)
{ {
if (ModelState.IsValid) if (ModelState.IsValid)
{ {

View File

@ -55,6 +55,7 @@
<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" MaxLength="50" Nullable="false" />
<Property Name="displayname" Type="nvarchar" MaxLength="50" /> <Property Name="displayname" Type="nvarchar" MaxLength="50" />
<Property Name="role" Type="int" Nullable="false" />
</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" />
@ -124,6 +125,7 @@
<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="50" 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" />
</EntityType> </EntityType>
</Schema> </Schema>
</edmx:ConceptualModels> </edmx:ConceptualModels>
@ -180,6 +182,7 @@
<EntitySetMapping Name="users"> <EntitySetMapping Name="users">
<EntityTypeMapping TypeName="newswebappModel.user"> <EntityTypeMapping TypeName="newswebappModel.user">
<MappingFragment StoreEntitySet="user"> <MappingFragment StoreEntitySet="user">
<ScalarProperty Name="role" ColumnName="role" />
<ScalarProperty Name="displayname" ColumnName="displayname" /> <ScalarProperty Name="displayname" ColumnName="displayname" />
<ScalarProperty Name="password" ColumnName="password" /> <ScalarProperty Name="password" ColumnName="password" />
<ScalarProperty Name="usename" ColumnName="usename" /> <ScalarProperty Name="usename" ColumnName="usename" />

View File

@ -18,5 +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; }
} }
} }

View File

@ -21,6 +21,8 @@
<li>@Html.ActionLink("About", "About", "Home", new { area = "" }, new { @class = "nav-link" })</li> <li>@Html.ActionLink("About", "About", "Home", new { area = "" }, new { @class = "nav-link" })</li>
<li>@Html.ActionLink("Contact", "Contact", "Home", new { area = "" }, new { @class = "nav-link" })</li> <li>@Html.ActionLink("Contact", "Contact", "Home", new { area = "" }, new { @class = "nav-link" })</li>
<li>@Html.ActionLink("user setting", "index", "users", new { area = "" }, new { @class = "nav-link" })</li> <li>@Html.ActionLink("user setting", "index", "users", new { area = "" }, new { @class = "nav-link" })</li>
<li>@Html.ActionLink("news", "index", "users", new { area = "" }, new { @class = "nav-link" })</li>
<li>@Html.ActionLink("categories", "index", "categories", new { area = "" }, new { @class = "nav-link" })</li>
</ul> </ul>
</div> </div>

View File

@ -0,0 +1,36 @@
@model WebApplication1.Models.category
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>category</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.title, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.title, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>

View File

@ -0,0 +1,40 @@
@model WebApplication1.Models.category
@{
ViewBag.Title = "Delete";
}
<h2>Delete</h2>
<h3>Are you sure you want to delete this?</h3>
<div>
<h4>category</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.link)
</dt>
<dd>
@Html.DisplayFor(model => model.link)
</dd>
<dt>
@Html.DisplayNameFor(model => model.title)
</dt>
<dd>
@Html.DisplayFor(model => model.title)
</dd>
</dl>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
<div class="form-actions no-color">
<input type="submit" value="Delete" class="btn btn-default" /> |
@Html.ActionLink("Back to List", "Index")
</div>
}
</div>

View File

@ -0,0 +1,49 @@
@model IEnumerable<WebApplication1.Models.news>
@{
ViewBag.Title = @ViewBag.title;
}
<h2>@ViewBag.title</h2>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.title)
</th>
<th>
@Html.DisplayNameFor(model => model.link)
</th>
<th>
@Html.DisplayNameFor(model => model.tag)
</th>
<th>
category
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.title)
</td>
<td>
@Html.DisplayFor(modelItem => item.link)
</td>
<td>
@Html.DisplayFor(modelItem => item.tag)
</td>
<td>
@Html.DisplayFor(modelItem => item.cat)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
</tr>
}
</table>

View File

@ -0,0 +1,45 @@
@model WebApplication1.Models.category
@{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>category</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.ID)
<div class="form-group">
@Html.LabelFor(model => model.link, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.link, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.link, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.title, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.title, "", 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>

View File

@ -0,0 +1,39 @@
@model IEnumerable<WebApplication1.Models.category>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.link)
</th>
<th>
@Html.DisplayNameFor(model => model.title)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.link)
</td>
<td>
@Html.DisplayFor(modelItem => item.title)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
}
</table>

107
Views/news/Create.cshtml Normal file
View File

@ -0,0 +1,107 @@
@model WebApplication1.Models.news
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>news</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.title, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.title, "", new { @class = "text-danger" })
</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">
@Html.LabelFor(model => model.link, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.link, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.link, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.summary, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.summary, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.summary, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.cat, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.cat, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.cat, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.tag, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.tag, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.tag, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.publishDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.publishDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.publishDate, "", new { @class = "text-danger" })
</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">
@Html.LabelFor(model => model.Content, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Content, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Content, "", new { @class = "text-danger" })
</div>
</div>
<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="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>

104
Views/news/Delete.cshtml Normal file
View File

@ -0,0 +1,104 @@
@model WebApplication1.Models.news
@{
ViewBag.Title = "Delete";
}
<h2>Delete</h2>
<h3>Are you sure you want to delete this?</h3>
<div>
<h4>news</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.title)
</dt>
<dd>
@Html.DisplayFor(model => model.title)
</dd>
<dt>
@Html.DisplayNameFor(model => model.image)
</dt>
<dd>
@Html.DisplayFor(model => model.image)
</dd>
<dt>
@Html.DisplayNameFor(model => model.link)
</dt>
<dd>
@Html.DisplayFor(model => model.link)
</dd>
<dt>
@Html.DisplayNameFor(model => model.summary)
</dt>
<dd>
@Html.DisplayFor(model => model.summary)
</dd>
<dt>
@Html.DisplayNameFor(model => model.cat)
</dt>
<dd>
@Html.DisplayFor(model => model.cat)
</dd>
<dt>
@Html.DisplayNameFor(model => model.tag)
</dt>
<dd>
@Html.DisplayFor(model => model.tag)
</dd>
<dt>
@Html.DisplayNameFor(model => model.publishDate)
</dt>
<dd>
@Html.DisplayFor(model => model.publishDate)
</dd>
<dt>
@Html.DisplayNameFor(model => model.userID)
</dt>
<dd>
@Html.DisplayFor(model => model.userID)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Content)
</dt>
<dd>
@Html.DisplayFor(model => model.Content)
</dd>
<dt>
@Html.DisplayNameFor(model => model.views)
</dt>
<dd>
@Html.DisplayFor(model => model.views)
</dd>
</dl>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
<div class="form-actions no-color">
<input type="submit" value="Delete" class="btn btn-default" /> |
@Html.ActionLink("Back to List", "Index")
</div>
}
</div>

98
Views/news/Details.cshtml Normal file
View File

@ -0,0 +1,98 @@
@model WebApplication1.Models.news
@{
ViewBag.Title = "Details";
}
<h2>Details</h2>
<div>
<h4>news</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.title)
</dt>
<dd>
@Html.DisplayFor(model => model.title)
</dd>
<dt>
@Html.DisplayNameFor(model => model.image)
</dt>
<dd>
@Html.DisplayFor(model => model.image)
</dd>
<dt>
@Html.DisplayNameFor(model => model.link)
</dt>
<dd>
@Html.DisplayFor(model => model.link)
</dd>
<dt>
@Html.DisplayNameFor(model => model.summary)
</dt>
<dd>
@Html.DisplayFor(model => model.summary)
</dd>
<dt>
@Html.DisplayNameFor(model => model.cat)
</dt>
<dd>
@Html.DisplayFor(model => model.cat)
</dd>
<dt>
@Html.DisplayNameFor(model => model.tag)
</dt>
<dd>
@Html.DisplayFor(model => model.tag)
</dd>
<dt>
@Html.DisplayNameFor(model => model.publishDate)
</dt>
<dd>
@Html.DisplayFor(model => model.publishDate)
</dd>
<dt>
@Html.DisplayNameFor(model => model.userID)
</dt>
<dd>
@Html.DisplayFor(model => model.userID)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Content)
</dt>
<dd>
@Html.DisplayFor(model => model.Content)
</dd>
<dt>
@Html.DisplayNameFor(model => model.views)
</dt>
<dd>
@Html.DisplayFor(model => model.views)
</dd>
</dl>
</div>
<p>
@Html.ActionLink("Edit", "Edit", new { id = Model.ID }) |
@Html.ActionLink("Back to List", "Index")
</p>

109
Views/news/Edit.cshtml Normal file
View File

@ -0,0 +1,109 @@
@model WebApplication1.Models.news
@{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>news</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.ID)
<div class="form-group">
@Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.title, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.title, "", new { @class = "text-danger" })
</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">
@Html.LabelFor(model => model.link, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.link, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.link, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.summary, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.summary, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.summary, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.cat, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.cat, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.cat, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.tag, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.tag, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.tag, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.publishDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.publishDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.publishDate, "", new { @class = "text-danger" })
</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">
@Html.LabelFor(model => model.Content, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Content, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Content, "", new { @class = "text-danger" })
</div>
</div>
<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="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>

87
Views/news/Index.cshtml Normal file
View File

@ -0,0 +1,87 @@
@model IEnumerable<WebApplication1.Models.news>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.title)
</th>
<th>
@Html.DisplayNameFor(model => model.image)
</th>
<th>
@Html.DisplayNameFor(model => model.link)
</th>
<th>
@Html.DisplayNameFor(model => model.summary)
</th>
<th>
@Html.DisplayNameFor(model => model.cat)
</th>
<th>
@Html.DisplayNameFor(model => model.tag)
</th>
<th>
@Html.DisplayNameFor(model => model.publishDate)
</th>
<th>
@Html.DisplayNameFor(model => model.userID)
</th>
<th>
@Html.DisplayNameFor(model => model.Content)
</th>
<th>
@Html.DisplayNameFor(model => model.views)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.title)
</td>
<td>
@Html.DisplayFor(modelItem => item.image)
</td>
<td>
@Html.DisplayFor(modelItem => item.link)
</td>
<td>
@Html.DisplayFor(modelItem => item.summary)
</td>
<td>
@Html.DisplayFor(modelItem => item.cat)
</td>
<td>
@Html.DisplayFor(modelItem => item.tag)
</td>
<td>
@Html.DisplayFor(modelItem => item.publishDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.userID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Content)
</td>
<td>
@Html.DisplayFor(modelItem => item.views)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
}
</table>

View File

@ -37,6 +37,13 @@
<dd> <dd>
@Html.DisplayFor(model => model.displayname) @Html.DisplayFor(model => model.displayname)
</dd> </dd>
<dt>
@Html.DisplayNameFor(model => model.role)
</dt>
<dd>
@ViewBag.role
</dd>
</dl> </dl>
<div class="col-md-offset-2 col-md-10"> <div class="col-md-offset-2 col-md-10">

View File

@ -25,7 +25,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" } }) @Html.EditorFor(model => model.password, new { htmlAttributes = new {@type="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>

View File

@ -9,7 +9,22 @@
@using (Html.BeginForm()) @using (Html.BeginForm())
{ {
@Html.AntiForgeryToken() @Html.AntiForgeryToken()
<script>
function checkPasswords() {
var password = document.getElementById("password");
var confirmPassword = document.getElementById("ConfirmPassword");
var errorMessage = document.getElementById("passwordMismatch");
if (password.value !== confirmPassword.value) {
errorMessage.textContent = "Passwords do not match.";
return false;
}
else {
errorMessage.textContent = "";
return true;
}
}
</script>
<div class="form-horizontal"> <div class="form-horizontal">
<h4>user</h4> <h4>user</h4>
<hr /> <hr />
@ -25,11 +40,17 @@
<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.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" }) @Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" })
</div> </div>
</div> </div>
<div class="form-group">
<label class="control-label col-md-2">Confirm password</label>
<input type="password" , id="ConfirmPassword", oninput="checkPasswords()" class="form-control" />
<span asp-validation-for="ConfirmPassword" class="text-danger"></span>
<span id="passwordMismatch" class="text-danger"></span>
</div>
<div class="form-group"> <div class="form-group">

View File

@ -142,8 +142,9 @@
<Compile Include="App_Start\FilterConfig.cs" /> <Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" /> <Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\WebApiConfig.cs" /> <Compile Include="App_Start\WebApiConfig.cs" />
<Compile Include="Controllers\AccountController.cs" /> <Compile Include="Controllers\categoriesController.cs" />
<Compile Include="Controllers\HomeController.cs" /> <Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\newsController.cs" />
<Compile Include="Controllers\usersController.cs" /> <Compile Include="Controllers\usersController.cs" />
<Compile Include="Global.asax.cs"> <Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon> <DependentUpon>Global.asax</DependentUpon>
@ -257,6 +258,16 @@
<Content Include="Views\users\Index.cshtml" /> <Content Include="Views\users\Index.cshtml" />
<Content Include="Views\users\Login.cshtml" /> <Content Include="Views\users\Login.cshtml" />
<Content Include="Views\users\allusers.cshtml" /> <Content Include="Views\users\allusers.cshtml" />
<Content Include="Views\categories\Create.cshtml" />
<Content Include="Views\categories\Delete.cshtml" />
<Content Include="Views\categories\Details.cshtml" />
<Content Include="Views\categories\Edit.cshtml" />
<Content Include="Views\categories\Index.cshtml" />
<Content Include="Views\news\Create.cshtml" />
<Content Include="Views\news\Delete.cshtml" />
<Content Include="Views\news\Details.cshtml" />
<Content Include="Views\news\Edit.cshtml" />
<Content Include="Views\news\Index.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="App_Data\" /> <Folder Include="App_Data\" />