แก้บั้กบันทึกคำสั่งไม่ได้
เพิ่มการใส่ค่าผู้ทำรายการใน GenericRepoository
This commit is contained in:
parent
71c8ff95e4
commit
e8607f76fa
4 changed files with 29 additions and 12 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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,15 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public async Task<List<CommandReceiver>> GetReceiverByCommmandIdAsync(Guid Id)
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -313,5 +313,10 @@ namespace BMA.EHR.Infrastructure.Persistence
|
|||
{
|
||||
return base.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public void Attatch<T>(T entity) where T : class
|
||||
{
|
||||
Attach(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue