Refactor file upload logic in LeaveController to handle check-in scenarios more effectively
#2328
This commit is contained in:
parent
7e613ab2e6
commit
3e34aaa178
1 changed files with 41 additions and 5 deletions
|
|
@ -970,11 +970,11 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _minIOService.UploadFileAsync(fileName, ms);
|
await _minIOService.UploadFileAsync(fileName, ms);
|
||||||
if (lastCheckIn != null && lastCheckIn.CheckOut == null)
|
// if (lastCheckIn != null && lastCheckIn.CheckOut == null)
|
||||||
{
|
// {
|
||||||
// ยังไม่เคย check-out มาก่อน หรือ check-out เป็น null ให้ใช้ชื่อไฟล์แบบ check-out
|
// // ยังไม่เคย check-out มาก่อน หรือ check-out เป็น null ให้ใช้ชื่อไฟล์แบบ check-out
|
||||||
await _minIOService.UploadFileAsync(fileNameCheckOut, ms);
|
// await _minIOService.UploadFileAsync(fileNameCheckOut, ms);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -997,6 +997,42 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lastCheckIn != null && lastCheckIn.CheckOut == null)
|
||||||
|
{
|
||||||
|
using (var ms2 = new MemoryStream(data.CheckInFileBytes ?? new byte[0]))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _minIOService.UploadFileAsync(fileNameCheckOut, ms2);
|
||||||
|
// if (lastCheckIn != null && lastCheckIn.CheckOut == null)
|
||||||
|
// {
|
||||||
|
// // ยังไม่เคย check-out มาก่อน หรือ check-out เป็น null ให้ใช้ชื่อไฟล์แบบ check-out
|
||||||
|
// await _minIOService.UploadFileAsync(fileNameCheckOut, ms);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, $"ไม่สามารถอัปโหลดรูปภาพได้: {ex.Message}");
|
||||||
|
|
||||||
|
// send notification to user
|
||||||
|
var noti1 = new Notification
|
||||||
|
{
|
||||||
|
Body = $"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากไม่สามารถอัปโหลดรูปภาพได้ {ex.Message}",
|
||||||
|
ReceiverUserId = profile.Id,
|
||||||
|
Type = "",
|
||||||
|
Payload = "",
|
||||||
|
};
|
||||||
|
_appDbContext.Set<Notification>().Add(noti1);
|
||||||
|
await _appDbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
|
||||||
|
return Error($"ไม่สามารถอัปโหลดรูปภาพได้: {ex.Message}", StatusCodes.Status500InternalServerError);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var defaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
var defaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
||||||
if (defaultRound == null)
|
if (defaultRound == null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue