Skip to content

Commit

Permalink
[Added] added create permission
Browse files Browse the repository at this point in the history
  • Loading branch information
nobir committed Jul 20, 2022
1 parent 66198df commit 9403347
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 1 deletion.
38 changes: 37 additions & 1 deletion Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace ERPSystemTimologio.Controllers
{
//[LoggedIn, IsAdmin]
[LoggedIn, IsAdmin]
public class AdminController : Controller
{
private readonly TimologioEntities db = new TimologioEntities();
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions ERPSystemTimologio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Models\PermissionCreateAdminModel.cs" />
<Compile Include="Models\ProfilePicture.cs" />
<Compile Include="Models\UniqueEmailValidation.cs" />
<Compile Include="Models\UniqueUsernameValidation.cs" />
Expand Down Expand Up @@ -283,6 +284,7 @@
<Content Include="Views\Admin\ViewUnverifiedUsers.cshtml" />
<Content Include="Views\Dashboard\ViewProfile.cshtml" />
<Content Include="Views\Dashboard\ProfilePicture.cshtml" />
<Content Include="Views\Admin\CreatePermission.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
Expand Down
31 changes: 31 additions & 0 deletions Models/PermissionCreateAdminModel.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
106 changes: 106 additions & 0 deletions Views/Admin/CreatePermission.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
@model ERPSystemTimologio.Models.PermissionCreateAdminModel
@{
ViewBag.Title = "CreatePermission";
}

<form id="create-permission-form" action="@Url.Action("CreatePermission", "Admin")" method="post" class="needs-validation">
<div class="row mb-3 has-validation">
<label for="name" class="col-sm-3 col-form-label">Permission Name</label>
<div class="col-sm-9">
<input id="name"
type="text"
name="Name"
class="@(!ViewData.ModelState.IsValidField("Name") ? "is-invalid" : "") form-control @(Model != null && Model.Name != null && ViewData.ModelState.IsValidField("Name") ? "is-valid" : "")"
value="@(Model != null && Model.Name != null ? Model.Name.ToString() : "")"
placeholder="e.g Admin">

@if (!ViewData.ModelState.IsValidField("Name"))
{
<span class="invalid-feedback" role="alert">
<strong>@Html.ValidationMessage("Name")</strong>
</span>
}
</div>
</div>
<fieldset class="row mb-3">
<legend class="col-form-label col-sm-3 pt-0">Permission:</legend>
<div class="col-sm-9">
<div class="form-check">
<input id="invoice_add" type="checkbox" name="InvoiceAdd"
class="form-check-input @(Model != null && Model.InvoiceAdd != null && Model.InvoiceAdd.Equals("InvoiceAdd") && ViewData.ModelState.IsValidField("InvoiceAdd") ? "is-valid" : "")"
value="InvoiceAdd"
@(Model != null && Model.InvoiceAdd != null && Model.InvoiceAdd.Equals("InvoiceAdd") ? "checked" : "" )>
<label for="invoice_add" class="form-check-label">Invoice Add</label>
</div>
</div>
<div class="col-sm-9">
<div class="form-check">
<input id="invoice_manage" type="checkbox" name="InvoiceManage"
class="form-check-input @(Model != null && Model.InvoiceManage != null && Model.InvoiceManage.Equals("InvoiceManage") && ViewData.ModelState.IsValidField("InvoiceManage") ? "is-valid" : "")"
value="InvoiceManage"
@(Model != null && Model.InvoiceManage != null && Model.InvoiceManage.Equals("InvoiceManage") ? "checked" : "" )>
<label for="invoice_manage" class="form-check-label">Invoice Manage</label>
</div>
</div>
<div class="col-sm-9">
<div class="form-check">
<input id="inventory_manage" type="checkbox" name="InventoryManage"
class="form-check-input @(Model != null && Model.InventoryManage != null && Model.InventoryManage.Equals("InventoryManage") && ViewData.ModelState.IsValidField("InventoryManage") ? "is-valid" : "")"
value="InventoryManage"
@(Model != null && Model.InventoryManage != null && Model.InventoryManage.Equals("InventoryManage") ? "checked" : "" )>
<label for="inventory_manage" class="form-check-label">Inventory Manage</label>
</div>
</div>
<div class="col-sm-9">
<div class="form-check">
<input id="category_manage" type="checkbox" name="CategoryManage"
class="form-check-input @(Model != null && Model.CategoryManage != null && Model.CategoryManage.Equals("CategoryManage") && ViewData.ModelState.IsValidField("CategoryManage") ? "is-valid" : "")"
value="CategoryManage"
@(Model != null && Model.CategoryManage != null && Model.CategoryManage.Equals("CategoryManage") ? "checked" : "" )>
<label for="category_manage" class="form-check-label">Category Manage</label>
</div>
</div>
<div class="col-sm-9">
<div class="form-check">
<input id="station_manage" type="checkbox" name="StationManage"
class="form-check-input @(Model != null && Model.StationManage != null && Model.StationManage.Equals("StationManage") && ViewData.ModelState.IsValidField("StationManage") ? "is-valid" : "")"
value="StationManage"
@(Model != null && Model.StationManage != null && Model.StationManage.Equals("StationManage") ? "checked" : "" )>
<label for="station_manage" class="form-check-label">Station Manage</label>
</div>
</div>
<div class="col-sm-9">
<div class="form-check">
<input id="operation_manage" type="checkbox" name="OperationManage "
class="form-check-input @(Model != null && Model.OperationManage != null && Model.OperationManage.Equals("OperationManage") && ViewData.ModelState.IsValidField("OperationManage") ? "is-valid" : "")"
value="OperationManage"
@(Model != null && Model.OperationManage != null && Model.OperationManage.Equals("OperationManage") ? "checked" : "" )>
<label for="operation_manage" class="form-check-label">Operation Manage</label>
</div>
</div>
<div class="col-sm-9">
<div class="form-check">
<input id="user_manage" type="checkbox" name="UserManage"
class="form-check-input @(Model != null && Model.UserManage != null && Model.UserManage.Equals("UserManage") && ViewData.ModelState.IsValidField("UserManage") ? "is-valid" : "")"
value="UserManage"
@(Model != null && Model.UserManage != null && Model.UserManage.Equals("UserManage") ? "checked" : "" )>
<label for="user_manage" class="form-check-label">User Manage</label>
</div>
</div>
<div class="col-sm-9">
<div class="form-check">
<input id="permission_manage" type="checkbox" name="PermissionManage"
class="form-check-input @(Model != null && Model.PermissionManage != null && Model.PermissionManage.Equals("PermissionManage") && ViewData.ModelState.IsValidField("PermissionManage") ? "is-valid" : "")"
value="PermissionManage"
@(Model != null && Model.PermissionManage != null && Model.PermissionManage.Equals("PermissionManage") ? "checked" : "" )>
<label for="permission_manage" class="form-check-label">Permission Manage</label>
</div>
</div>
</fieldset>

<div class="row mb-3">
<div class="col-sm-9 offset-sm-3">
<button id="create-permission-btn" type="submit" class="btn btn-success">Add</button>
</div>
</div>
</form>

0 comments on commit 9403347

Please sign in to comment.