Merge branch 'master' into install-CLI-dependencies-if-not-installed-

pull/1131/head
Yunus Emre Kalkan 6 years ago
commit fa3a7bc338

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

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

@ -4,6 +4,7 @@ using System.Linq.Dynamic.Core;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
using Volo.Abp.MultiTenancy;
using Volo.Abp.ObjectMapping; using Volo.Abp.ObjectMapping;
namespace Volo.Abp.Application.Services namespace Volo.Abp.Application.Services
@ -150,5 +151,22 @@ namespace Volo.Abp.Application.Services
ObjectMapper.Map(updateInput, entity); 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