Dodano konntroler kategorii
This commit is contained in:
parent
8e90b463ae
commit
70bdf02761
@ -20,9 +20,7 @@ namespace Forum.Controllers
|
|||||||
private ApplicationSignInManager _signInManager;
|
private ApplicationSignInManager _signInManager;
|
||||||
private ApplicationUserManager _userManager;
|
private ApplicationUserManager _userManager;
|
||||||
|
|
||||||
public AccountController()
|
public AccountController(){}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager )
|
public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager )
|
||||||
{
|
{
|
||||||
@ -138,7 +136,7 @@ namespace Forum.Controllers
|
|||||||
|
|
||||||
//
|
//
|
||||||
// GET: /Account/Register
|
// GET: /Account/Register
|
||||||
[AllowAnonymous]
|
[Authorize]
|
||||||
public ActionResult Register()
|
public ActionResult Register()
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
@ -147,7 +145,7 @@ namespace Forum.Controllers
|
|||||||
//
|
//
|
||||||
// POST: /Account/Register
|
// POST: /Account/Register
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[AllowAnonymous]
|
[Authorize]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
public async Task<ActionResult> Register(RegisterViewModel model)
|
public async Task<ActionResult> Register(RegisterViewModel model)
|
||||||
{
|
{
|
||||||
|
114
Trunk/Server/Forum/Forum/Controllers/CategoriesController.cs
Normal file
114
Trunk/Server/Forum/Forum/Controllers/CategoriesController.cs
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
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 Forum.DataAccessLayer;
|
||||||
|
using Forum.DataAccessLayer.Models;
|
||||||
|
|
||||||
|
namespace Forum.Controllers
|
||||||
|
{
|
||||||
|
[Authorize]
|
||||||
|
public class CategoriesController : Controller
|
||||||
|
{
|
||||||
|
private ApplicationDbContext db = new ApplicationDbContext();
|
||||||
|
|
||||||
|
// GET: Categories
|
||||||
|
public ActionResult Index()
|
||||||
|
{
|
||||||
|
return View(db.Categories.ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: Categories/Create
|
||||||
|
public ActionResult Create()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: Categories/Create
|
||||||
|
// To protect from overposting attacks, please 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,CategoryName")] Category category)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
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, please 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,CategoryName")] 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -176,6 +176,7 @@
|
|||||||
<Compile Include="App_Start\RouteConfig.cs" />
|
<Compile Include="App_Start\RouteConfig.cs" />
|
||||||
<Compile Include="App_Start\Startup.Auth.cs" />
|
<Compile Include="App_Start\Startup.Auth.cs" />
|
||||||
<Compile Include="Controllers\AccountController.cs" />
|
<Compile Include="Controllers\AccountController.cs" />
|
||||||
|
<Compile Include="Controllers\CategoriesController.cs" />
|
||||||
<Compile Include="Controllers\HomeController.cs" />
|
<Compile Include="Controllers\HomeController.cs" />
|
||||||
<Compile Include="Controllers\ManageController.cs" />
|
<Compile Include="Controllers\ManageController.cs" />
|
||||||
<Compile Include="Global.asax.cs">
|
<Compile Include="Global.asax.cs">
|
||||||
@ -279,9 +280,14 @@
|
|||||||
<Content Include="Scripts\popper-utils.js.map" />
|
<Content Include="Scripts\popper-utils.js.map" />
|
||||||
<Content Include="Views\Home\AddQuestion.cshtml" />
|
<Content Include="Views\Home\AddQuestion.cshtml" />
|
||||||
<Content Include="Views\Home\AddAnswer.cshtml" />
|
<Content Include="Views\Home\AddAnswer.cshtml" />
|
||||||
|
<Content Include="Views\Categories\Create.cshtml" />
|
||||||
|
<Content Include="Views\Categories\Delete.cshtml" />
|
||||||
|
<Content Include="Views\Categories\Edit.cshtml" />
|
||||||
|
<Content Include="Views\Categories\Index.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="App_Data\" />
|
<Folder Include="App_Data\" />
|
||||||
|
<Folder Include="Views\Professional\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
40
Trunk/Server/Forum/Forum/Views/Categories/Create.cshtml
Normal file
40
Trunk/Server/Forum/Forum/Views/Categories/Create.cshtml
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
@model Forum.DataAccessLayer.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.CategoryName, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||||
|
<div class="col-md-10">
|
||||||
|
@Html.EditorFor(model => model.CategoryName, new { htmlAttributes = new { @class = "form-control" } })
|
||||||
|
@Html.ValidationMessageFor(model => model.CategoryName, "", 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>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
@Scripts.Render("~/bundles/jqueryval")
|
||||||
|
}
|
32
Trunk/Server/Forum/Forum/Views/Categories/Delete.cshtml
Normal file
32
Trunk/Server/Forum/Forum/Views/Categories/Delete.cshtml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
@model Forum.DataAccessLayer.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.CategoryName)
|
||||||
|
</dt>
|
||||||
|
|
||||||
|
<dd>
|
||||||
|
@Html.DisplayFor(model => model.CategoryName)
|
||||||
|
</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>
|
42
Trunk/Server/Forum/Forum/Views/Categories/Edit.cshtml
Normal file
42
Trunk/Server/Forum/Forum/Views/Categories/Edit.cshtml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
@model Forum.DataAccessLayer.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.CategoryName, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||||
|
<div class="col-md-10">
|
||||||
|
@Html.EditorFor(model => model.CategoryName, new { htmlAttributes = new { @class = "form-control" } })
|
||||||
|
@Html.ValidationMessageFor(model => model.CategoryName, "", 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>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
@Scripts.Render("~/bundles/jqueryval")
|
||||||
|
}
|
32
Trunk/Server/Forum/Forum/Views/Categories/Index.cshtml
Normal file
32
Trunk/Server/Forum/Forum/Views/Categories/Index.cshtml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
@model IEnumerable<Forum.DataAccessLayer.Models.Category>
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewBag.Title = "Index";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>Index</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
@Html.ActionLink("Create New", "Create")
|
||||||
|
</p>
|
||||||
|
<table class="table">
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
@Html.DisplayNameFor(model => model.CategoryName)
|
||||||
|
</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
@foreach (var item in Model) {
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.CategoryName)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
|
||||||
|
@Html.ActionLink("Delete", "Delete", new { id=item.Id })
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
|
||||||
|
</table>
|
@ -20,10 +20,11 @@
|
|||||||
@Html.ActionLink("FORUM", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
|
@Html.ActionLink("FORUM", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
|
||||||
</div>
|
</div>
|
||||||
<div class="navbar-collapse collapse">
|
<div class="navbar-collapse collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li>@Html.ActionLink("Home", "Index", "Home")</li>
|
@if (User.Identity.IsAuthenticated)
|
||||||
<li>@Html.ActionLink("About", "About", "Home")</li>
|
{
|
||||||
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
|
<li>@Html.ActionLink("Zarządzaj kategoriami", "Index", "Categories")</li>
|
||||||
|
}
|
||||||
</ul>
|
</ul>
|
||||||
@Html.Partial("_LoginPartial")
|
@Html.Partial("_LoginPartial")
|
||||||
</div>
|
</div>
|
||||||
@ -33,7 +34,7 @@
|
|||||||
@RenderBody()
|
@RenderBody()
|
||||||
<hr />
|
<hr />
|
||||||
<footer>
|
<footer>
|
||||||
<p>© @DateTime.Now.Year - My ASP.NET Application</p>
|
<p>© @DateTime.Now.Year - Grupa 1CF Inżynieria oprogramowania</p>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -9,14 +9,14 @@
|
|||||||
<li>
|
<li>
|
||||||
@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
|
@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
|
||||||
</li>
|
</li>
|
||||||
|
<li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
|
||||||
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
|
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
<li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
|
<li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new {id = "loginLink"})</li>
|
||||||
<li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user