From dbdd4a7be41700a138c26b7ba56b6376d7831877 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 11 Aug 2023 14:05:08 +0700 Subject: [PATCH] fix bug swap record --- .../Repositories/Commands/CommandRepository.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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();