Browse Source

Merge pull request #1136 from mehmetuken/patch-1

#1134 Create methods should care multitenancy.
pull/1137/head
Halil İbrahim Kalkan 7 years ago
committed by GitHub
parent
commit
180b39fcd6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AsyncCrudAppService.cs
  2. 7
      framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppService.cs
  3. 18
      framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppServiceBase.cs

8
framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AsyncCrudAppService.cs

@ -1,10 +1,10 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Linq;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Application.Services
{
@ -90,6 +90,12 @@ namespace Volo.Abp.Application.Services
await CheckCreatePolicyAsync();
var entity = MapToEntity(input);
if(entity is IMultiTenant)
{
TryToSetTenantId(entity);
}
await Repository.InsertAsync(entity, autoSave: true);
return MapToEntityDto(entity);

7
framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppService.cs

@ -2,6 +2,7 @@
using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Application.Services
{
@ -86,6 +87,12 @@ namespace Volo.Abp.Application.Services
CheckCreatePolicy();
var entity = MapToEntity(input);
if(entity is IMultiTenant)
{
TryToSetTenantId(entity);
}
Repository.Insert(entity, autoSave: true);
return MapToEntityDto(entity);

18
framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppServiceBase.cs

@ -4,6 +4,7 @@ using System.Linq.Dynamic.Core;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.MultiTenancy;
using Volo.Abp.ObjectMapping;
namespace Volo.Abp.Application.Services
@ -150,5 +151,22 @@ namespace Volo.Abp.Application.Services
ObjectMapper.Map(updateInput, entity);
}
protected virtual void TryToSetTenantId(TEntity entity)
{
var tenantId = CurrentTenant.Id;
if (tenantId == null)
{
return;
}
var propertyInfo = entity.GetType().GetProperty(nameof(IMultiTenant.TenantId));
if (propertyInfo != null && propertyInfo.GetSetMethod() != null)
{
propertyInfo.SetValue(entity, tenantId, null);
}
}
}
}

Loading…
Cancel
Save