Skip to content
Open
92 changes: 92 additions & 0 deletions Faizan_Akhtar/employeeManagement/admin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Admin Dashboard</title>
<link rel="stylesheet" href="./assets/styles/main.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="./assets/scripts/admin.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse" id="navbar">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Admin Dashboard</a>
</div>
<div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li><a href="#">Employee</a></li>
<li><a href="#">Pending Employee</a></li>
<li class="active"><a href="#">Manager</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><span onclick="logoutFunc()" class="glyphicon glyphicon-user"></span> Logout</a></li>
</ul>
</div>
</div>

</nav>
<button type="button" onclick="tryFunction()">Show Details</button>
<div id="dashboardBody">
<div id="dashboardDiv">
<table class="table table-hover" id="tableID">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">EmpID</th>
<th scope="col">Username</th>
<th scope="col">FirstName</th>
<th scope="col">LastName</th>
<th scope="col">Designation</th>
<th scope="col">Project</th>
<th scope="col">Manager</th>
<th scope="col">Salary</th>
<th scope="col">EDIT</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>104</td>
<td>faizan.akhtar</td>
<td>Faizan</td>
<td>Akhtar</td>
<td>Intern</td>
<td>Bootcamp</td>
<td>Vishal</td>
<td>20000</td>
<td>
<button type="button" class="btn btn-danger"><i class="fas fa-edit"></i></button>
</td>
</tr>
<tr>
<th scope="row">2</th>
<td>104</td>
<td>faizan.akhtar</td>
<td>Faizan</td>
<td>Akhtar</td>
<td>Intern</td>
<td>Bootcamp</td>
<td>Vishal</td>
<td>20000</td>
<td>
<button type="button" class="btn btn-danger"><i class="fas fa-edit"></i></button>
</td>
</tr>
</tbody>
</table>

</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</body>
</html>
40 changes: 40 additions & 0 deletions Faizan_Akhtar/employeeManagement/api/AdminController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EmployeeManagement.Custom_Models;
using EmployeeManagement.DbModels;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace EmployeeManagement.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class AdminController : ControllerBase
{

EmployeeDBContext _employeeDBContext;
public AdminController(EmployeeDBContext employeeDBContext)
{
_employeeDBContext = employeeDBContext;
}

[HttpGet]
public ActionResult GetEmployee()
{
// List<TStudent> studentName = _cSharpAdvContext.TStudent.ToList();
List<TEmployee> employee = _employeeDBContext.TEmployee.ToList();
return Ok(employee);
}

[HttpDelete]
public IActionResult DeleteStudent(CustomEmployee customEmployee)
{
TEmployee employee = _employeeDBContext.TEmployee.FirstOrDefault();
_employeeDBContext.TEmployee.Remove(employee);
_employeeDBContext.SaveChanges();
return Ok("Deleted");
}
}
}
21 changes: 21 additions & 0 deletions Faizan_Akhtar/employeeManagement/api/CustomEmployee.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace EmployeeManagement.Custom_Models
{
public class CustomEmployee
{

public int EmpId { get; set; }
public string FName { get; set; }
public string Lname { get; set; }
public string Email { get; set; }
public string Passwrd { get; set; }
public string Designation { get; set; }
public string Project { get; set; }
public string Manager { get; set; }
public int? Salary { get; set; }
}
}
71 changes: 71 additions & 0 deletions Faizan_Akhtar/employeeManagement/api/EmployeeDBContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace EmployeeManagement.DbModels
{
public partial class EmployeeDBContext : DbContext
{

public EmployeeDBContext(DbContextOptions<EmployeeDBContext> options)
: base(options)
{
}

public virtual DbSet<TEmployee> TEmployee { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{

}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TEmployee>(entity =>
{
entity.HasKey(e => e.EmpId);

entity.ToTable("tEmployee");

entity.Property(e => e.EmpId).HasColumnName("EmpID");

entity.Property(e => e.Designation)
.HasColumnName("designation")
.HasMaxLength(200)
.IsUnicode(false);

entity.Property(e => e.Email)
.HasColumnName("email")
.HasMaxLength(200)
.IsUnicode(false);

entity.Property(e => e.FName)
.HasColumnName("fName")
.HasMaxLength(200)
.IsUnicode(false);

entity.Property(e => e.Lname)
.HasColumnName("LName")
.HasMaxLength(200)
.IsUnicode(false);

entity.Property(e => e.Manager)
.HasColumnName("manager")
.HasMaxLength(200)
.IsUnicode(false);

entity.Property(e => e.Passwrd)
.HasColumnName("passwrd")
.HasMaxLength(200)
.IsUnicode(false);

entity.Property(e => e.Project)
.HasColumnName("project")
.HasMaxLength(200)
.IsUnicode(false);

entity.Property(e => e.Salary).HasColumnName("salary");
});
}
}
}
81 changes: 81 additions & 0 deletions Faizan_Akhtar/employeeManagement/api/LoginController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Text;
using EmployeeManagement.Custom_Models;
using EmployeeManagement.DbModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using System.Security.Claims;

namespace EmployeeManagement.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class LoginController : ControllerBase
{
private IConfiguration _config;
private EmployeeDBContext _employeeDBContext;

public LoginController(IConfiguration config, EmployeeDBContext employeeDBcontext)
{
_config = config;
_employeeDBContext = employeeDBcontext;
}
[AllowAnonymous]
[HttpPost]
public IActionResult Login([FromBody]CustomEmployee customEmployee)
{
IActionResult response = Unauthorized();
var user = AuthenticateUser(customEmployee);

if (user != null)
{
var tokenString = GenerateJSONWebToken(user);
response = Ok(new { token = tokenString });
}

return response;
}

private string GenerateJSONWebToken(CustomEmployee customEmployee)
{
var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"]));
var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);


var claims = new[]
{

new Claim("FName", customEmployee.FName ),
new Claim("Lname", customEmployee.Lname),
new Claim("Email", customEmployee.Email)
};

var token = new JwtSecurityToken(_config["Jwt:Issuer"],
_config["Jwt:Issuer"],
claims,
expires: DateTime.Now.AddMinutes(2400),
signingCredentials: credentials);

return new JwtSecurityTokenHandler().WriteToken(token);
}

private CustomEmployee AuthenticateUser(CustomEmployee customEmployee)
{
CustomEmployee user = null;

//Validate the User Credentials
//Demo Purpose, I have Passed HardCoded User Information
TEmployee employee = _employeeDBContext.TEmployee.Where(x => x.Email == customEmployee.Email && x.Passwrd == customEmployee.Passwrd).FirstOrDefault();

if (employee != null)
{
user = new CustomEmployee { FName = employee.FName, Lname = employee.Lname, Email = employee.Email};
}
return user;
}
}
}
44 changes: 44 additions & 0 deletions Faizan_Akhtar/employeeManagement/api/SignupController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EmployeeManagement.Custom_Models;
using EmployeeManagement.DbModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;

namespace EmployeeManagement.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class SignupController : ControllerBase
{
EmployeeDBContext _employeeDBContext;
public SignupController(EmployeeDBContext employeeDBContext)
{
_employeeDBContext = employeeDBContext;
}

[HttpPost]
public IActionResult CreateEmployee([FromBody]CustomEmployee customEmployee)
{
TEmployee employee = new TEmployee()
{
FName =customEmployee.FName,
Lname = customEmployee.Lname,
Email = customEmployee.Email,
Passwrd = customEmployee.Passwrd

};
_employeeDBContext.TEmployee.Add(employee);
_employeeDBContext.SaveChanges();
return Ok("Employee Added");
}
}
}

18 changes: 18 additions & 0 deletions Faizan_Akhtar/employeeManagement/api/TEmployee.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;

namespace EmployeeManagement.DbModels
{
public partial class TEmployee
{
public int EmpId { get; set; }
public string FName { get; set; }
public string Lname { get; set; }
public string Email { get; set; }
public string Passwrd { get; set; }
public string Designation { get; set; }
public string Project { get; set; }
public string Manager { get; set; }
public int? Salary { get; set; }
}
}
Loading