diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index c0af212d..e1fe44ef 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -614,12 +614,14 @@ namespace BMA.EHR.Application.Repositories.Commands try { var current = await _dbContext.Set() + .Include(c => c.Command) .FirstOrDefaultAsync(x => x.Id == personalId); if (current == null) throw new Exception(GlobalMessages.DataNotFound); var currentSeq = current.Sequence; + var commandID = current.Command!.Id; switch (direction.Trim().ToLower()) { @@ -627,8 +629,10 @@ namespace BMA.EHR.Application.Repositories.Commands { // get prev record var prev = await _dbContext.Set() - .OrderByDescending(x => x.Sequence) + .Include (c => c.Command) + .Where(x => x.Command.Id == commandID) .Where(x => x.Sequence < currentSeq) + .OrderByDescending(x => x.Sequence) .Take(1) .FirstOrDefaultAsync(); @@ -646,8 +650,10 @@ namespace BMA.EHR.Application.Repositories.Commands { // get next record var next = await _dbContext.Set() - .OrderBy(x => x.Sequence) + .Include(c => c.Command) + .Where(x => x.Command.Id == commandID) .Where(x => x.Sequence > currentSeq) + .OrderBy(x => x.Sequence) .Take(1) .FirstOrDefaultAsync();