แก้บั้กบันทึกคำสั่งไม่ได้
เพิ่มการใส่ค่าผู้ทำรายการใน 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;
|
DbSet<T> Set<T>() where T : class;
|
||||||
|
|
||||||
|
void Attatch<T>(T entity) where T : class;
|
||||||
|
|
||||||
Task<int> SaveChangesAsync();
|
Task<int> SaveChangesAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,15 @@ namespace BMA.EHR.Application.Repositories.Commands
|
||||||
.FirstOrDefaultAsync(x => x.Id == id);
|
.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
|
#endregion
|
||||||
|
|
||||||
public async Task<List<CommandReceiver>> GetReceiverByCommmandIdAsync(Guid Id)
|
public async Task<List<CommandReceiver>> GetReceiverByCommmandIdAsync(Guid Id)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using BMA.EHR.Application.Common.Interfaces;
|
using BMA.EHR.Application.Common.Interfaces;
|
||||||
|
using BMA.EHR.Domain.Models.Base;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
|
|
@ -49,12 +50,12 @@ namespace BMA.EHR.Application.Repositories
|
||||||
|
|
||||||
public virtual async Task<T> AddAsync(T entity)
|
public virtual async Task<T> AddAsync(T entity)
|
||||||
{
|
{
|
||||||
//if (entity is IAuditableEntity)
|
if (entity is EntityBase)
|
||||||
//{
|
{
|
||||||
// (entity as IAuditableEntity).CreatedUserId = Guid.Parse(UserId);
|
(entity as EntityBase).CreatedUserId = UserId!;
|
||||||
// (entity as IAuditableEntity).CreatedUserFullName = FullName;
|
(entity as EntityBase).CreatedFullName = FullName!;
|
||||||
// (entity as IAuditableEntity).CreatedDate = DateTime.Now;
|
(entity as EntityBase).CreatedAt = DateTime.Now;
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
|
||||||
await _dbSet.AddAsync(entity);
|
await _dbSet.AddAsync(entity);
|
||||||
|
|
@ -65,12 +66,12 @@ namespace BMA.EHR.Application.Repositories
|
||||||
|
|
||||||
public virtual async Task<T> UpdateAsync(T entity)
|
public virtual async Task<T> UpdateAsync(T entity)
|
||||||
{
|
{
|
||||||
//if (entity is IAuditableEntity)
|
if (entity is EntityBase)
|
||||||
//{
|
{
|
||||||
// (entity as IAuditableEntity).ModifiedUserId = Guid.Parse(UserId);
|
(entity as EntityBase).LastUpdateUserId = UserId!;
|
||||||
// (entity as IAuditableEntity).ModifiedUserFullName = FullName;
|
(entity as EntityBase).LastUpdateFullName = FullName!;
|
||||||
// (entity as IAuditableEntity).ModifiedDate = DateTime.Now;
|
(entity as EntityBase).LastUpdatedAt = DateTime.Now;
|
||||||
//}
|
}
|
||||||
|
|
||||||
_dbSet.Update(entity);
|
_dbSet.Update(entity);
|
||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
|
|
|
||||||
|
|
@ -313,5 +313,10 @@ namespace BMA.EHR.Infrastructure.Persistence
|
||||||
{
|
{
|
||||||
return base.SaveChangesAsync();
|
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