first commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user