Browse Source

Minor refactor.

pull/96/head
Halil İbrahim Kalkan 9 years ago
parent
commit
755a61a92f
  1. 17
      src/Volo.Abp/Volo/Abp/Application/Services/CrudAppServiceBase.cs

17
src/Volo.Abp/Volo/Abp/Application/Services/CrudAppServiceBase.cs

@ -115,15 +115,24 @@ namespace Volo.Abp.Application.Services
protected virtual TEntity MapToEntity(TCreateInput createInput) protected virtual TEntity MapToEntity(TCreateInput createInput)
{ {
var entity = ObjectMapper.Map<TCreateInput, TEntity>(createInput); var entity = ObjectMapper.Map<TCreateInput, TEntity>(createInput);
SetIdForGuids(entity);
return entity;
}
//Set ID for GUIDs /// <summary>
/// Sets Id value for the entity if <see cref="TPrimaryKey"/> is <see cref="Guid"/>.
/// It's used while creating a new entity.
/// </summary>
protected virtual void SetIdForGuids(TEntity entity)
{
var entityWithGuidId = entity as IEntity<Guid>; var entityWithGuidId = entity as IEntity<Guid>;
if (entityWithGuidId != null && entityWithGuidId.Id == Guid.Empty)
if (entityWithGuidId == null || entityWithGuidId.Id != Guid.Empty)
{ {
entityWithGuidId.Id = GuidGenerator.Create(); return;
} }
return entity; entityWithGuidId.Id = GuidGenerator.Create();
} }
/// <summary> /// <summary>

Loading…
Cancel
Save