This commit is contained in:
he
2023-01-16 10:41:07 +08:00
parent cae80eeeba
commit 0655d5bdb0
7 changed files with 46 additions and 15 deletions
@@ -13,6 +13,7 @@ using System.Linq.Expressions;
using System.Threading.Tasks;
using IRaCIS.Core.Domain.Share;
using EFCore.BulkExtensions;
using Microsoft.Extensions.Localization;
namespace IRaCIS.Core.Infra.EFCore
{
@@ -85,8 +86,11 @@ namespace IRaCIS.Core.Infra.EFCore
public IUserInfo _userInfo { get; set; }
public Repository(IRaCISDBContext dbContext, IMapper mapper, IUserInfo userInfo)
public IStringLocalizer _localizer { get; set; }
public Repository(IRaCISDBContext dbContext, IMapper mapper, IUserInfo userInfo, IStringLocalizer localizer)
{
_localizer = localizer;
_dbContext = dbContext;
_mapper = mapper;
_userInfo = userInfo;
@@ -173,8 +177,8 @@ namespace IRaCIS.Core.Infra.EFCore
if (dbEntity == null)
{
throw new BusinessValidationFailedException(
" Update object not exist in db,Please check if the parameter Id is passed incorrectly");
throw new BusinessValidationFailedException(_localizer["Repository_UpdateError"]);
}
var dbBeforEntity = dbEntity.Clone();
@@ -14,6 +14,8 @@ using EFCore.BulkExtensions;
using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Infrastructure;
using IRaCIS.Core.Infrastructure.Extention;
using Microsoft.Extensions.Localization;
namespace IRaCIS.Core.Infra.EFCore
{
public interface IRepository<TEntity> : ICommandRepository<TEntity>, IQueryRepository<TEntity> where TEntity : Entity
@@ -30,12 +32,15 @@ namespace IRaCIS.Core.Infra.EFCore
public IMapper _mapper { get; set; }
public IRaCISDBContext _dbContext { get; set; }
public IStringLocalizer _localizer { get; set; }
public DbSet<TEntity> _dbSet => _dbContext.Set<TEntity>();
public IUserInfo _userInfo { get; set; }
public Repository(IRaCISDBContext dbContext, IMapper mapper, IUserInfo userInfo)
public Repository(IRaCISDBContext dbContext, IMapper mapper, IUserInfo userInfo, IStringLocalizer localizer)
{
_localizer = localizer;
_dbContext = dbContext;
_mapper = mapper;
_userInfo = userInfo;
@@ -103,8 +108,8 @@ namespace IRaCIS.Core.Infra.EFCore
if (dbEntity == null)
{
throw new BusinessValidationFailedException(
" Update object not exist in db,Please check if the parameter Id is passed incorrectly");
throw new BusinessValidationFailedException(_localizer["Repository_UpdateError"]);
}
var dbBeforEntity = dbEntity.Clone();
@@ -208,8 +213,7 @@ namespace IRaCIS.Core.Infra.EFCore
if (searchEntity == null)
{
throw new BusinessValidationFailedException(
" Update object not exist in db,Please check if the parameter Id is passed incorrectly");
throw new BusinessValidationFailedException(_localizer["Repository_UpdateError"]);
}
_dbContext.EntityModifyPartialFiled(searchEntity, updateFactory);
@@ -261,8 +265,7 @@ namespace IRaCIS.Core.Infra.EFCore
if (waitDelete == null)
{
throw new BusinessValidationFailedException(
" Delete object not exist in db,Please check if the parameter Id is passed incorrectly");
throw new BusinessValidationFailedException(_localizer["Repository_DeleteError"]);
}
await DeleteAsync(waitDelete, autoSave);