fix Edit Leave with Upload File Error
Some checks failed
release-dev / release-dev (push) Failing after 13s
Some checks failed
release-dev / release-dev (push) Failing after 13s
This commit is contained in:
parent
3c1182ff26
commit
76c722137d
1 changed files with 68 additions and 53 deletions
|
|
@ -393,6 +393,19 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
// else
|
||||
// leaveTotal = sumLeave - sumHoliday - sumWeekend;
|
||||
|
||||
// ลองใช้ oldData
|
||||
oldData.LeaveRange = req.LeaveRange;
|
||||
oldData.LeaveStartDate = req.LeaveStartDate;
|
||||
oldData.LeaveEndDate = req.LeaveEndDate;
|
||||
oldData.LeaveWrote = req.LeaveWrote ?? "";
|
||||
oldData.LeaveDetail = req.LeaveDetail ?? "";
|
||||
oldData.LeaveAddress = req.LeaveAddress ?? "";
|
||||
oldData.LeaveNumber = req.LeaveNumber ?? "";
|
||||
oldData.LeaveTotal = req.LeaveTotal;
|
||||
oldData.LeaveSalaryText = req.LeaveSalaryText ?? "";
|
||||
|
||||
/*** remove old code
|
||||
|
||||
var leaveRequest = new LeaveRequest
|
||||
{
|
||||
Id = id,
|
||||
|
|
@ -422,6 +435,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
// get leave last
|
||||
leaveRequest.LeaveLast = await _leaveRequestRepository.GetLeaveLastByTypeForUserAsync(userId, req.Type);
|
||||
|
||||
**/
|
||||
|
||||
// upload document
|
||||
if (req.LeaveDocument != null)
|
||||
{
|
||||
|
|
@ -430,8 +445,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
var doc = await _minIOService.UploadFileAsync(d);
|
||||
if (doc != null)
|
||||
{
|
||||
leaveRequest.LeaveDocument.Add(new LeaveDocument { Document = doc });
|
||||
var a = leaveRequest.LeaveDocument.Last();
|
||||
oldData.LeaveDocument.Add(new LeaveDocument { Document = doc });
|
||||
var a = oldData.LeaveDocument.Last();
|
||||
_context.Entry(a).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||
}
|
||||
}
|
||||
|
|
@ -443,8 +458,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
var doc = await _minIOService.UploadFileAsync(req.LeaveDraftDocument);
|
||||
if (doc != null)
|
||||
{
|
||||
leaveRequest.LeaveDraftDocument = doc;
|
||||
_context.Entry(leaveRequest.LeaveDraftDocument).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||
oldData.LeaveDraftDocument = doc;
|
||||
_context.Entry(oldData.LeaveDraftDocument).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -453,91 +468,91 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
{
|
||||
case "LV-004":
|
||||
{
|
||||
leaveRequest.WifeDayName = req.WifeDayName ?? "";
|
||||
leaveRequest.WifeDayDateBorn = req.WifeDayDateBorn ?? "";
|
||||
oldData.WifeDayName = req.WifeDayName ?? "";
|
||||
oldData.WifeDayDateBorn = req.WifeDayDateBorn ?? "";
|
||||
}
|
||||
break;
|
||||
case "LV-005":
|
||||
{
|
||||
leaveRequest.RestDayOldTotal =
|
||||
oldData.RestDayOldTotal =
|
||||
await _leaveRequestRepository.GetRestDayTotalByYearForUserAsync(userId, thisYear - 1);
|
||||
leaveRequest.RestDayCurrentTotal =
|
||||
oldData.RestDayCurrentTotal =
|
||||
await _leaveRequestRepository.GetRestDayTotalByYearForUserAsync(userId, thisYear);
|
||||
}
|
||||
break;
|
||||
case "LV-006":
|
||||
{
|
||||
leaveRequest.OrdainDayStatus = req.OrdainDayStatus ?? false;
|
||||
leaveRequest.OrdainDayLocationName = req.OrdainDayLocationName ?? "";
|
||||
leaveRequest.OrdainDayLocationAddress = req.OrdainDayLocationAddress ?? "";
|
||||
leaveRequest.OrdainDayLocationNumber = req.OrdainDayLocationNumber ?? "";
|
||||
oldData.OrdainDayStatus = req.OrdainDayStatus ?? false;
|
||||
oldData.OrdainDayLocationName = req.OrdainDayLocationName ?? "";
|
||||
oldData.OrdainDayLocationAddress = req.OrdainDayLocationAddress ?? "";
|
||||
oldData.OrdainDayLocationNumber = req.OrdainDayLocationNumber ?? "";
|
||||
if (req.OrdainDayOrdination != null)
|
||||
leaveRequest.OrdainDayOrdination = req.OrdainDayOrdination.Value;
|
||||
oldData.OrdainDayOrdination = req.OrdainDayOrdination.Value;
|
||||
|
||||
leaveRequest.OrdainDayBuddhistLentName = req.OrdainDayBuddhistLentName ?? "";
|
||||
oldData.OrdainDayBuddhistLentName = req.OrdainDayBuddhistLentName ?? "";
|
||||
|
||||
leaveRequest.OrdainDayBuddhistLentAddress = req.OrdainDayBuddhistLentAddress ?? "";
|
||||
oldData.OrdainDayBuddhistLentAddress = req.OrdainDayBuddhistLentAddress ?? "";
|
||||
|
||||
leaveRequest.LeaveBirthDate = profile.BirthDate;
|
||||
leaveRequest.LeaveGovernmentDate = profile.DateStart;
|
||||
oldData.LeaveBirthDate = profile.BirthDate;
|
||||
oldData.LeaveGovernmentDate = profile.DateStart;
|
||||
|
||||
leaveRequest.HajjDayStatus = req.HajjDayStatus ?? false;
|
||||
oldData.HajjDayStatus = req.HajjDayStatus ?? false;
|
||||
}
|
||||
break;
|
||||
case "LV-007":
|
||||
{
|
||||
leaveRequest.AbsentDayLocation = req.AbsentDayLocation ?? "";
|
||||
leaveRequest.AbsentDaySummon = req.AbsentDaySummon ?? "";
|
||||
oldData.AbsentDayLocation = req.AbsentDayLocation ?? "";
|
||||
oldData.AbsentDaySummon = req.AbsentDaySummon ?? "";
|
||||
if (req.AbsentDayRegistorDate != null)
|
||||
leaveRequest.AbsentDayRegistorDate = req.AbsentDayRegistorDate.Value;
|
||||
oldData.AbsentDayRegistorDate = req.AbsentDayRegistorDate.Value;
|
||||
|
||||
leaveRequest.AbsentDayGetIn = req.AbsentDayGetIn ?? "";
|
||||
oldData.AbsentDayGetIn = req.AbsentDayGetIn ?? "";
|
||||
|
||||
leaveRequest.AbsentDayAt = req.AbsentDayAt ?? "";
|
||||
oldData.AbsentDayAt = req.AbsentDayAt ?? "";
|
||||
}
|
||||
break;
|
||||
case "LV-008":
|
||||
{
|
||||
var lastSalary = profile.ProfileSalary;
|
||||
|
||||
leaveRequest.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value;
|
||||
leaveRequest.LeaveSalaryText =
|
||||
oldData.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value;
|
||||
oldData.LeaveSalaryText =
|
||||
lastSalary == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false);
|
||||
leaveRequest.LeaveBirthDate = profile.BirthDate;
|
||||
leaveRequest.LeaveGovernmentDate = profile.DateStart;
|
||||
oldData.LeaveBirthDate = profile.BirthDate;
|
||||
oldData.LeaveGovernmentDate = profile.DateStart;
|
||||
|
||||
leaveRequest.StudyDaySubject = req.StudyDaySubject ?? "";
|
||||
leaveRequest.StudyDayDegreeLevel = req.StudyDayDegreeLevel ?? "";
|
||||
leaveRequest.StudyDayUniversityName = req.StudyDayUniversityName ?? "";
|
||||
leaveRequest.StudyDayCountry = req.StudyDayCountry ?? "";
|
||||
leaveRequest.StudyDayScholarship = req.StudyDayScholarship ?? "";
|
||||
oldData.StudyDaySubject = req.StudyDaySubject ?? "";
|
||||
oldData.StudyDayDegreeLevel = req.StudyDayDegreeLevel ?? "";
|
||||
oldData.StudyDayUniversityName = req.StudyDayUniversityName ?? "";
|
||||
oldData.StudyDayCountry = req.StudyDayCountry ?? "";
|
||||
oldData.StudyDayScholarship = req.StudyDayScholarship ?? "";
|
||||
|
||||
leaveRequest.StudyDayTrainingSubject = req.StudyDayTrainingSubject ?? "";
|
||||
leaveRequest.StudyDayTrainingName = req.StudyDayTrainingName ?? "";
|
||||
oldData.StudyDayTrainingSubject = req.StudyDayTrainingSubject ?? "";
|
||||
oldData.StudyDayTrainingName = req.StudyDayTrainingName ?? "";
|
||||
}
|
||||
break;
|
||||
case "LV-010":
|
||||
{
|
||||
var lastSalary = profile.ProfileSalary;
|
||||
|
||||
leaveRequest.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value;
|
||||
leaveRequest.LeaveSalaryText =
|
||||
oldData.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value;
|
||||
oldData.LeaveSalaryText =
|
||||
lastSalary == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false);
|
||||
|
||||
leaveRequest.CoupleDayName = req.CoupleDayName ?? "";
|
||||
leaveRequest.CoupleDayPosition = req.CoupleDayPosition ?? "";
|
||||
leaveRequest.CoupleDayLevel = req.CoupleDayLevel ?? "";
|
||||
leaveRequest.CoupleDayLevelCountry = req.CoupleDayLevelCountry ?? "";
|
||||
leaveRequest.CoupleDayCountryHistory = req.CoupleDayCountryHistory ?? "";
|
||||
leaveRequest.CoupleDayTotalHistory = req.CoupleDayTotalHistory ?? "";
|
||||
oldData.CoupleDayName = req.CoupleDayName ?? "";
|
||||
oldData.CoupleDayPosition = req.CoupleDayPosition ?? "";
|
||||
oldData.CoupleDayLevel = req.CoupleDayLevel ?? "";
|
||||
oldData.CoupleDayLevelCountry = req.CoupleDayLevelCountry ?? "";
|
||||
oldData.CoupleDayCountryHistory = req.CoupleDayCountryHistory ?? "";
|
||||
oldData.CoupleDayTotalHistory = req.CoupleDayTotalHistory ?? "";
|
||||
|
||||
if (req.CoupleDayStartDateHistory != null)
|
||||
leaveRequest.CoupleDayStartDateHistory = req.CoupleDayStartDateHistory.Value;
|
||||
oldData.CoupleDayStartDateHistory = req.CoupleDayStartDateHistory.Value;
|
||||
|
||||
if (req.CoupleDayEndDateHistory != null)
|
||||
leaveRequest.CoupleDayEndDateHistory = req.CoupleDayEndDateHistory.Value;
|
||||
oldData.CoupleDayEndDateHistory = req.CoupleDayEndDateHistory.Value;
|
||||
|
||||
leaveRequest.CoupleDaySumTotalHistory = req.CoupleDaySumTotalHistory ?? "";
|
||||
oldData.CoupleDaySumTotalHistory = req.CoupleDaySumTotalHistory ?? "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -552,13 +567,13 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
approver = list.First().Name;
|
||||
}
|
||||
|
||||
leaveRequest.LeaveTypeCode = leaveType.Code;
|
||||
leaveRequest.Dear = approver;
|
||||
leaveRequest.PositionName = profile.Position == null ? "" : profile.Position;
|
||||
leaveRequest.PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel.PosLevelName;
|
||||
leaveRequest.OrganizationName = profile.Oc ?? "";
|
||||
oldData.LeaveTypeCode = leaveType.Code;
|
||||
oldData.Dear = approver;
|
||||
oldData.PositionName = profile.Position == null ? "" : profile.Position;
|
||||
oldData.PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel.PosLevelName;
|
||||
oldData.OrganizationName = profile.Oc ?? "";
|
||||
|
||||
_context.Entry(leaveRequest.Type).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
|
||||
_context.Entry(oldData.Type).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
|
||||
//_context.Entry(leaveRequest.Type).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||
|
||||
|
||||
|
|
@ -567,9 +582,9 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
//await _leaveRequestRepository.DeleteAsync(oldData);
|
||||
|
||||
// save to database
|
||||
await _leaveRequestRepository.UpdateAsync(leaveRequest);
|
||||
await _leaveRequestRepository.UpdateAsync(oldData);
|
||||
|
||||
return Success(new { id = leaveRequest.Id });
|
||||
return Success(new { id = oldData.Id });
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue