Files
Core_Be/Services/AttendanceService.cs
T
Dhananjaya99 bffc9b1686 first commit
2026-09-28 11:44:26 +05:30

74 lines
3.0 KiB
C#

using Fitness_core_BE.Helpers;
using Fitness_core_BE.Interfaces;
using Fitness_core_BE.Interfaces.Services;
namespace Fitness_core_BE.Services
{
public class AttendanceService : IAttendanceService
{
private readonly IAttendanceRepository _attendanceRepo;
private readonly UserRoleHelper _userRoleHelper;
private readonly IAccessDeviceService _accessDeviceService;
public AttendanceService(
IAttendanceRepository attendanceRepo,
UserRoleHelper userRoleHelper,
IAccessDeviceService accessDeviceService)
{
_attendanceRepo = attendanceRepo;
_userRoleHelper = userRoleHelper;
_accessDeviceService = accessDeviceService;
}
public async Task<object> GetAllAttendanceRecords(object payload, HttpContext httpContext)
{
var data = DeserializePayload.Deserialize(payload);
Guid userId = DataExtractor.GetUserIdFromContext(httpContext);
Guid clientId = await _userRoleHelper.GetClientId(userId);
//await _accessDeviceService.GetAttendance(clientId);
return await _attendanceRepo.GetLatestPerPersonAsync(clientId);
}
public async Task<object> GetAttendanceCounts(object payload, HttpContext httpContext)
{
var data = DeserializePayload.Deserialize(payload);
Guid userId = DataExtractor.GetUserIdFromContext(httpContext);
Guid clientId = await _userRoleHelper.GetClientId(userId);
//await _accessDeviceService.GetAttendance(clientId);
var fromDate = DataExtractor.GetOptionalDateTime(data, "fromDate");
var toDate = DataExtractor.GetOptionalDateTime(data, "toDate");
var now = DateTime.UtcNow;
DateTime resolvedFrom;
DateTime resolvedTo;
if (fromDate == null && toDate == null)
{
resolvedFrom = new DateTime(now.Year, now.Month, 1);
resolvedTo = now.Date.AddDays(1).AddTicks(-1);
}
else if (fromDate != null && toDate == null)
{
resolvedFrom = fromDate.Value;
resolvedTo = now.Date.AddDays(1).AddTicks(-1);
}
else
{
resolvedFrom = fromDate!.Value;
resolvedTo = toDate!.Value.Date.AddDays(1).AddTicks(-1);
}
return await _attendanceRepo.GetAttendanceCountsAsync(clientId, resolvedFrom, resolvedTo);
}
public async Task<object> GetTodayAttendance(object payload, HttpContext httpContext)
{
var data = DeserializePayload.Deserialize(payload);
Guid userId = DataExtractor.GetUserIdFromContext(httpContext);
Guid clientId = await _userRoleHelper.GetClientId(userId);
//await _accessDeviceService.GetAttendance(clientId);
return await _attendanceRepo.GetTodayAttendanceAsync(clientId);
}
}
}