fix : create and edit leave request
This commit is contained in:
parent
9c696be46e
commit
8ad90f18f0
2 changed files with 15 additions and 4 deletions
|
|
@ -72,7 +72,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
|
||||
public override async Task<LeaveRequest?> GetByIdAsync(Guid id)
|
||||
{
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||
.Include(x => x.LeaveDocument)
|
||||
.ThenInclude(x => x.Document)
|
||||
.Include(x => x.LeaveDraftDocument)
|
||||
|
|
@ -112,7 +112,11 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
// _dbContext.Attatch(entity.LeaveDocument);
|
||||
|
||||
if (entity.Type != null)
|
||||
{
|
||||
|
||||
_dbContext.Attatch(entity.Type);
|
||||
}
|
||||
|
||||
|
||||
return await base.UpdateAsync(entity);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ using Swashbuckle.AspNetCore.Annotations;
|
|||
using System.Security.Claims;
|
||||
using BMA.EHR.Application.Repositories.Commands;
|
||||
using BMA.EHR.Application.Repositories.Leaves.TimeAttendants;
|
||||
using BMA.EHR.Domain.Models.Leave.Commons;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Leave.Service.Controllers
|
||||
{
|
||||
|
|
@ -200,6 +202,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
if (doc != null)
|
||||
{
|
||||
leaveRequest.LeaveDraftDocument = doc;
|
||||
_context.Entry(leaveRequest.LeaveDraftDocument).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -361,7 +364,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
var userCalendar = await _userCalendarRepository.GetExist(profile.Id);
|
||||
var category = userCalendar == null ? "NORMAL" : userCalendar.Calendar;
|
||||
|
||||
var leaveType = await _leaveTypeRepository.GetByIdAsync(req.Type);
|
||||
var leaveType = await _context.Set<LeaveType>().AsNoTracking().FirstOrDefaultAsync(x => x.Id == req.Type); // _leaveTypeRepository.GetByIdAsync(req.Type);
|
||||
if (leaveType == null)
|
||||
{
|
||||
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||
|
|
@ -426,6 +429,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
if (doc != null)
|
||||
{
|
||||
leaveRequest.LeaveDraftDocument = doc;
|
||||
_context.Entry(leaveRequest.LeaveDraftDocument).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -539,13 +543,16 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
leaveRequest.PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel.PosLevelName;
|
||||
leaveRequest.OrganizationName = profile.Oc ?? "";
|
||||
|
||||
_context.Entry(leaveRequest.Type).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
|
||||
//_context.Entry(leaveRequest.Type).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||
|
||||
|
||||
|
||||
// delete old
|
||||
await _leaveRequestRepository.DeleteAsync(oldData);
|
||||
//await _leaveRequestRepository.DeleteAsync(oldData);
|
||||
|
||||
// save to database
|
||||
await _leaveRequestRepository.AddAsync(leaveRequest);
|
||||
await _leaveRequestRepository.UpdateAsync(leaveRequest);
|
||||
|
||||
return Success(new { id = leaveRequest.Id });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue