fix bug swap record

This commit is contained in:
Suphonchai Phoonsawat 2023-08-11 14:05:08 +07:00
parent e5699ea046
commit dbdd4a7be4

View file

@ -614,12 +614,14 @@ namespace BMA.EHR.Application.Repositories.Commands
try
{
var current = await _dbContext.Set<CommandReceiver>()
.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<CommandReceiver>()
.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<CommandReceiver>()
.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();