From 9403347e1e120c9541c3f6d0432335c1748df232 Mon Sep 17 00:00:00 2001 From: Nobir Date: Wed, 20 Jul 2022 15:24:09 +0600 Subject: [PATCH] [Added] added create permission --- Controllers/AdminController.cs | 38 +++++++++- ERPSystemTimologio.csproj | 2 + Models/PermissionCreateAdminModel.cs | 31 ++++++++ Views/Admin/CreatePermission.cshtml | 106 +++++++++++++++++++++++++++ 4 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 Models/PermissionCreateAdminModel.cs create mode 100644 Views/Admin/CreatePermission.cshtml diff --git a/Controllers/AdminController.cs b/Controllers/AdminController.cs index a68c5dd..95c64d2 100644 --- a/Controllers/AdminController.cs +++ b/Controllers/AdminController.cs @@ -9,7 +9,7 @@ namespace ERPSystemTimologio.Controllers { - //[LoggedIn, IsAdmin] + [LoggedIn, IsAdmin] public class AdminController : Controller { private readonly TimologioEntities db = new TimologioEntities(); @@ -19,6 +19,42 @@ public ActionResult Index() return View(); } + [HttpGet] + public ActionResult CreatePermission() + { + return View(); + } + + [HttpPost] + public ActionResult CreatePermission(PermissionCreateAdminModel _permission) + { + if(!ModelState.IsValid) + { + return View(_permission); + } + + var permission = new Permission + { + Name = _permission.Name.ToString(), + InvoiceAdd = _permission.InvoiceAdd != null ? 1 : 0, + InvoiceManage = _permission.InvoiceManage != null ? 1 : 0, + InventoryManage = _permission.InventoryManage != null ? 1 : 0, + CategoryManage = _permission.CategoryManage != null ? 1 : 0, + StationManage = _permission.StationManage != null ? 1 : 0, + OperationManage = _permission.OperationManage != null ? 1 : 0, + UserManage = _permission.UserManage != null ? 1 : 0, + PermissionManage = _permission.PermissionManage != null ? 1 : 0, + }; + + this.db.Permissions.Add(permission); + + this.db.SaveChanges(); + + TempData["success_message"] = "Successfully created Permission"; + + return RedirectToAction("CreatePermission", "Admin"); + } + public ActionResult VerifyUser(int id) { var user = this.db.Users.Where(u => u.Id == id).SingleOrDefault(); diff --git a/ERPSystemTimologio.csproj b/ERPSystemTimologio.csproj index c05d7f1..d3038a1 100644 --- a/ERPSystemTimologio.csproj +++ b/ERPSystemTimologio.csproj @@ -194,6 +194,7 @@ Global.asax + @@ -283,6 +284,7 @@ + diff --git a/Models/PermissionCreateAdminModel.cs b/Models/PermissionCreateAdminModel.cs new file mode 100644 index 0000000..d9a1376 --- /dev/null +++ b/Models/PermissionCreateAdminModel.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Web; +using ERPSystemTimologio.EF; + +namespace ERPSystemTimologio.Models +{ + public class PermissionCreateAdminModel : Permission + { + [Required, MinLength(3)] + public new string Name { get; set; } + + public new string InvoiceAdd { get; set; } + + public new string InvoiceManage { get; set; } + + public new string InventoryManage { get; set; } + + public new string CategoryManage { get; set; } + + public new string StationManage { get; set; } + + public new string OperationManage { get; set; } + + public new string UserManage { get; set; } + + public new string PermissionManage { get; set; } + } +} \ No newline at end of file diff --git a/Views/Admin/CreatePermission.cshtml b/Views/Admin/CreatePermission.cshtml new file mode 100644 index 0000000..2654ca3 --- /dev/null +++ b/Views/Admin/CreatePermission.cshtml @@ -0,0 +1,106 @@ +@model ERPSystemTimologio.Models.PermissionCreateAdminModel +@{ + ViewBag.Title = "CreatePermission"; +} + +
+
+ +
+ + + @if (!ViewData.ModelState.IsValidField("Name")) + { + + @Html.ValidationMessage("Name") + + } +
+
+
+ Permission: +
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+ +
+
+
\ No newline at end of file