Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Kritika_Sachdeva/LoginModule/EmployeeProject.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.960
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeeProject", "EmployeeProject\EmployeeProject.csproj", "{6861454D-ED03-4CD8-BAB0-C974EF4F6F3E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6861454D-ED03-4CD8-BAB0-C974EF4F6F3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6861454D-ED03-4CD8-BAB0-C974EF4F6F3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6861454D-ED03-4CD8-BAB0-C974EF4F6F3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6861454D-ED03-4CD8-BAB0-C974EF4F6F3E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5D5889BC-B22B-49FC-A190-0A8FE96F198D}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

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

DbModels.projectContext _projectContext;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still we are using complete refrence instead of relative to create instance of classes.


private string EmpName;
private string EmpEmail;
private string EmpPassword;
private string EmpGender;
private long EmpPhone;
private decimal EmpExp;
private DateTime? EmpJoining;
private string EmpRole;
private string EmpPm;
private string EmpProject;

public AdminController(DbModels.projectContext projectContext)
{
_projectContext = projectContext;
}


[HttpGet("{mail}")]
public IActionResult EmpData(String mail)
{
DbModels.Temployee temployee = _projectContext.Temployee.Where(s => s.EmpEmail == mail).FirstOrDefault();
return Ok(temployee);
}



[HttpPost]
public IActionResult CreateEntry([FromBody] CustomModels.DetailsClass detailsClass)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer to the above comment and make necessary changes.

{
DbModels.Temployee temployee = new DbModels.Temployee();

temployee.EmpName = detailsClass.EmpName;
temployee.EmpEmail = detailsClass.EmpEmail;
temployee.EmpPassword = detailsClass.EmpPassword;
temployee.EmpGender = detailsClass.EmpGender;
temployee.EmpPhone = detailsClass.EmpPhone;
temployee.EmpExp = detailsClass.EmpExp;
temployee.EmpJoining = detailsClass.EmpJoining;
temployee.EmpRole = detailsClass.EmpRole;
temployee.EmpPm = detailsClass.EmpPm;
temployee.EmpProject = detailsClass.EmpProject;

_projectContext.Temployee.Add(temployee);
_projectContext.SaveChanges();

return Ok("Employee Added!");
}

[HttpDelete("{id}")]
public void DeleteEntry(int id)
{
DbModels.Temployee emp = _projectContext.Temployee.Where(s => s.EmpId == id).FirstOrDefault();
_projectContext.Temployee.Remove(emp);
_projectContext.SaveChanges();
}



[HttpPut("{id}")]
public IActionResult UpdateEntry(int id, [FromBody] CustomModels.DetailsClass detailsClass)
{
DbModels.Temployee temployee = _projectContext.Temployee.Where(s => s.EmpId == id).FirstOrDefault();
temployee.EmpName = detailsClass.EmpName;
temployee.EmpEmail = detailsClass.EmpEmail;
temployee.EmpPassword = detailsClass.EmpPassword;
temployee.EmpGender = detailsClass.EmpGender;
temployee.EmpPhone = detailsClass.EmpPhone;
temployee.EmpExp = detailsClass.EmpExp;
temployee.EmpJoining = detailsClass.EmpJoining;
temployee.EmpRole = detailsClass.EmpRole;
temployee.EmpPm = detailsClass.EmpPm;
temployee.EmpProject = detailsClass.EmpProject;

_projectContext.Temployee.Update(temployee);
_projectContext.SaveChanges();

return Ok("Employee data updated!");
}

[HttpPatch("{id}")]
public IActionResult PartialUpdateData(int id, [FromBody] CustomModels.DetailsClass detailsClass)
{
DbModels.Temployee temployee = _projectContext.Temployee.Where(s => s.EmpId == id).FirstOrDefault();
temployee.EmpRole = detailsClass.EmpRole;
temployee.EmpPm = detailsClass.EmpPm;
_projectContext.SaveChanges();

return Ok("Employee data updated by patch!");
}

[Route("UsersList")]
[HttpGet]
public IActionResult GetAll()
{
List<CustomModels.DetailsClass> emps = null;

emps = _projectContext.Temployee
.Select(x => new CustomModels.DetailsClass
{
EmpName = x.EmpName,
EmpEmail = x.EmpEmail,
EmpGender=x.EmpGender,
EmpPhone = x.EmpPhone,
EmpExp=x.EmpExp,
EmpJoining=x.EmpJoining,
EmpRole = x.EmpRole,
EmpPm = x.EmpPm,
EmpProject = x.EmpProject
}).ToList();


return Ok(emps);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace EmployeeProject.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class EmployeeController : ControllerBase
{
DbModels.projectContext _projectContext;

private string EmpName;
private string EmpEmail;
private string EmpPassword;
private string EmpGender;
private long EmpPhone;
private decimal EmpExp;
private DateTime? EmpJoining;
private string EmpRole;
private string EmpPm;
private string EmpProject;

public EmployeeController(DbModels.projectContext projectContext)
{
_projectContext = projectContext;
}

[HttpPost]
public IActionResult CreateEntry([FromBody] CustomModels.DetailsClass detailsClass)
{
DbModels.Temployee temployee = new DbModels.Temployee();

temployee.EmpName = detailsClass.EmpName;
temployee.EmpEmail = detailsClass.EmpEmail;
temployee.EmpPassword = detailsClass.EmpPassword;
temployee.EmpGender= detailsClass.EmpGender;
temployee.EmpPhone = detailsClass.EmpPhone;
temployee.EmpExp = detailsClass.EmpExp;
temployee.EmpJoining = detailsClass.EmpJoining;
temployee.EmpRole = detailsClass.EmpRole;
temployee.EmpPm = detailsClass.EmpPm;
temployee.EmpProject = detailsClass.EmpProject;

_projectContext.Temployee.Add(temployee);
_projectContext.SaveChanges();

return Ok("Employee Added!");
}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using DbModels

namespace EmployeeProject.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class LoginController : ControllerBase
{
private IConfiguration _config;
public DbModels.projectContext _projectContext;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

projectContext _projectContext;
also a Class name must not be CamelCase.


public LoginController(IConfiguration config, DbModels.projectContext context)
{
_config = config;
_projectContext = context;
}
[AllowAnonymous]
[HttpPost]
public IActionResult LoginToken([FromBody]CustomModels.Credentials login)
{
IActionResult response = Unauthorized();
var user = AuthenticateUser(login);

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

return response;
}

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

var claims = new[] {
new Claim(JwtRegisteredClaimNames.Sub, _config["Jwt:Issuer"]),
new Claim(JwtRegisteredClaimNames.Email, userInfo.EmpEmail),
new Claim("Urole", userInfo.EmpRole)
};

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

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

private DbModels.Temployee AuthenticateUser(CustomModels.Credentials details)
{
DbModels.Temployee user = _projectContext.Temployee.Where(x => x.EmpEmail == details.EmpEmail && x.EmpPassword == details.EmpPassword).FirstOrDefault();
//Validate the User Credentials
if (user != null)
{
user = new DbModels.Temployee { EmpName = user.EmpName, EmpEmail = user.EmpEmail, EmpPassword = user.EmpPassword, EmpRole = user.EmpRole };
}


return user;

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace EmployeeProject.CustomModels
{
public class Credentials
{
public string EmpEmail { get; set; }
public string EmpPassword { get; set; }

}
}
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 EmployeeProject.CustomModels
{
public class DetailsClass
{
public string EmpName { get; set; }
public string EmpEmail { get; set; }
public string EmpPassword { get; set; }
public string EmpGender { get; set; }
public long EmpPhone { get; set; }
public decimal EmpExp { get; set; }
public DateTime? EmpJoining { get; set; }
public string EmpRole { get; set; }
public string EmpPm { get; set; }
public string EmpProject { get; set; }
}
}
20 changes: 20 additions & 0 deletions Kritika_Sachdeva/LoginModule/EmployeeProject/DbModels/Temployee.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;

namespace EmployeeProject.DbModels
{
public partial class Temployee
{
public int EmpId { get; set; }
public string EmpName { get; set; }
public string EmpEmail { get; set; }
public string EmpPassword { get; set; }
public string EmpGender { get; set; }
public long EmpPhone { get; set; }
public decimal EmpExp { get; set; }
public DateTime? EmpJoining { get; set; }
public string EmpRole { get; set; }
public string EmpPm { get; set; }
public string EmpProject { get; set; }
}
}
Loading