feat: add DNA update functionality and enrich leave beginning data with profile details
Some checks failed
release-dev / release-dev (push) Failing after 12s
Some checks failed
release-dev / release-dev (push) Failing after 12s
This commit is contained in:
parent
6b9767449c
commit
fc68cb0101
2 changed files with 55 additions and 2 deletions
|
|
@ -293,7 +293,12 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
FirstName = pf.FirstName,
|
||||
LastName = pf.LastName,
|
||||
LeaveDaysUsed = 0,
|
||||
LeaveDays = leaveType?.Code == "LV-005" ? limit : 0
|
||||
LeaveDays = leaveType?.Code == "LV-005" ? limit : 0,
|
||||
RootDnaId = pf.RootDnaId,
|
||||
Child1DnaId = pf.Child1DnaId,
|
||||
Child2DnaId = pf.Child2DnaId,
|
||||
Child3DnaId = pf.Child3DnaId,
|
||||
Child4DnaId = pf.Child4DnaId
|
||||
};
|
||||
|
||||
_dbContext.Set<LeaveBeginning>().Add(data);
|
||||
|
|
@ -305,6 +310,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
|
||||
public async Task<List<LeaveBeginning>> GetAllByYearAndTypeAsync(int year, Guid typeId, List<ProfileData> userIdList)
|
||||
{
|
||||
|
||||
|
||||
var updateList = new List<LeaveBeginning>();
|
||||
var result = new List<LeaveBeginning>();
|
||||
|
||||
|
|
@ -321,6 +328,12 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
// continue; // Goto Next Id
|
||||
//}
|
||||
|
||||
var profile = await _userProfileRepository.GetProfileByProfileIdAsync(pf.Id, AccessToken);
|
||||
if (profile == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var govAge = (pf?.DateStart?.Date ?? DateTime.Now.Date).DiffDay(DateTime.Now.Date);
|
||||
|
||||
var leaveType = await _dbContext.Set<LeaveType>().FirstOrDefaultAsync(x => x.Id == typeId);
|
||||
|
|
@ -368,7 +381,12 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
FirstName = pf.FirstName,
|
||||
LastName = pf.LastName,
|
||||
LeaveDaysUsed = 0,
|
||||
LeaveDays = leaveType?.Code == "LV-005" ? limit : 0
|
||||
LeaveDays = leaveType?.Code == "LV-005" ? limit : 0,
|
||||
RootDnaId = profile.RootDnaId,
|
||||
Child1DnaId = profile.Child1DnaId,
|
||||
Child2DnaId = profile.Child2DnaId,
|
||||
Child3DnaId = profile.Child3DnaId,
|
||||
Child4DnaId = profile.Child4DnaId
|
||||
};
|
||||
|
||||
updateList.Add(data);
|
||||
|
|
|
|||
|
|
@ -311,6 +311,35 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
[HttpGet("update-dna")]
|
||||
public async Task<ActionResult<ResponseObject>> UpdateDnaAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var leaveBeginnings = await _context.LeaveBeginnings.ToListAsync();
|
||||
foreach (var item in leaveBeginnings)
|
||||
{
|
||||
var profile = await _userProfileRepository.GetProfileByProfileIdAsync(item.ProfileId, AccessToken);
|
||||
if (profile != null)
|
||||
{
|
||||
item.RootDnaId = profile.RootDnaId;
|
||||
item.Child1DnaId = profile.Child1DnaId;
|
||||
item.Child2DnaId = profile.Child2DnaId;
|
||||
item.Child3DnaId = profile.Child3DnaId;
|
||||
item.Child4DnaId = profile.Child4DnaId;
|
||||
_context.LeaveBeginnings.Update(item);
|
||||
}
|
||||
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
return Success("อัพเดทข้อมูลสำเร็จ");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// <summary>
|
||||
/// แก้ไขรายการ
|
||||
|
|
@ -358,6 +387,12 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
leaveBeginning.LastUpdateFullName = FullName ?? "";
|
||||
leaveBeginning.LastUpdatedAt = DateTime.Now;
|
||||
|
||||
leaveBeginning.RootDnaId = profile.RootDnaId;
|
||||
leaveBeginning.Child1DnaId = profile.Child1DnaId;
|
||||
leaveBeginning.Child2DnaId = profile.Child2DnaId;
|
||||
leaveBeginning.Child3DnaId = profile.Child3DnaId;
|
||||
leaveBeginning.Child4DnaId = profile.Child4DnaId;
|
||||
|
||||
await _leaveBeginningRepository.UpdateAsync(leaveBeginning);
|
||||
return Success("แก้ไขข้อมูลสำเร็จ");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue