From 62c476a253f969d1c974ea5fc1dcc09664afa91d Mon Sep 17 00:00:00 2001 From: Kiyan Date: Thu, 24 Jul 2025 10:39:39 +0330 Subject: [PATCH] making dashboard --- test/Controllers/UsersController.cs | 101 +++++++++++++++++++++++++++- test/Views/Users/Dashboard.cshtml | 97 ++++++++++++++++++++++++++ test/test.csproj | 1 + 3 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 test/Views/Users/Dashboard.cshtml diff --git a/test/Controllers/UsersController.cs b/test/Controllers/UsersController.cs index 8639ca7..a6bcdf1 100644 --- a/test/Controllers/UsersController.cs +++ b/test/Controllers/UsersController.cs @@ -8,10 +8,13 @@ using System.Web; using System.Web.Mvc; using test.Models; + + namespace test.Controllers { public class UsersController : Controller { + private testEntities db = new testEntities(); // GET: Users @@ -58,6 +61,28 @@ namespace test.Controllers 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 public ActionResult Edit(int? id) { @@ -95,7 +120,8 @@ namespace test.Controllers Session["UserName"] = user.User_Name; // انتقال به صفحه اصلی - return RedirectToAction("Index", "Home"); + return RedirectToAction("Dashboard", "Users"); + } ViewBag.Message = "شماره یا رمز عبور اشتباه است."; @@ -118,6 +144,9 @@ namespace test.Controllers return View(user); } + + + // GET: Users/Delete/5 public ActionResult Delete(int? id) { @@ -133,6 +162,9 @@ namespace test.Controllers return View(user); } + + + // POST: Users/Delete/5 [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] @@ -152,5 +184,72 @@ namespace test.Controllers } 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"); + } + + + + + + + } } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/Views/Users/Dashboard.cshtml b/test/Views/Users/Dashboard.cshtml new file mode 100644 index 0000000..e8f026d --- /dev/null +++ b/test/Views/Users/Dashboard.cshtml @@ -0,0 +1,97 @@ +@using test.Models +@{ + ViewBag.Title = "پنل کاربری"; + var name = Session["UserName"]; + var Categories = ViewBag.Categories as List; + var tag = ViewBag.tag as List; +} + +

به پنل خوش آمدید

+ +

سلام @name عزیز 🎉

+ +خروج + +@{ + ViewBag.Title = "داشبورد"; +} + +

به پنل خوش آمدید، @Session["UserName"]

+ +
+ +@if (TempData["CategoryMessage"] != null) +{ +

@TempData["CategoryMessage"]

+} +@if (TempData["TagMessage"] != null) +{ +

@TempData["TagMessage"]

+} + +
+
+

افزودن دسته‌بندی جدید

+ @using (Html.BeginForm("AddCategoryFromDashboard", "Users", FormMethod.Post)) + { + @Html.AntiForgeryToken() +
+ + +
+ + } +
+ +
+

افزودن تگ جدید

+ @using (Html.BeginForm("AddTagFromDashboard", "Users", FormMethod.Post)) + { + @Html.AntiForgeryToken() +
+ + +
+ + } +
+
+ +

لیست دسته‌بندی‌ها

+ + + + + + + + + @foreach (var cat in Categories) + { + + + + + } + + +
شناسهعنوان
@cat.Category_ID@cat.Catgegory_Title
+

لیست تگ‌ها

+ + + + + + + + + @foreach (var tagg in tag) + { + + + + + } + +
شناسهعنوان
@tagg.Tag_ID@tagg.Tag_Title
+ diff --git a/test/test.csproj b/test/test.csproj index 72c7d93..fab0d2f 100644 --- a/test/test.csproj +++ b/test/test.csproj @@ -289,6 +289,7 @@ +