public async Task <Result <TId> > Handle(AddEditExtendedAttributeCommand <TId, TEntityId, TEntity, TExtendedAttribute> command, CancellationToken cancellationToken) { if (await _unitOfWork.Repository <TExtendedAttribute>().Entities.Where(x => !x.Id.Equals(command.Id) && x.EntityId.Equals(command.EntityId)) .AnyAsync(p => p.Key == command.Key, cancellationToken)) { return(await Result <TId> .FailAsync(_localizer["Extended Attribute with this Key already exists."])); } if (command.Id.Equals(default))
public async Task <Result <TId> > Handle(DeleteExtendedAttributeCommand <TId, TEntityId, TEntity, TExtendedAttribute> command, CancellationToken cancellationToken) { var extendedAttribute = await _unitOfWork.Repository <TExtendedAttribute>().GetByIdAsync(command.Id); if (extendedAttribute != null) { await _unitOfWork.Repository <TExtendedAttribute>().DeleteAsync(extendedAttribute); // delete all caches related with deleted entity extended attribute var cacheKeys = await _unitOfWork.Repository <TExtendedAttribute>().Entities.Select(x => ApplicationConstants.Cache.GetAllEntityExtendedAttributesByEntityIdCacheKey( typeof(TEntity).Name, x.Entity.Id)).Distinct().ToListAsync(cancellationToken); cacheKeys.Add(ApplicationConstants.Cache.GetAllEntityExtendedAttributesCacheKey(typeof(TEntity).Name)); await _unitOfWork.CommitAndRemoveCache(cancellationToken, cacheKeys.ToArray()); return(await Result <TId> .SuccessAsync(extendedAttribute.Id, _localizer["Extended Attribute Deleted"])); } else { return(await Result <TId> .FailAsync(_localizer["Extended Attribute Not Found!"])); } }