diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserCalendarRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserCalendarRepository.cs index 61da2e93..5ea0d3b8 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserCalendarRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserCalendarRepository.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using BMA.EHR.Application.Common.Interfaces; using BMA.EHR.Application.Messaging; using BMA.EHR.Domain.Models.Leave.TimeAttendants; @@ -11,7 +7,7 @@ using Microsoft.Extensions.Configuration; namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants { - public class UserCalendarRepository : GenericLeaveRepository + public class UserCalendarRepository : GenericLeaveRepository { #region " Fields " diff --git a/BMA.EHR.Application/Repositories/MetaData/HolidayRepository.cs b/BMA.EHR.Application/Repositories/MetaData/HolidayRepository.cs index 4575a8e2..5b6e0de9 100644 --- a/BMA.EHR.Application/Repositories/MetaData/HolidayRepository.cs +++ b/BMA.EHR.Application/Repositories/MetaData/HolidayRepository.cs @@ -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(); @@ -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; } diff --git a/BMA.EHR.Leave.Service/Controllers/LeaveController.cs b/BMA.EHR.Leave.Service/Controllers/LeaveController.cs index 1299337f..959101ed 100644 --- a/BMA.EHR.Leave.Service/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave.Service/Controllers/LeaveController.cs @@ -5,6 +5,7 @@ using BMA.EHR.Domain.Models.Leave.TimeAttendants; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; using BMA.EHR.Leave.Service.DTOs.AdditionalCheck; +using BMA.EHR.Leave.Service.DTOs.Calendar; using BMA.EHR.Leave.Service.DTOs.ChangeRound; using BMA.EHR.Leave.Service.DTOs.CheckIn; using BMA.EHR.Leave.Service.DTOs.DutyTime; @@ -38,6 +39,8 @@ namespace BMA.EHR.Leave.Service.Controllers private readonly UserDutyTimeRepository _userDutyTimeRepository; private readonly AdditionalCheckRequestRepository _additionalCheckRequestRepository; + private readonly UserCalendarRepository _userCalendarRepository; + private readonly string _bucketName = "check-in"; #endregion @@ -54,7 +57,8 @@ namespace BMA.EHR.Leave.Service.Controllers MinIOService minIOService, ProcessUserTimeStampRepository processUserTimeStampRepository, UserDutyTimeRepository userDutyTimeRepository, - AdditionalCheckRequestRepository additionalCheckRequestRepository) + AdditionalCheckRequestRepository additionalCheckRequestRepository, + UserCalendarRepository userCalendarRepository) { _dutyTimeRepository = dutyTimeRepository; _context = context; @@ -67,6 +71,7 @@ namespace BMA.EHR.Leave.Service.Controllers _processUserTimeStampRepository = processUserTimeStampRepository; _userDutyTimeRepository = userDutyTimeRepository; _additionalCheckRequestRepository = additionalCheckRequestRepository; + _userCalendarRepository = userCalendarRepository; } #endregion @@ -1490,6 +1495,65 @@ namespace BMA.EHR.Leave.Service.Controllers #endregion - #endregion + #region " ปฏิทินการทำงานของ ขรก. " + + /// + /// LV1_023 - แสดงปฏิทินวันทำงานรายคน (ADMIN) + /// + /// + /// + /// เมื่อทำรายการสำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("admin/work/{id:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetCalendarByProfileAsync(Guid id) + { + var data = await _userCalendarRepository.GetExist(id); + if (data == null) + return Success(new { Work = "NORMAL" }); + else + return Success(new { Work = data.Calendar }); + } + + /// + /// LV1_024 - บันทึกแก้ไขปฏิทินวันทำงาน (ADMIN) + /// + /// + /// + /// เมื่อทำรายการสำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("admin/work/{id:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> UpdateCalendarByProfileAsync(Guid id, [FromBody] UpdateCalendarDto req) + { + var data = await _userCalendarRepository.GetExist(id); + if (data != null) + { + data.Calendar = req.Work; + await _userCalendarRepository.UpdateAsync(data); + return Success(); + } + else + { + data = new UserCalendar + { + ProfileId = id, + Calendar = req.Work + }; + + await _userCalendarRepository.AddAsync(data); + + return Success(); + } + + #endregion + + #endregion + } } -} diff --git a/BMA.EHR.Leave.Service/DTOs/Calendar/UpdateCalendarDto.cs b/BMA.EHR.Leave.Service/DTOs/Calendar/UpdateCalendarDto.cs new file mode 100644 index 00000000..592c5dcc --- /dev/null +++ b/BMA.EHR.Leave.Service/DTOs/Calendar/UpdateCalendarDto.cs @@ -0,0 +1,7 @@ +namespace BMA.EHR.Leave.Service.DTOs.Calendar +{ + public class UpdateCalendarDto + { + public string Work { get; set; } = string.Empty; + } +} \ No newline at end of file