fix : Error แก้ไข เนื่องจากกระทบการยกเลิก tracking entity id
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
069f427459
commit
bb9e79b06c
3 changed files with 84 additions and 6 deletions
|
|
@ -77,7 +77,7 @@ namespace BMA.EHR.Application.Repositories.Leaves
|
||||||
(entity as EntityBase).LastUpdatedAt = DateTime.Now;
|
(entity as EntityBase).LastUpdatedAt = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
_dbContext.Detach(entity);
|
//_dbContext.Detach(entity);
|
||||||
_dbSet.Update(entity);
|
_dbSet.Update(entity);
|
||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
|
|
||||||
#region " Overrides "
|
#region " Overrides "
|
||||||
|
|
||||||
public override async Task<LeaveRequest?> GetByIdAsync(Guid id)
|
public async Task<LeaveRequest?> GetByIdWithTrackingAsync(Guid id)
|
||||||
{
|
{
|
||||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
||||||
//.AsNoTracking()
|
//.AsNoTracking()
|
||||||
|
|
@ -84,6 +84,20 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task<LeaveRequest?> GetByIdAsync(Guid id)
|
||||||
|
{
|
||||||
|
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
||||||
|
.AsNoTracking()
|
||||||
|
.Include(x => x.LeaveDocument)
|
||||||
|
.ThenInclude(x => x.Document)
|
||||||
|
.Include(x => x.LeaveDraftDocument)
|
||||||
|
.Include(x => x.LeaveCancelDocument)
|
||||||
|
.Include(x => x.Type)
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
public override async Task<LeaveRequest> AddAsync(LeaveRequest entity)
|
public override async Task<LeaveRequest> AddAsync(LeaveRequest entity)
|
||||||
{
|
{
|
||||||
if (entity.LeaveCancelDocument != null)
|
if (entity.LeaveCancelDocument != null)
|
||||||
|
|
@ -108,7 +122,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
return await base.AddAsync(entity);
|
return await base.AddAsync(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<LeaveRequest> UpdateAsync(LeaveRequest entity)
|
public async Task<LeaveRequest> UpdateWithTrackingAsync(LeaveRequest entity)
|
||||||
{
|
{
|
||||||
// detach
|
// detach
|
||||||
//_dbContext.Detach(entity);
|
//_dbContext.Detach(entity);
|
||||||
|
|
@ -137,6 +151,35 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
return await base.UpdateAsync(entity);
|
return await base.UpdateAsync(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task<LeaveRequest> UpdateAsync(LeaveRequest entity)
|
||||||
|
{
|
||||||
|
// detach
|
||||||
|
//_dbContext.Detach(entity);
|
||||||
|
|
||||||
|
if (entity.LeaveCancelDocument != null)
|
||||||
|
_dbContext.Attatch(entity.LeaveCancelDocument);
|
||||||
|
|
||||||
|
if (entity.LeaveDraftDocument != null)
|
||||||
|
_dbContext.Attatch(entity.LeaveDraftDocument);
|
||||||
|
|
||||||
|
if (entity.LeaveDocument != null)
|
||||||
|
{
|
||||||
|
foreach (var d in entity.LeaveDocument)
|
||||||
|
{
|
||||||
|
_dbContext.Attatch(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.Type != null)
|
||||||
|
{
|
||||||
|
_dbContext.Attatch(entity.Type);
|
||||||
|
//_dbContext.Detach(entity.Type);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return await base.UpdateAsync(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
@ -275,6 +318,41 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
return await rawData.ToListAsync();
|
return await rawData.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<LeaveRequest> ApproveCancelLeaveRequestAsync(LeaveRequest data,string Reason)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken ?? "");
|
||||||
|
if (profile == null)
|
||||||
|
{
|
||||||
|
throw new Exception(GlobalMessages.DataNotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
data.LeaveCancelStatus = "APPROVE";
|
||||||
|
data.LeaveCancelComment = Reason;
|
||||||
|
|
||||||
|
// Send Noti
|
||||||
|
var noti = new Notification
|
||||||
|
{
|
||||||
|
Body = $"การขอยกเลิกใบลาของคุณได้รับการอนุมัติ",
|
||||||
|
ReceiverUserId = profile.Id,
|
||||||
|
Type = "",
|
||||||
|
Payload = "",
|
||||||
|
};
|
||||||
|
_appDbContext.Set<Notification>().Add(noti);
|
||||||
|
await _appDbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task ApproveCancelLeaveRequestAsync(Guid id, string Reason)
|
public async Task ApproveCancelLeaveRequestAsync(Guid id, string Reason)
|
||||||
{
|
{
|
||||||
var rawData = await GetByIdAsync(id);
|
var rawData = await GetByIdAsync(id);
|
||||||
|
|
|
||||||
|
|
@ -1151,7 +1151,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
public async Task<ActionResult<ResponseObject>> CancelLeaveRequestAsync([FromForm] CancelLeaveRequestDto req,
|
public async Task<ActionResult<ResponseObject>> CancelLeaveRequestAsync([FromForm] CancelLeaveRequestDto req,
|
||||||
Guid id)
|
Guid id)
|
||||||
{
|
{
|
||||||
var data = await _leaveRequestRepository.GetByIdAsync(id);
|
var data = await _leaveRequestRepository.GetByIdWithTrackingAsync(id);
|
||||||
if (data == null)
|
if (data == null)
|
||||||
{
|
{
|
||||||
//return Success(new List<object>());
|
//return Success(new List<object>());
|
||||||
|
|
@ -1173,7 +1173,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _leaveRequestRepository.ApproveCancelLeaveRequestAsync(data.Id, "อนุมัติการขอยกเลิกการลา โดยระบบ");
|
data = await _leaveRequestRepository.ApproveCancelLeaveRequestAsync(data, "อนุมัติการขอยกเลิกการลา โดยระบบ");
|
||||||
}
|
}
|
||||||
|
|
||||||
// upload leave cancel document
|
// upload leave cancel document
|
||||||
|
|
@ -1187,7 +1187,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
// save to database
|
// save to database
|
||||||
await _leaveRequestRepository.UpdateAsync(data);
|
await _leaveRequestRepository.UpdateWithTrackingAsync(data);
|
||||||
|
|
||||||
return Success();
|
return Success();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue