Compare commits

..

No commits in common. "04d6c03b05c1206ab243a6909d42985e137be7f0" and "6ae2912a529966cd4624b55d191125f042d62b23" have entirely different histories.

6 changed files with 36 additions and 59 deletions

View File

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

View File

@ -38,12 +38,17 @@ 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 = GetTenantId();
int TenantId = GetUserId();
List<AttendanceLog> lstAttendance = await _context.AttendanceLogs.Where(c => c.AttendanceId == attendanceid && c.TenantId == TenantId).ToListAsync();
@ -54,7 +59,7 @@ namespace MarcoBMS.Services.Controllers
public async Task<IActionResult> GetAttendanceLogByEmployeeId(int employeeid, [FromQuery] string? date = null)
{
int TenantId = GetTenantId();
int TenantId = GetUserId();
DateOnly forDate = new DateOnly();
if (date != null && DateOnly.TryParse(date, out forDate) == false)
@ -79,7 +84,7 @@ namespace MarcoBMS.Services.Controllers
public async Task<IActionResult> EmployeeAttendanceByDateRange([FromQuery] int projectId, [FromQuery] string? dateFrom = null, [FromQuery] string? dateTo = null)
{
int TenantId = GetTenantId();
int TenantId = GetUserId();
DateTime fromDate = new DateTime();
DateTime toDate = new DateTime();
@ -144,9 +149,9 @@ namespace MarcoBMS.Services.Controllers
/// <returns></returns>
[HttpGet("project/team")]
public async Task<IActionResult> EmployeeAttendanceByProject([FromQuery] int projectId, [FromQuery] bool IncludeInActive, [FromQuery] string? date = null)
public async Task<IActionResult> EmployeeAttendanceByProject([FromQuery] int projectId, [FromQuery] string? date = null)
{
int TenantId = GetTenantId();
int TenantId = GetUserId();
DateTime forDate = new DateTime();
if (date != null && DateTime.TryParse(date, out forDate) == false)
@ -167,7 +172,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, IncludeInActive);
List<ProjectAllocation> projectteam = await _projectsHelper.GetTeamByProject(TenantId, projectId, true);
foreach (ProjectAllocation teamMember in projectteam)
{
@ -214,8 +219,6 @@ 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)
{
@ -233,13 +236,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;
@ -274,7 +277,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;
@ -292,15 +295,15 @@ namespace MarcoBMS.Services.Controllers
AttendanceId = attendance.Id, // Use existing or new AttendanceId
Activity = attendance.Activity,
ActivityTime = finalDateTime,
ActivityTime = recordAttendanceDot.Date,
Comment = recordAttendanceDot.Comment,
EmployeeID = recordAttendanceDot.EmployeeID,
Latitude = recordAttendanceDot.Latitude,
Longitude = recordAttendanceDot.Longitude,
TenantId = TenantId,
UpdatedBy = recordAttendanceDot.EmployeeID,
UpdatedOn = recordAttendanceDot.Date
UpdatedBy = GetUserId(),
UpdatedOn = DateTime.UtcNow
};
//if (recordAttendanceDot.Image != null && recordAttendanceDot.Image.Count > 0)
//{

View File

@ -1,5 +1,4 @@
using Marco.Pms.DataAccess.Data;
using Marco.Pms.Model.Authentication;
using Marco.Pms.Model.Authentication;
using Marco.Pms.Model.Dtos;
using Marco.Pms.Model.Dtos.Util;
using Marco.Pms.Model.Employees;
@ -22,14 +21,13 @@ 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,ApplicationDbContext context, JwtSettings jwtSettings, RefreshTokenService refreshTokenService,
public AuthController(UserManager<IdentityUser> userManager, JwtSettings jwtSettings, RefreshTokenService refreshTokenService,
IEmailSender emailSender, IConfiguration configuration, EmployeeHelper employeeHelper)
{
_userManager = userManager;
@ -38,27 +36,21 @@ 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 _context.ApplicationUsers.FirstOrDefaultAsync(u => u.Email == loginDto.Username || u.PhoneNumber == loginDto.Username);
var user = await _userManager.FindByEmailAsync(loginDto.Username);
var user1 = await _userManager.Users.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();
@ -170,28 +162,12 @@ 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.");
return BadRequest("Invalid or expired token.");
token = model.Token;
}
else
{
token = WebUtility.UrlDecode(model.Token);
}
var result = await _userManager.ResetPasswordAsync(user, token, model.NewPassword);
var result = await _userManager.ResetPasswordAsync(user, WebUtility.UrlDecode(model.Token), model.NewPassword);
if (!result.Succeeded)
return BadRequest(result.Errors);

View File

@ -182,24 +182,23 @@ namespace MarcoBMS.Services.Controllers
/* Identity user Exists - Create/update employee Employee */
// Update Employee record
var existingEmployee = await _context.Employees.FirstOrDefaultAsync(e => e.Email == model.Email && e.Id == model.Id);
var existingEmployee = await _context.Employees.FirstOrDefaultAsync(e => e.ApplicationUserId == existingUser.Id || 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);
return BadRequest("You cannot use this email");
Employee newEmployee = GetNewEmployeeModel(model, TenantId, existingUser.Id);
_context.Employees.Add(newEmployee);
}
await _context.SaveChangesAsync();
responsemessage = "User updated successfully.";
}
else
{
@ -226,7 +225,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

@ -197,7 +197,7 @@ namespace MarcoBMS.Services.Controllers
int TenantId = GetTenantId();
updateProjectDto.TenantId = TenantId;
Project project = updateProjectDto.ToProjectFromUpdateProjectDto(TenantId,id);
Project project = updateProjectDto.ToProjectFromUpdateProjectDto(TenantId);
_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=3306;User ID=root;Password=root;Database=MarcoBMS2",
//"DefaultConnectionString": "Server=147.93.98.152;User ID=devuser;Password=AppUser@123$;Database=MarcoBMS1"
//"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"
},
"AppSettings": {
"WebFrontendUrl": "http://localhost:5173",