From 2a6ab929d91ea50a872ebf6d7b8e2eac9e606994 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Mar 2025 13:08:50 +0530 Subject: [PATCH 01/18] Added the condition to check if received token for reset password is encoded or not --- .../Controllers/AuthController.cs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Marco.Pms.Services/Controllers/AuthController.cs b/Marco.Pms.Services/Controllers/AuthController.cs index 2259142..6b8a2bb 100644 --- a/Marco.Pms.Services/Controllers/AuthController.cs +++ b/Marco.Pms.Services/Controllers/AuthController.cs @@ -162,12 +162,28 @@ namespace MarcoBMS.Services.Controllers UserManager.ResetPasswordTokenPurpose, WebUtility.UrlDecode( model.Token) ); - + string token = ""; if (!isTokenValid) - return BadRequest("Invalid or expired token."); + { + var isDecodedTokenValid = await _userManager.VerifyUserTokenAsync( + user, + TokenOptions.DefaultProvider, // This is the token provider + UserManager.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); From 354680d28b5be56a72f15c6fa8e4e9f529c707d0 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Mar 2025 13:45:06 +0530 Subject: [PATCH 02/18] Solved time discrepancies in attendance/record --- .../Controllers/AttendanceController.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Marco.Pms.Services/Controllers/AttendanceController.cs b/Marco.Pms.Services/Controllers/AttendanceController.cs index 37b3471..3103b9b 100644 --- a/Marco.Pms.Services/Controllers/AttendanceController.cs +++ b/Marco.Pms.Services/Controllers/AttendanceController.cs @@ -219,6 +219,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 +238,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 +279,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,7 +297,7 @@ 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, @@ -303,7 +305,7 @@ namespace MarcoBMS.Services.Controllers TenantId = TenantId, UpdatedBy = GetUserId(), - UpdatedOn = DateTime.UtcNow + UpdatedOn = recordAttendanceDot.Date }; //if (recordAttendanceDot.Image != null && recordAttendanceDot.Image.Count > 0) //{ From 8b4f892edfc5eaab3461ac876baaeebe08dc0e0b Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Mar 2025 13:45:06 +0530 Subject: [PATCH 03/18] Solved time discrepancies in attendance/record --- .../Controllers/AttendanceController.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Marco.Pms.Services/Controllers/AttendanceController.cs b/Marco.Pms.Services/Controllers/AttendanceController.cs index 37b3471..3103b9b 100644 --- a/Marco.Pms.Services/Controllers/AttendanceController.cs +++ b/Marco.Pms.Services/Controllers/AttendanceController.cs @@ -219,6 +219,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 +238,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 +279,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,7 +297,7 @@ 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, @@ -303,7 +305,7 @@ namespace MarcoBMS.Services.Controllers TenantId = TenantId, UpdatedBy = GetUserId(), - UpdatedOn = DateTime.UtcNow + UpdatedOn = recordAttendanceDot.Date }; //if (recordAttendanceDot.Image != null && recordAttendanceDot.Image.Count > 0) //{ From 93a25690f1922e6e3260020bce34acb837d94499 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 31 Mar 2025 11:23:30 +0530 Subject: [PATCH 04/18] Fixed project duplicate bug appered due to absence of projectId --- Marco.Pms.Model/Mapper/ProjectMapper.cs | 3 ++- Marco.Pms.Services/Controllers/ProjectController.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Marco.Pms.Model/Mapper/ProjectMapper.cs b/Marco.Pms.Model/Mapper/ProjectMapper.cs index 6801a11..6dc0986 100644 --- a/Marco.Pms.Model/Mapper/ProjectMapper.cs +++ b/Marco.Pms.Model/Mapper/ProjectMapper.cs @@ -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, diff --git a/Marco.Pms.Services/Controllers/ProjectController.cs b/Marco.Pms.Services/Controllers/ProjectController.cs index 4ca7a23..ef98a1b 100644 --- a/Marco.Pms.Services/Controllers/ProjectController.cs +++ b/Marco.Pms.Services/Controllers/ProjectController.cs @@ -197,7 +197,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(); From 35da59304d0a0413ed41faafcbcc81900329e6d8 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Mar 2025 13:08:50 +0530 Subject: [PATCH 05/18] Added the condition to check if received token for reset password is encoded or not --- .../Controllers/AuthController.cs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Marco.Pms.Services/Controllers/AuthController.cs b/Marco.Pms.Services/Controllers/AuthController.cs index 2259142..6b8a2bb 100644 --- a/Marco.Pms.Services/Controllers/AuthController.cs +++ b/Marco.Pms.Services/Controllers/AuthController.cs @@ -162,12 +162,28 @@ namespace MarcoBMS.Services.Controllers UserManager.ResetPasswordTokenPurpose, WebUtility.UrlDecode( model.Token) ); - + string token = ""; if (!isTokenValid) - return BadRequest("Invalid or expired token."); + { + var isDecodedTokenValid = await _userManager.VerifyUserTokenAsync( + user, + TokenOptions.DefaultProvider, // This is the token provider + UserManager.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); From 58526d5feb9ead812e02f71626c91950bb642d78 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Mar 2025 13:45:06 +0530 Subject: [PATCH 06/18] Solved time discrepancies in attendance/record --- .../Controllers/AttendanceController.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Marco.Pms.Services/Controllers/AttendanceController.cs b/Marco.Pms.Services/Controllers/AttendanceController.cs index 37b3471..3103b9b 100644 --- a/Marco.Pms.Services/Controllers/AttendanceController.cs +++ b/Marco.Pms.Services/Controllers/AttendanceController.cs @@ -219,6 +219,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 +238,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 +279,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,7 +297,7 @@ 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, @@ -303,7 +305,7 @@ namespace MarcoBMS.Services.Controllers TenantId = TenantId, UpdatedBy = GetUserId(), - UpdatedOn = DateTime.UtcNow + UpdatedOn = recordAttendanceDot.Date }; //if (recordAttendanceDot.Image != null && recordAttendanceDot.Image.Count > 0) //{ From bea2bcffb7aba7838214601504fb9f4ec15e3e91 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Mar 2025 13:08:50 +0530 Subject: [PATCH 07/18] Added the condition to check if received token for reset password is encoded or not --- .../Controllers/AuthController.cs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Marco.Pms.Services/Controllers/AuthController.cs b/Marco.Pms.Services/Controllers/AuthController.cs index 2259142..6b8a2bb 100644 --- a/Marco.Pms.Services/Controllers/AuthController.cs +++ b/Marco.Pms.Services/Controllers/AuthController.cs @@ -162,12 +162,28 @@ namespace MarcoBMS.Services.Controllers UserManager.ResetPasswordTokenPurpose, WebUtility.UrlDecode( model.Token) ); - + string token = ""; if (!isTokenValid) - return BadRequest("Invalid or expired token."); + { + var isDecodedTokenValid = await _userManager.VerifyUserTokenAsync( + user, + TokenOptions.DefaultProvider, // This is the token provider + UserManager.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); From 7fcb022ab3c55a7144026fe94318777533fc14a5 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Mar 2025 13:45:06 +0530 Subject: [PATCH 08/18] Solved time discrepancies in attendance/record --- .../Controllers/AttendanceController.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Marco.Pms.Services/Controllers/AttendanceController.cs b/Marco.Pms.Services/Controllers/AttendanceController.cs index 37b3471..3103b9b 100644 --- a/Marco.Pms.Services/Controllers/AttendanceController.cs +++ b/Marco.Pms.Services/Controllers/AttendanceController.cs @@ -219,6 +219,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 +238,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 +279,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,7 +297,7 @@ 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, @@ -303,7 +305,7 @@ namespace MarcoBMS.Services.Controllers TenantId = TenantId, UpdatedBy = GetUserId(), - UpdatedOn = DateTime.UtcNow + UpdatedOn = recordAttendanceDot.Date }; //if (recordAttendanceDot.Image != null && recordAttendanceDot.Image.Count > 0) //{ From dd75f9a115bbe73979b0b3ded05fdaedb9b03b0c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 31 Mar 2025 11:23:30 +0530 Subject: [PATCH 09/18] Fixed project duplicate bug appered due to absence of projectId --- Marco.Pms.Model/Mapper/ProjectMapper.cs | 3 ++- Marco.Pms.Services/Controllers/ProjectController.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Marco.Pms.Model/Mapper/ProjectMapper.cs b/Marco.Pms.Model/Mapper/ProjectMapper.cs index 6801a11..6dc0986 100644 --- a/Marco.Pms.Model/Mapper/ProjectMapper.cs +++ b/Marco.Pms.Model/Mapper/ProjectMapper.cs @@ -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, diff --git a/Marco.Pms.Services/Controllers/ProjectController.cs b/Marco.Pms.Services/Controllers/ProjectController.cs index 4ca7a23..ef98a1b 100644 --- a/Marco.Pms.Services/Controllers/ProjectController.cs +++ b/Marco.Pms.Services/Controllers/ProjectController.cs @@ -197,7 +197,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(); From ac6f52ce1627db37b461318c4fb218f52ae08e87 Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Wed, 2 Apr 2025 13:22:32 +0530 Subject: [PATCH 10/18] Fixed bug regrading passing incorrect tenantId and sending list of active and inactive employees rather than list of active or inc=active employees --- .../Controllers/AttendanceController.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Marco.Pms.Services/Controllers/AttendanceController.cs b/Marco.Pms.Services/Controllers/AttendanceController.cs index 3103b9b..2fb7ab0 100644 --- a/Marco.Pms.Services/Controllers/AttendanceController.cs +++ b/Marco.Pms.Services/Controllers/AttendanceController.cs @@ -40,15 +40,15 @@ namespace MarcoBMS.Services.Controllers } private int GetUserId() { - var tenant = User.FindFirst("Id")?.Value; - return (tenant != null ? Convert.ToInt32(tenant) : 1); + var user = _userHelper.GetCurrentUserAsync(); + return user.Id; } [HttpGet("log/attendance/{attendanceid}")] public async Task GetAttendanceLogById(int attendanceid) { - int TenantId = GetUserId(); + int TenantId = GetTenantId(); List lstAttendance = await _context.AttendanceLogs.Where(c => c.AttendanceId == attendanceid && c.TenantId == TenantId).ToListAsync(); @@ -59,7 +59,7 @@ namespace MarcoBMS.Services.Controllers public async Task 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 +84,7 @@ namespace MarcoBMS.Services.Controllers public async Task 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 +149,9 @@ namespace MarcoBMS.Services.Controllers /// [HttpGet("project/team")] - public async Task EmployeeAttendanceByProject([FromQuery] int projectId, [FromQuery] string? date = null) + public async Task 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 +172,7 @@ namespace MarcoBMS.Services.Controllers List lstAttendance = await _context.Attendes.Where(c => c.ProjectID == projectId && c.AttendanceDate.Date == forDate && c.TenantId == TenantId).ToListAsync(); - List projectteam = await _projectsHelper.GetTeamByProject(TenantId, projectId, true); + List projectteam = await _projectsHelper.GetTeamByProject(TenantId, projectId, IncludeInActive); foreach (ProjectAllocation teamMember in projectteam) { From 414bf7ece1b9aecb19ec3e0adcd7da38d0ba5ee7 Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Wed, 2 Apr 2025 13:37:03 +0530 Subject: [PATCH 11/18] Fixed bug about UpdatedBy --- Marco.Pms.Services/Controllers/AttendanceController.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Marco.Pms.Services/Controllers/AttendanceController.cs b/Marco.Pms.Services/Controllers/AttendanceController.cs index 2fb7ab0..df91456 100644 --- a/Marco.Pms.Services/Controllers/AttendanceController.cs +++ b/Marco.Pms.Services/Controllers/AttendanceController.cs @@ -38,11 +38,6 @@ namespace MarcoBMS.Services.Controllers //var tenant = User.FindFirst("TenantId")?.Value; //return (tenant != null ? Convert.ToInt32(tenant) : 1); } - private int GetUserId() - { - var user = _userHelper.GetCurrentUserAsync(); - return user.Id; - } [HttpGet("log/attendance/{attendanceid}")] @@ -304,7 +299,7 @@ namespace MarcoBMS.Services.Controllers Longitude = recordAttendanceDot.Longitude, TenantId = TenantId, - UpdatedBy = GetUserId(), + UpdatedBy = recordAttendanceDot.EmployeeID, UpdatedOn = recordAttendanceDot.Date }; //if (recordAttendanceDot.Image != null && recordAttendanceDot.Image.Count > 0) From 0674f84a2c017ab8bf974d3c852526f517f755fc Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Wed, 2 Apr 2025 15:31:41 +0530 Subject: [PATCH 12/18] Added new validation in user login to verify if user is active or not and if user's email is confirmed or not --- .../Controllers/AuthController.cs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Marco.Pms.Services/Controllers/AuthController.cs b/Marco.Pms.Services/Controllers/AuthController.cs index 6b8a2bb..58a4a6c 100644 --- a/Marco.Pms.Services/Controllers/AuthController.cs +++ b/Marco.Pms.Services/Controllers/AuthController.cs @@ -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 _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 userManager, JwtSettings jwtSettings, RefreshTokenService refreshTokenService, + public AuthController(UserManager 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 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(); From 4936a99e57f353377a1728c0614fc9ed6118bdbe Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Mar 2025 13:08:50 +0530 Subject: [PATCH 13/18] Added the condition to check if received token for reset password is encoded or not --- .../Controllers/AuthController.cs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Marco.Pms.Services/Controllers/AuthController.cs b/Marco.Pms.Services/Controllers/AuthController.cs index 2259142..6b8a2bb 100644 --- a/Marco.Pms.Services/Controllers/AuthController.cs +++ b/Marco.Pms.Services/Controllers/AuthController.cs @@ -162,12 +162,28 @@ namespace MarcoBMS.Services.Controllers UserManager.ResetPasswordTokenPurpose, WebUtility.UrlDecode( model.Token) ); - + string token = ""; if (!isTokenValid) - return BadRequest("Invalid or expired token."); + { + var isDecodedTokenValid = await _userManager.VerifyUserTokenAsync( + user, + TokenOptions.DefaultProvider, // This is the token provider + UserManager.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); From a502be497794d3d759c2fd070e68d5e486fead1d Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Mar 2025 13:45:06 +0530 Subject: [PATCH 14/18] Solved time discrepancies in attendance/record --- .../Controllers/AttendanceController.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Marco.Pms.Services/Controllers/AttendanceController.cs b/Marco.Pms.Services/Controllers/AttendanceController.cs index 37b3471..3103b9b 100644 --- a/Marco.Pms.Services/Controllers/AttendanceController.cs +++ b/Marco.Pms.Services/Controllers/AttendanceController.cs @@ -219,6 +219,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 +238,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 +279,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,7 +297,7 @@ 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, @@ -303,7 +305,7 @@ namespace MarcoBMS.Services.Controllers TenantId = TenantId, UpdatedBy = GetUserId(), - UpdatedOn = DateTime.UtcNow + UpdatedOn = recordAttendanceDot.Date }; //if (recordAttendanceDot.Image != null && recordAttendanceDot.Image.Count > 0) //{ From 805624700841d3191b5cce90b3326400a93768f2 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 31 Mar 2025 11:23:30 +0530 Subject: [PATCH 15/18] Fixed project duplicate bug appered due to absence of projectId --- Marco.Pms.Model/Mapper/ProjectMapper.cs | 3 ++- Marco.Pms.Services/Controllers/ProjectController.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Marco.Pms.Model/Mapper/ProjectMapper.cs b/Marco.Pms.Model/Mapper/ProjectMapper.cs index 6801a11..6dc0986 100644 --- a/Marco.Pms.Model/Mapper/ProjectMapper.cs +++ b/Marco.Pms.Model/Mapper/ProjectMapper.cs @@ -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, diff --git a/Marco.Pms.Services/Controllers/ProjectController.cs b/Marco.Pms.Services/Controllers/ProjectController.cs index 4ca7a23..ef98a1b 100644 --- a/Marco.Pms.Services/Controllers/ProjectController.cs +++ b/Marco.Pms.Services/Controllers/ProjectController.cs @@ -197,7 +197,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(); From 97adf8b99546b5dd206686d2d7d749db784b04bc Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Wed, 2 Apr 2025 13:22:32 +0530 Subject: [PATCH 16/18] Fixed bug regrading passing incorrect tenantId and sending list of active and inactive employees rather than list of active or inc=active employees --- .../Controllers/AttendanceController.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Marco.Pms.Services/Controllers/AttendanceController.cs b/Marco.Pms.Services/Controllers/AttendanceController.cs index 3103b9b..2fb7ab0 100644 --- a/Marco.Pms.Services/Controllers/AttendanceController.cs +++ b/Marco.Pms.Services/Controllers/AttendanceController.cs @@ -40,15 +40,15 @@ namespace MarcoBMS.Services.Controllers } private int GetUserId() { - var tenant = User.FindFirst("Id")?.Value; - return (tenant != null ? Convert.ToInt32(tenant) : 1); + var user = _userHelper.GetCurrentUserAsync(); + return user.Id; } [HttpGet("log/attendance/{attendanceid}")] public async Task GetAttendanceLogById(int attendanceid) { - int TenantId = GetUserId(); + int TenantId = GetTenantId(); List lstAttendance = await _context.AttendanceLogs.Where(c => c.AttendanceId == attendanceid && c.TenantId == TenantId).ToListAsync(); @@ -59,7 +59,7 @@ namespace MarcoBMS.Services.Controllers public async Task 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 +84,7 @@ namespace MarcoBMS.Services.Controllers public async Task 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 +149,9 @@ namespace MarcoBMS.Services.Controllers /// [HttpGet("project/team")] - public async Task EmployeeAttendanceByProject([FromQuery] int projectId, [FromQuery] string? date = null) + public async Task 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 +172,7 @@ namespace MarcoBMS.Services.Controllers List lstAttendance = await _context.Attendes.Where(c => c.ProjectID == projectId && c.AttendanceDate.Date == forDate && c.TenantId == TenantId).ToListAsync(); - List projectteam = await _projectsHelper.GetTeamByProject(TenantId, projectId, true); + List projectteam = await _projectsHelper.GetTeamByProject(TenantId, projectId, IncludeInActive); foreach (ProjectAllocation teamMember in projectteam) { From 368e186e36f60a2ab982c07749cfdd9abfafc810 Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Wed, 2 Apr 2025 13:37:03 +0530 Subject: [PATCH 17/18] Fixed bug about UpdatedBy --- Marco.Pms.Services/Controllers/AttendanceController.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Marco.Pms.Services/Controllers/AttendanceController.cs b/Marco.Pms.Services/Controllers/AttendanceController.cs index 2fb7ab0..df91456 100644 --- a/Marco.Pms.Services/Controllers/AttendanceController.cs +++ b/Marco.Pms.Services/Controllers/AttendanceController.cs @@ -38,11 +38,6 @@ namespace MarcoBMS.Services.Controllers //var tenant = User.FindFirst("TenantId")?.Value; //return (tenant != null ? Convert.ToInt32(tenant) : 1); } - private int GetUserId() - { - var user = _userHelper.GetCurrentUserAsync(); - return user.Id; - } [HttpGet("log/attendance/{attendanceid}")] @@ -304,7 +299,7 @@ namespace MarcoBMS.Services.Controllers Longitude = recordAttendanceDot.Longitude, TenantId = TenantId, - UpdatedBy = GetUserId(), + UpdatedBy = recordAttendanceDot.EmployeeID, UpdatedOn = recordAttendanceDot.Date }; //if (recordAttendanceDot.Image != null && recordAttendanceDot.Image.Count > 0) From 5e9dd55a07f3a78ae93ebd5d1a69781002474b4b Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Wed, 2 Apr 2025 15:31:41 +0530 Subject: [PATCH 18/18] Added new validation in user login to verify if user is active or not and if user's email is confirmed or not --- .../Controllers/AuthController.cs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Marco.Pms.Services/Controllers/AuthController.cs b/Marco.Pms.Services/Controllers/AuthController.cs index 6b8a2bb..58a4a6c 100644 --- a/Marco.Pms.Services/Controllers/AuthController.cs +++ b/Marco.Pms.Services/Controllers/AuthController.cs @@ -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 _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 userManager, JwtSettings jwtSettings, RefreshTokenService refreshTokenService, + public AuthController(UserManager 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 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();