-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from GerardGargan/dev
Merge dev to master
- Loading branch information
Showing
5 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Bookstore.DataAccess.Data; | ||
using Bookstore.DataAccess.Repository.IRepository; | ||
using Bookstore.Models; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace BookstoreWeb.Areas.Admin.Controllers | ||
{ | ||
[Area("Admin")] | ||
public class UserController : Controller | ||
{ | ||
private readonly IUnitOfWork _unitOfWork; | ||
private readonly ApplicationDbContext _db; | ||
|
||
public UserController(IUnitOfWork unitOfWork, ApplicationDbContext db) | ||
{ | ||
_unitOfWork = unitOfWork; | ||
_db = db; | ||
} | ||
|
||
public IActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
|
||
#region | ||
|
||
[HttpGet] | ||
public IActionResult GetAll() | ||
{ | ||
List<ApplicationUser> allUsers = _unitOfWork.User.GetAll(includeProperties: "Company").ToList(); | ||
// get all roles and user roles | ||
var userRoles = _db.UserRoles.ToList(); | ||
var roles = _db.Roles.ToList(); | ||
|
||
foreach(var user in allUsers) | ||
{ | ||
var roleId = userRoles.FirstOrDefault(x => x.UserId == user.Id).RoleId; | ||
user.Role = roles.FirstOrDefault(x => x.Id == roleId).Name; | ||
|
||
if(user.Company == null) | ||
{ | ||
user.Company = new Company() { Name = "" }; | ||
} | ||
} | ||
|
||
return Json(new { data = allUsers }); | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<div class="card shadow border-0 my-4"> | ||
<div class="card-header bg-primary bg-gradient ml-0 py-3"> | ||
<div class="col-12 text-center"> | ||
<h2 class="text-white py-2">User List</h2> | ||
</div> | ||
</div> | ||
<div class="card-body p-4"> | ||
<table id="tblData" class="table table-bordered table-striped" style="width:100%"> | ||
<thead> | ||
<tr> | ||
<th> | ||
Name | ||
</th> | ||
<th> | ||
</th> | ||
<th> | ||
Phone | ||
</th> | ||
<th> | ||
Company | ||
</th> | ||
<th> | ||
Role | ||
</th> | ||
<th> | ||
</th> | ||
</tr> | ||
</thead> | ||
</table> | ||
</div> | ||
</div> | ||
|
||
@section Scripts { | ||
<script src="~/js/user.js"></script> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
$(document).ready(function () { | ||
loadDataTable(); | ||
}); | ||
|
||
function loadDataTable() { | ||
dataTable = $('#tblData').DataTable({ | ||
ajax: '/admin/user/getall', | ||
"columns": [ | ||
{ data: 'name', "width": "15%" }, | ||
{ data: 'email', "width": "25%" }, | ||
{ data: 'phoneNumber', "width": "10%" }, | ||
{ data: 'company.name', "width": "10%" }, | ||
{ data: 'role', "width": "10%" }, | ||
{ | ||
data: 'id', | ||
"render": function (data) { | ||
return `<div class="w-75 btn-group" role="group"> | ||
<a href="/Admin/User/Upsert/${data}" class="btn btn-primary mx-1"><i class="bi bi-pencil-square"></i> Edit</a> | ||
</div>` | ||
}, | ||
"width": "25%" | ||
} | ||
] | ||
}); | ||
} |