Merge branch 'develop' of github.com:Frappet/BMA-EHR-BackEnd into develop

This commit is contained in:
Kittapath 2024-01-09 12:45:39 +07:00
commit 3d1dfa9997
18 changed files with 2722 additions and 39 deletions

View file

@ -51,6 +51,7 @@ namespace BMA.EHR.Application
services.AddTransient<ProcessUserTimeStampRepository>();
services.AddTransient<UserDutyTimeRepository>();
services.AddTransient<AdditionalCheckRequestRepository>();
services.AddTransient<UserCalendarRepository>();
services.AddTransient<LeaveTypeRepository>();
services.AddTransient<LeaveRequestRepository>();

View file

@ -0,0 +1,80 @@
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Messaging;
using BMA.EHR.Domain.Models.Leave.TimeAttendants;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
{
public class UserCalendarRepository : GenericLeaveRepository<Guid, UserCalendar>
{
#region " Fields "
private readonly ILeaveDbContext _dbContext;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly OrganizationCommonRepository _organizationCommonRepository;
private readonly UserProfileRepository _userProfileRepository;
private readonly IConfiguration _configuration;
private readonly EmailSenderService _emailSenderService;
#endregion
#region " Constructor and Destuctor "
public UserCalendarRepository(ILeaveDbContext dbContext,
IHttpContextAccessor httpContextAccessor,
OrganizationCommonRepository organizationCommonRepository,
UserProfileRepository userProfileRepository,
IConfiguration configuration,
EmailSenderService emailSenderService) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
_organizationCommonRepository = organizationCommonRepository;
_userProfileRepository = userProfileRepository;
_configuration = configuration;
_emailSenderService = emailSenderService;
}
#endregion
#region " Properties "
protected Guid UserOrganizationId
{
get
{
if (UserId != null || UserId != "")
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
else
return Guid.Empty;
}
}
#endregion
#region " Methods "
public async Task<List<UserCalendar>> GetListByProfileIdAsync(Guid profileId)
{
var data = await _dbContext.Set<UserCalendar>().AsQueryable()
.Where(x => x.ProfileId == profileId)
.ToListAsync();
return data;
}
public async Task<UserCalendar?> GetExist(Guid profileId)
{
var data = await _dbContext.Set<UserCalendar>()
.Where(x => x.ProfileId == profileId)
.FirstOrDefaultAsync();
return data;
}
#endregion
}
}

View file

@ -36,7 +36,7 @@ namespace BMA.EHR.Application.Repositories.MetaData
return data;
}
public int GetWeekEndCount(DateTime startDate, DateTime endDate)
public int GetWeekEndCount(DateTime startDate, DateTime endDate, string category = "NORMAL")
{
var dates = new List<DateTime>();
@ -45,7 +45,11 @@ namespace BMA.EHR.Application.Repositories.MetaData
dates.Add(i);
}
var count = dates.Where(d => d.DayOfWeek == DayOfWeek.Saturday || d.DayOfWeek == DayOfWeek.Sunday).Count();
var count = 0;
if (category == "NORMAL")
count = dates.Where(d => d.DayOfWeek == DayOfWeek.Saturday || d.DayOfWeek == DayOfWeek.Sunday).Count();
else
count = dates.Where(d => d.DayOfWeek == DayOfWeek.Sunday).Count();
return count;
}