Merge branch 'develop' into work
This commit is contained in:
commit
c56e3b06b9
12 changed files with 849 additions and 29 deletions
|
|
@ -7,6 +7,8 @@ namespace BMA.EHR.Application.Common.Interfaces
|
|||
{
|
||||
DbSet<T> Set<T>() where T : class;
|
||||
|
||||
void Attatch<T>(T entity) where T : class;
|
||||
|
||||
Task<int> SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
using Amazon.S3.Model.Internal.MarshallTransformations;
|
||||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Application.Requests.Commands;
|
||||
using BMA.EHR.Domain.Models.Commands.Core;
|
||||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using BMA.EHR.Domain.Models.Organizations;
|
||||
using BMA.EHR.Domain.Models.Placement;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Transactions;
|
||||
using Command = BMA.EHR.Domain.Models.Commands.Core.Command;
|
||||
|
||||
namespace BMA.EHR.Application.Repositories.Commands
|
||||
|
|
@ -39,11 +42,44 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
return await _dbContext.Set<Command>()
|
||||
.Include(x => x.Placement)
|
||||
.Include(x => x.CommandType)
|
||||
.Include(x => x.Documents)
|
||||
.Include(x => x.Receivers)
|
||||
.Include(x => x.CommandStatus)
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
}
|
||||
|
||||
public override async Task<IReadOnlyList<Command>> GetAllAsync()
|
||||
{
|
||||
return await _dbContext.Set<Command>()
|
||||
.Include(x => x.Placement)
|
||||
.Include(x => x.CommandType)
|
||||
.Include(x => x.CommandStatus)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public override async Task<Command> AddAsync(Command command)
|
||||
{
|
||||
var status = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(c => c.Sequence == 1);
|
||||
command.CommandStatus = status!;
|
||||
_dbContext.Attatch(status!);
|
||||
|
||||
return await base.AddAsync(command);
|
||||
}
|
||||
|
||||
public override async Task<Command> UpdateAsync(Command entity)
|
||||
{
|
||||
// attatch
|
||||
_dbContext.Attatch(entity.CommandStatus);
|
||||
_dbContext.Attatch(entity.CommandType);
|
||||
_dbContext.Attatch(entity.Placement);
|
||||
|
||||
return await base.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Command Receiver "
|
||||
|
||||
public async Task<List<CommandReceiver>> GetReceiverByCommmandIdAsync(Guid Id)
|
||||
{
|
||||
try
|
||||
|
|
@ -135,6 +171,89 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<CommandReceiver?> GetCommandReceiverAsync(Guid personalId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var receiver = await _dbContext.Set<CommandReceiver>()
|
||||
.FirstOrDefaultAsync(x => x.Id == personalId);
|
||||
|
||||
if (receiver == null)
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
|
||||
return receiver;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public async Task SwapReceiverOrderAsync(Guid personalId, string direction)
|
||||
{
|
||||
try
|
||||
{
|
||||
var current = await _dbContext.Set<CommandReceiver>()
|
||||
.FirstOrDefaultAsync(x => x.Id == personalId);
|
||||
|
||||
if (current == null)
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
|
||||
var currentSeq = current.Sequence;
|
||||
|
||||
switch (direction.Trim().ToLower())
|
||||
{
|
||||
case "up":
|
||||
{
|
||||
// get prev record
|
||||
var prev = await _dbContext.Set<CommandReceiver>()
|
||||
.OrderByDescending(x => x.Sequence)
|
||||
.Where(x => x.Sequence < currentSeq)
|
||||
.Take(1)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (prev != null)
|
||||
{
|
||||
var prevSeq = prev.Sequence;
|
||||
|
||||
current.Sequence = prevSeq;
|
||||
prev.Sequence = currentSeq;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "down":
|
||||
{
|
||||
// get next record
|
||||
var next = await _dbContext.Set<CommandReceiver>()
|
||||
.OrderBy(x => x.Sequence)
|
||||
.Where(x => x.Sequence > currentSeq)
|
||||
.Take(1)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (next != null)
|
||||
{
|
||||
var nextSeq = next.Sequence;
|
||||
|
||||
current.Sequence = nextSeq;
|
||||
next.Sequence = currentSeq;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: throw new Exception("Invalid swap direction!");
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public async Task<List<CommandDeployment>> GetDeploymentByCommandIdAsync(Guid id)
|
||||
{
|
||||
try
|
||||
|
|
@ -314,6 +433,54 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
|
||||
#region " Documents "
|
||||
|
||||
public async Task<List<CommandDocument>> GetExistDocument(Guid id, string category)
|
||||
{
|
||||
try
|
||||
{
|
||||
var command = await _dbContext.Set<Command>()
|
||||
.Include(x => x.Documents)
|
||||
.ThenInclude(x => x.Document)
|
||||
.FirstOrDefaultAsync(c => c.Id == id);
|
||||
if (command == null)
|
||||
throw new Exception(GlobalMessages.CommandNotFound);
|
||||
|
||||
// insert new record to comand Document
|
||||
var exist = command.Documents.Where(x => x.Category == category).ToList();
|
||||
|
||||
return exist;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UploadDocument(Guid id, string category, CommandDocument document)
|
||||
{
|
||||
try
|
||||
{
|
||||
var command = await _dbContext.Set<Command>().Include(x => x.Documents).FirstOrDefaultAsync(c => c.Id == id);
|
||||
if (command == null)
|
||||
throw new Exception(GlobalMessages.CommandNotFound);
|
||||
|
||||
// insert new record to comand Document
|
||||
var exist = command.Documents.Where(x => x.Category == category).ToList();
|
||||
if (exist.Any())
|
||||
{
|
||||
_dbContext.Set<CommandDocument>().RemoveRange(exist);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
// insert new Record
|
||||
command.Documents.Add(document);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<CommandDocument>> GetCommandDocumentAsync(Guid id)
|
||||
{
|
||||
try
|
||||
|
|
@ -334,12 +501,116 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
|
||||
#endregion
|
||||
|
||||
#region " Change Command Status "
|
||||
|
||||
public async Task GotoNextStateAsync(Guid id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var command = await _dbContext.Set<Command>().Include(c => c.CommandStatus).FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (command == null)
|
||||
throw new Exception(GlobalMessages.CommandNotFound);
|
||||
|
||||
var notProcess = new int[] { 4, 5 };
|
||||
|
||||
if (!notProcess.Contains(command.CommandStatus.Sequence))
|
||||
{
|
||||
var nextStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(c => c.Sequence == command.CommandStatus.Sequence + 1);
|
||||
command.CommandStatus = nextStatus!;
|
||||
_dbContext.Attatch(nextStatus!);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task GotoPrevStateAsync(Guid id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var command = await _dbContext.Set<Command>().Include(c => c.CommandStatus).FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (command == null)
|
||||
throw new Exception(GlobalMessages.CommandNotFound);
|
||||
|
||||
var notProcess = new int[] { 1, 5 };
|
||||
|
||||
if (!notProcess.Contains(command.CommandStatus.Sequence))
|
||||
{
|
||||
var nextStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(c => c.Sequence == command.CommandStatus.Sequence - 1);
|
||||
command.CommandStatus = nextStatus!;
|
||||
_dbContext.Attatch(nextStatus!);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Change Detail Sequence "
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Placement "
|
||||
|
||||
public async Task UpdatePlacementSalaryAsync(Guid placementProfileId, UpdatePlacementSalaryRequest req)
|
||||
{
|
||||
try
|
||||
{
|
||||
var placementProfile = await _dbContext.Set<PlacementProfile>()
|
||||
.FirstOrDefaultAsync(p => p.Id == placementProfileId);
|
||||
|
||||
if (placementProfile == null)
|
||||
throw new Exception($"Invalid placement profile: {placementProfileId}");
|
||||
|
||||
placementProfile.Amount = req.SalaryAmount;
|
||||
placementProfile.PositionSalaryAmount = req.PositionSalaryAmount;
|
||||
placementProfile.MouthSalaryAmount = req.MonthSalaryAmount;
|
||||
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<PositionPath>> GetPlacementPositionPath(Guid id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = await _dbContext.Set<PlacementProfile>()
|
||||
.Include(x => x.PositionPath)
|
||||
.Include(x => x.Placement)
|
||||
.Where(x => x.Placement!.Id == id)
|
||||
.Where(x => x.PositionPath != null)
|
||||
.Select(x => x.PositionPath)
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
|
||||
return data!;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public async Task UpdateCommandInfo(Guid id, string orderNo, string orderYear, DateTime signDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
var command = await _dbContext.Set<Command>().FirstOrDefaultAsync(x => x.Id == id);
|
||||
if(command == null)
|
||||
if (command == null)
|
||||
throw new Exception(GlobalMessages.CommandNotFound);
|
||||
|
||||
command.CommandExcecuteDate = signDate;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Domain.Models.Base;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Security.Claims;
|
||||
|
|
@ -49,12 +50,12 @@ namespace BMA.EHR.Application.Repositories
|
|||
|
||||
public virtual async Task<T> AddAsync(T entity)
|
||||
{
|
||||
//if (entity is IAuditableEntity)
|
||||
//{
|
||||
// (entity as IAuditableEntity).CreatedUserId = Guid.Parse(UserId);
|
||||
// (entity as IAuditableEntity).CreatedUserFullName = FullName;
|
||||
// (entity as IAuditableEntity).CreatedDate = DateTime.Now;
|
||||
//}
|
||||
if (entity is EntityBase)
|
||||
{
|
||||
(entity as EntityBase).CreatedUserId = UserId!;
|
||||
(entity as EntityBase).CreatedFullName = FullName!;
|
||||
(entity as EntityBase).CreatedAt = DateTime.Now;
|
||||
}
|
||||
|
||||
|
||||
await _dbSet.AddAsync(entity);
|
||||
|
|
@ -65,12 +66,12 @@ namespace BMA.EHR.Application.Repositories
|
|||
|
||||
public virtual async Task<T> UpdateAsync(T entity)
|
||||
{
|
||||
//if (entity is IAuditableEntity)
|
||||
//{
|
||||
// (entity as IAuditableEntity).ModifiedUserId = Guid.Parse(UserId);
|
||||
// (entity as IAuditableEntity).ModifiedUserFullName = FullName;
|
||||
// (entity as IAuditableEntity).ModifiedDate = DateTime.Now;
|
||||
//}
|
||||
if (entity is EntityBase)
|
||||
{
|
||||
(entity as EntityBase).LastUpdateUserId = UserId!;
|
||||
(entity as EntityBase).LastUpdateFullName = FullName!;
|
||||
(entity as EntityBase).LastUpdatedAt = DateTime.Now;
|
||||
}
|
||||
|
||||
_dbSet.Update(entity);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
namespace BMA.EHR.Application.Requests.Commands
|
||||
{
|
||||
public class UpdatePlacementSalaryRequest
|
||||
{
|
||||
public double SalaryAmount { get; set; } = 0;
|
||||
|
||||
public double PositionSalaryAmount { get; set; } = 0;
|
||||
|
||||
public double MonthSalaryAmount { get; set; } = 0;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue