Compare commits

...

42 Commits

Author SHA1 Message Date
9c4b1639fe Merge branch 'Feature_Task_management' of https://git.marcoaiot.com/admin/marco.pms.api into Feature_Task_management 2025-04-02 18:37:29 +05:30
1b16983092 #40 - Add models and database migration for Task Allocation 2025-04-02 18:37:15 +05:30
04d6c03b05 Merge pull request 'Ashutosh_Employee_Update_Validation' (#13) from Ashutosh_Employee_Update_Validation into Issuses
Reviewed-on: #13
2025-04-02 13:04:43 +00:00
e50eedc7e6 Added validation in Employee Create and update api to check Whether this email and Id belongs to same employee 2025-04-02 17:54:38 +05:30
Pramod Mahajan
5034da19cd added condition for unique role name. 2025-04-02 16:53:35 +05:30
Pramod Mahajan
3fce6ef499 Merge branch 'Issuses' of https://git.marcoaiot.com/admin/marco.pms.api into Issuses 2025-04-02 16:53:08 +05:30
eba230723b Fixed bug about UpdatedBy 2025-04-02 16:08:02 +05:30
69a4ad7286 Fixed bug regrading passing incorrect tenantId and sending list of active and inactive employees rather than list of active or inc=active employees 2025-04-02 16:08:02 +05:30
212fe250c1 Solved time discrepancies in attendance/record 2025-04-02 16:08:01 +05:30
a42a924884 Added new validation in user login to verify if user is active or not and if user's email is confirmed or not 2025-04-02 16:06:53 +05:30
bec60cd24e Fixed bug about UpdatedBy 2025-04-02 16:06:53 +05:30
c17b5df8d0 Fixed bug regrading passing incorrect tenantId and sending list of active and inactive employees rather than list of active or inc=active employees 2025-04-02 16:06:53 +05:30
a9124e1a93 Fixed project duplicate bug appered due to absence of projectId 2025-04-02 16:06:53 +05:30
f0ed430f37 Solved time discrepancies in attendance/record 2025-04-02 16:06:53 +05:30
c071b7ecaf Added the condition to check if received token for reset password is encoded or not 2025-04-02 16:06:53 +05:30
Pramod Mahajan
fce9832ea2 Merge branch 'Issuses' of https://git.marcoaiot.com/admin/marco.pms.api into Issuses 2025-04-02 16:04:24 +05:30
5e9dd55a07 Added new validation in user login to verify if user is active or not and if user's email is confirmed or not 2025-04-02 16:04:12 +05:30
368e186e36 Fixed bug about UpdatedBy 2025-04-02 16:04:11 +05:30
97adf8b995 Fixed bug regrading passing incorrect tenantId and sending list of active and inactive employees rather than list of active or inc=active employees 2025-04-02 16:04:11 +05:30
8056247008 Fixed project duplicate bug appered due to absence of projectId 2025-04-02 16:04:11 +05:30
a502be4977 Solved time discrepancies in attendance/record 2025-04-02 16:04:11 +05:30
4936a99e57 Added the condition to check if received token for reset password is encoded or not 2025-04-02 16:04:11 +05:30
587530856a Merge pull request 'Added new validation in user login to verify if user is active or not and if user's email is confirmed or not' (#11) from Ashutosh_User_Validations into Issuses
Reviewed-on: #11
2025-04-02 10:26:11 +00:00
0674f84a2c Added new validation in user login to verify if user is active or not and if user's email is confirmed or not 2025-04-02 10:26:11 +00:00
c4dcd589db Merge pull request 'Fixed bug regrading passing incorrect tenantId and sending list of active and inactive employees rather than list of active or inactive employees' (#10) from Ashutosh_Bug#37_Attendance_Issues into Issuses
Reviewed-on: #10
2025-04-02 10:25:06 +00:00
414bf7ece1 Fixed bug about UpdatedBy 2025-04-02 13:37:03 +05:30
ac6f52ce16 Fixed bug regrading passing incorrect tenantId and sending list of active and inactive employees rather than list of active or inc=active employees 2025-04-02 13:22:32 +05:30
7b0a1b0073 Merge branch 'Issuses' of https://git.marcoaiot.com/admin/marco.pms.api into Issuses 2025-03-31 17:23:50 +05:30
dd75f9a115 Fixed project duplicate bug appered due to absence of projectId 2025-03-31 17:23:25 +05:30
7fcb022ab3 Solved time discrepancies in attendance/record 2025-03-31 17:23:25 +05:30
bea2bcffb7 Added the condition to check if received token for reset password is encoded or not 2025-03-31 17:23:25 +05:30
063441f322 Merge branch 'Ashutosh_SCRUM-58_Time_Discrepancies_Attendance' into Issuses 2025-03-31 13:11:24 +05:30
5a4b46cb4f Merge branch 'Issuses' of https://git.marcoaiot.com/admin/marco.pms.api into Issuses 2025-03-31 13:01:44 +05:30
58526d5feb Solved time discrepancies in attendance/record 2025-03-31 13:01:36 +05:30
35da59304d Added the condition to check if received token for reset password is encoded or not 2025-03-31 13:01:35 +05:30
2c3463b74f Merge pull request 'Fixed project duplicate bug appered due to absence of projectId' (#9) from Ashutosh_Bug#18_Project_Duplicate into Issuses
Reviewed-on: #9
2025-03-31 07:30:49 +00:00
93a25690f1 Fixed project duplicate bug appered due to absence of projectId 2025-03-31 11:23:30 +05:30
b85bc3d62e Merge pull request 'Solved time discrepancies in attendance/record' (#3) from Ashutosh_SCRUM-58_Time_Discrepancies_Attendance into Issuses
Reviewed-on: #3
2025-03-28 09:35:03 +00:00
8b4f892edf Solved time discrepancies in attendance/record 2025-03-28 09:35:03 +00:00
597d86aa27 Merge pull request 'Added the condition to check if received token for reset password is encoded or not' (#2) from Ashutosh_SCRUM-62_Decodeing_Token_Reset_password into Issuses
Reviewed-on: #2
2025-03-28 09:34:33 +00:00
354680d28b Solved time discrepancies in attendance/record 2025-03-28 13:45:06 +05:30
2a6ab929d9 Added the condition to check if received token for reset password is encoded or not 2025-03-28 13:08:50 +05:30
6 changed files with 59 additions and 36 deletions

View File

@ -34,10 +34,11 @@ namespace Marco.Pms.Model.Mapper
};
}
public static Project ToProjectFromUpdateProjectDto(this UpdateProjectDto projectModel, int TenantId)
public static Project ToProjectFromUpdateProjectDto(this UpdateProjectDto projectModel, int TenantId,int id)
{
return new Project
{
Id = id,
ContactPerson = projectModel.ContactPerson,
ProjectAddress = projectModel.ProjectAddress,
Name = projectModel.Name,

View File

@ -38,17 +38,12 @@ namespace MarcoBMS.Services.Controllers
//var tenant = User.FindFirst("TenantId")?.Value;
//return (tenant != null ? Convert.ToInt32(tenant) : 1);
}
private int GetUserId()
{
var tenant = User.FindFirst("Id")?.Value;
return (tenant != null ? Convert.ToInt32(tenant) : 1);
}
[HttpGet("log/attendance/{attendanceid}")]
public async Task<IActionResult> GetAttendanceLogById(int attendanceid)
{
int TenantId = GetUserId();
int TenantId = GetTenantId();
List<AttendanceLog> lstAttendance = await _context.AttendanceLogs.Where(c => c.AttendanceId == attendanceid && c.TenantId == TenantId).ToListAsync();
@ -59,7 +54,7 @@ namespace MarcoBMS.Services.Controllers
public async Task<IActionResult> GetAttendanceLogByEmployeeId(int employeeid, [FromQuery] string? date = null)
{
int TenantId = GetUserId();
int TenantId = GetTenantId();
DateOnly forDate = new DateOnly();
if (date != null && DateOnly.TryParse(date, out forDate) == false)
@ -84,7 +79,7 @@ namespace MarcoBMS.Services.Controllers
public async Task<IActionResult> EmployeeAttendanceByDateRange([FromQuery] int projectId, [FromQuery] string? dateFrom = null, [FromQuery] string? dateTo = null)
{
int TenantId = GetUserId();
int TenantId = GetTenantId();
DateTime fromDate = new DateTime();
DateTime toDate = new DateTime();
@ -149,9 +144,9 @@ namespace MarcoBMS.Services.Controllers
/// <returns></returns>
[HttpGet("project/team")]
public async Task<IActionResult> EmployeeAttendanceByProject([FromQuery] int projectId, [FromQuery] string? date = null)
public async Task<IActionResult> EmployeeAttendanceByProject([FromQuery] int projectId, [FromQuery] bool IncludeInActive, [FromQuery] string? date = null)
{
int TenantId = GetUserId();
int TenantId = GetTenantId();
DateTime forDate = new DateTime();
if (date != null && DateTime.TryParse(date, out forDate) == false)
@ -172,7 +167,7 @@ namespace MarcoBMS.Services.Controllers
List<Attendance> lstAttendance = await _context.Attendes.Where(c => c.ProjectID == projectId && c.AttendanceDate.Date == forDate && c.TenantId == TenantId).ToListAsync();
List<ProjectAllocation> projectteam = await _projectsHelper.GetTeamByProject(TenantId, projectId, true);
List<ProjectAllocation> projectteam = await _projectsHelper.GetTeamByProject(TenantId, projectId, IncludeInActive);
foreach (ProjectAllocation teamMember in projectteam)
{
@ -219,6 +214,8 @@ namespace MarcoBMS.Services.Controllers
Attendance attendance = await _context.Attendes.FirstOrDefaultAsync(a => a.EmployeeID == recordAttendanceDot.EmployeeID &&
a.AttendanceDate.Date == recordAttendanceDot.Date.Date && a.TenantId == TenantId); ;
DateTime finalDateTime = GetDateFromTimeStamp(recordAttendanceDot, recordAttendanceDot.MarkTime);
if (attendance != null)
{
@ -236,13 +233,13 @@ namespace MarcoBMS.Services.Controllers
//string timeString = "10:30 PM"; // Format: "hh:mm tt"
DateTime finalDateTime = GetDateFromTimeStamp(recordAttendanceDot, recordAttendanceDot.MarkTime);
//DateTime finalDateTime = GetDateFromTimeStamp(recordAttendanceDot, recordAttendanceDot.MarkTime);
attendance.OutTime = finalDateTime;
}
else if (recordAttendanceDot.Action == ATTENDANCE_MARK_TYPE.REQUEST_REGULARIZE)
{
DateTime finalDateTime = GetDateFromTimeStamp(recordAttendanceDot, recordAttendanceDot.MarkTime);
//DateTime finalDateTime = GetDateFromTimeStamp(recordAttendanceDot, recordAttendanceDot.MarkTime);
attendance.OutTime = finalDateTime;
attendance.Activity = ATTENDANCE_MARK_TYPE.REQUEST_REGULARIZE;
@ -277,7 +274,7 @@ namespace MarcoBMS.Services.Controllers
attendance.Date = DateTime.UtcNow;
DateTime finalDateTime = GetDateFromTimeStamp(recordAttendanceDot, recordAttendanceDot.MarkTime);
//DateTime finalDateTime = GetDateFromTimeStamp(recordAttendanceDot, recordAttendanceDot.MarkTime);
attendance.InTime = finalDateTime;
attendance.OutTime = null;
@ -295,15 +292,15 @@ namespace MarcoBMS.Services.Controllers
AttendanceId = attendance.Id, // Use existing or new AttendanceId
Activity = attendance.Activity,
ActivityTime = recordAttendanceDot.Date,
ActivityTime = finalDateTime,
Comment = recordAttendanceDot.Comment,
EmployeeID = recordAttendanceDot.EmployeeID,
Latitude = recordAttendanceDot.Latitude,
Longitude = recordAttendanceDot.Longitude,
TenantId = TenantId,
UpdatedBy = GetUserId(),
UpdatedOn = DateTime.UtcNow
UpdatedBy = recordAttendanceDot.EmployeeID,
UpdatedOn = recordAttendanceDot.Date
};
//if (recordAttendanceDot.Image != null && recordAttendanceDot.Image.Count > 0)
//{

View File

@ -1,4 +1,5 @@
using Marco.Pms.Model.Authentication;
using Marco.Pms.DataAccess.Data;
using Marco.Pms.Model.Authentication;
using Marco.Pms.Model.Dtos;
using Marco.Pms.Model.Dtos.Util;
using Marco.Pms.Model.Employees;
@ -21,13 +22,14 @@ namespace MarcoBMS.Services.Controllers
public class AuthController : ControllerBase
{
private readonly UserManager<IdentityUser> _userManager;
private readonly ApplicationDbContext _context;
private readonly JwtSettings _jwtSettings;
private readonly RefreshTokenService _refreshTokenService;
private readonly IEmailSender _emailSender;
private readonly IConfiguration _configuration;
private readonly EmployeeHelper _employeeHelper;
//string tenentId = "1";
public AuthController(UserManager<IdentityUser> userManager, JwtSettings jwtSettings, RefreshTokenService refreshTokenService,
public AuthController(UserManager<IdentityUser> userManager,ApplicationDbContext context, JwtSettings jwtSettings, RefreshTokenService refreshTokenService,
IEmailSender emailSender, IConfiguration configuration, EmployeeHelper employeeHelper)
{
_userManager = userManager;
@ -36,21 +38,27 @@ namespace MarcoBMS.Services.Controllers
_emailSender = emailSender;
_configuration = configuration;
_employeeHelper = employeeHelper;
_context = context;
}
[HttpPost("login")]
public async Task<IActionResult> Login([FromBody] LoginDto loginDto)
{
var user = await _userManager.FindByEmailAsync(loginDto.Username);
var user1 = await _userManager.Users.FirstOrDefaultAsync(u => u.Email == loginDto.Username || u.PhoneNumber == loginDto.Username);
var user = await _context.ApplicationUsers.FirstOrDefaultAsync(u => u.Email == loginDto.Username || u.PhoneNumber == loginDto.Username);
if (user == null || !await _userManager.CheckPasswordAsync(user, loginDto.Password))
{
return Unauthorized("Invalid username or password.");
}
if (!user.IsActive)
{
return BadRequest("User is In Active");
}
if (!user.EmailConfirmed)
{
return BadRequest("Your email is not verified, Please verify your email");
}
Employee emp = await _employeeHelper.GetEmployeeByApplicationUserID(user.Id);
//var refreshToken = GenerateRefreshToken();
@ -162,12 +170,28 @@ namespace MarcoBMS.Services.Controllers
UserManager<ApplicationUser>.ResetPasswordTokenPurpose,
WebUtility.UrlDecode( model.Token)
);
string token = "";
if (!isTokenValid)
{
var isDecodedTokenValid = await _userManager.VerifyUserTokenAsync(
user,
TokenOptions.DefaultProvider, // This is the token provider
UserManager<ApplicationUser>.ResetPasswordTokenPurpose,
model.Token
);
if(!isDecodedTokenValid)
return BadRequest("Invalid or expired token.");
var result = await _userManager.ResetPasswordAsync(user, WebUtility.UrlDecode(model.Token), model.NewPassword);
token = model.Token;
}
else
{
token = WebUtility.UrlDecode(model.Token);
}
var result = await _userManager.ResetPasswordAsync(user, token, model.NewPassword);
if (!result.Succeeded)
return BadRequest(result.Errors);

View File

@ -182,23 +182,24 @@ namespace MarcoBMS.Services.Controllers
/* Identity user Exists - Create/update employee Employee */
// Update Employee record
var existingEmployee = await _context.Employees.FirstOrDefaultAsync(e => e.ApplicationUserId == existingUser.Id || e.Email == model.Email || e.Id == model.Id);
var existingEmployee = await _context.Employees.FirstOrDefaultAsync(e => e.Email == model.Email && e.Id == model.Id);
if (existingEmployee != null)
{
existingEmployee = GetUpdateEmployeeModel(model, existingEmployee, existingUser);
_context.Employees.Update(existingEmployee);
await _context.SaveChangesAsync();
responsemessage = "User updated successfully.";
}
else
{
// Create Employee record if missing
Employee newEmployee = GetNewEmployeeModel(model, TenantId, existingUser.Id);
_context.Employees.Add(newEmployee);
//Employee newEmployee = GetNewEmployeeModel(model, TenantId, existingUser.Id);
//_context.Employees.Add(newEmployee);
return BadRequest("You cannot use this email");
}
await _context.SaveChangesAsync();
responsemessage = "User updated successfully.";
}
else
{
@ -225,7 +226,7 @@ namespace MarcoBMS.Services.Controllers
var resetLink = $"{_configuration["AppSettings:WebFrontendUrl"]}/reset-password?token={WebUtility.UrlEncode(token)}";
await _emailSender.SendResetPasswordEmailOnRegister(user.Email, newEmployee.FirstName, resetLink);
responsemessage = "User created successfully. PAssword reset link is sent to registered email";
responsemessage = "User created successfully. Password reset link is sent to registered email";
}
}
else

View File

@ -196,7 +196,7 @@ namespace MarcoBMS.Services.Controllers
int TenantId = GetTenantId();
updateProjectDto.TenantId = TenantId;
Project project = updateProjectDto.ToProjectFromUpdateProjectDto(TenantId);
Project project = updateProjectDto.ToProjectFromUpdateProjectDto(TenantId,id);
_context.Projects.Update(project);
await _context.SaveChangesAsync();

View File

@ -64,8 +64,8 @@
"ConnectionStrings": {
// "DefaultConnectionString": "Server=103.50.160.45;User ID=marcowvh_admin;Password=Marcoemp@123;Database=marcowvh_empattendanceci",
//"DefaultConnectionString": "Server=localhost;port=3333;User ID=root;Password=root;Database=MarcoBMS1",
"DefaultConnectionString": "Server=147.93.98.152;User ID=devuser;Password=AppUser@123$;Database=MarcoBMS1"
"DefaultConnectionString": "Server=localhost;port=3306;User ID=root;Password=root;Database=MarcoBMS2",
//"DefaultConnectionString": "Server=147.93.98.152;User ID=devuser;Password=AppUser@123$;Database=MarcoBMS1"
},
"AppSettings": {
"WebFrontendUrl": "http://localhost:5173",