making dashboard
This commit is contained in:
@ -8,10 +8,13 @@ using System.Web;
|
|||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using test.Models;
|
using test.Models;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace test.Controllers
|
namespace test.Controllers
|
||||||
{
|
{
|
||||||
public class UsersController : Controller
|
public class UsersController : Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
private testEntities db = new testEntities();
|
private testEntities db = new testEntities();
|
||||||
|
|
||||||
// GET: Users
|
// GET: Users
|
||||||
@ -58,6 +61,28 @@ namespace test.Controllers
|
|||||||
return View(user);
|
return View(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ActionResult Dashboard()
|
||||||
|
{
|
||||||
|
// اگر کاربر لاگین نکرده بود، منتقلش کن به لاگین
|
||||||
|
if (Session["UserID"] == null)
|
||||||
|
return RedirectToAction("Login");
|
||||||
|
|
||||||
|
|
||||||
|
ViewBag.Categories = db.Categories.ToList();
|
||||||
|
ViewBag.tag = db.Tags.ToList();
|
||||||
|
|
||||||
|
return View();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionResult Logout()
|
||||||
|
{
|
||||||
|
Session.Clear(); // یا Session.Abandon()
|
||||||
|
return RedirectToAction("Login");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// GET: Users/Edit/5
|
// GET: Users/Edit/5
|
||||||
public ActionResult Edit(int? id)
|
public ActionResult Edit(int? id)
|
||||||
{
|
{
|
||||||
@ -95,7 +120,8 @@ namespace test.Controllers
|
|||||||
Session["UserName"] = user.User_Name;
|
Session["UserName"] = user.User_Name;
|
||||||
|
|
||||||
// انتقال به صفحه اصلی
|
// انتقال به صفحه اصلی
|
||||||
return RedirectToAction("Index", "Home");
|
return RedirectToAction("Dashboard", "Users");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewBag.Message = "شماره یا رمز عبور اشتباه است.";
|
ViewBag.Message = "شماره یا رمز عبور اشتباه است.";
|
||||||
@ -118,6 +144,9 @@ namespace test.Controllers
|
|||||||
return View(user);
|
return View(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// GET: Users/Delete/5
|
// GET: Users/Delete/5
|
||||||
public ActionResult Delete(int? id)
|
public ActionResult Delete(int? id)
|
||||||
{
|
{
|
||||||
@ -133,6 +162,9 @@ namespace test.Controllers
|
|||||||
return View(user);
|
return View(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// POST: Users/Delete/5
|
// POST: Users/Delete/5
|
||||||
[HttpPost, ActionName("Delete")]
|
[HttpPost, ActionName("Delete")]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
@ -152,5 +184,72 @@ namespace test.Controllers
|
|||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public ActionResult AddCategoryFromDashboard(Category category)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
db.Categories.Add(category);
|
||||||
|
db.SaveChanges();
|
||||||
|
TempData["CategoryMessage"] = "دستهبندی با موفقیت اضافه شد.";
|
||||||
|
}
|
||||||
|
return RedirectToAction("Dashboard");
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public ActionResult AddTagFromDashboard(Tag tag)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
db.Tags.Add(tag);
|
||||||
|
db.SaveChanges();
|
||||||
|
TempData["TagMessage"] = "تگ با موفقیت اضافه شد.";
|
||||||
|
}
|
||||||
|
return RedirectToAction("Dashboard");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
97
test/Views/Users/Dashboard.cshtml
Normal file
97
test/Views/Users/Dashboard.cshtml
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
@using test.Models
|
||||||
|
@{
|
||||||
|
ViewBag.Title = "پنل کاربری";
|
||||||
|
var name = Session["UserName"];
|
||||||
|
var Categories = ViewBag.Categories as List<Category>;
|
||||||
|
var tag = ViewBag.tag as List<Tag>;
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>به پنل خوش آمدید</h2>
|
||||||
|
|
||||||
|
<p>سلام @name عزیز 🎉</p>
|
||||||
|
|
||||||
|
<a href="@Url.Action("Logout", "Users")" class="btn btn-danger">خروج</a>
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewBag.Title = "داشبورد";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>به پنل خوش آمدید، @Session["UserName"]</h2>
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
|
||||||
|
@if (TempData["CategoryMessage"] != null)
|
||||||
|
{
|
||||||
|
<p class="alert alert-success">@TempData["CategoryMessage"]</p>
|
||||||
|
}
|
||||||
|
@if (TempData["TagMessage"] != null)
|
||||||
|
{
|
||||||
|
<p class="alert alert-success">@TempData["TagMessage"]</p>
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<h4>افزودن دستهبندی جدید</h4>
|
||||||
|
@using (Html.BeginForm("AddCategoryFromDashboard", "Users", FormMethod.Post))
|
||||||
|
{
|
||||||
|
@Html.AntiForgeryToken()
|
||||||
|
<div class="form-group">
|
||||||
|
<label>عنوان دستهبندی</label>
|
||||||
|
<input type="text" name="Catgegory_Title" class="form-control" required />
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-success">افزودن دستهبندی</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6">
|
||||||
|
<h4>افزودن تگ جدید</h4>
|
||||||
|
@using (Html.BeginForm("AddTagFromDashboard", "Users", FormMethod.Post))
|
||||||
|
{
|
||||||
|
@Html.AntiForgeryToken()
|
||||||
|
<div class="form-group">
|
||||||
|
<label>عنوان تگ</label>
|
||||||
|
<input type="text" name="Tag_Title" class="form-control" required />
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-success">افزودن تگ</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h4 class="mt-5">لیست دستهبندیها</h4>
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>شناسه</th>
|
||||||
|
<th>عنوان</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var cat in Categories)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>@cat.Category_ID</td>
|
||||||
|
<td>@cat.Catgegory_Title</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<h4 class="mt-4">لیست تگها</h4>
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>شناسه</th>
|
||||||
|
<th>عنوان</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var tagg in tag)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>@tagg.Tag_ID</td>
|
||||||
|
<td>@tagg.Tag_Title</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
@ -289,6 +289,7 @@
|
|||||||
<Content Include="Views\Users\Edit.cshtml" />
|
<Content Include="Views\Users\Edit.cshtml" />
|
||||||
<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\Dashboard.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="App_Data\" />
|
<Folder Include="App_Data\" />
|
||||||
|
|||||||
Reference in New Issue
Block a user