31 lines
878 B
C#
31 lines
878 B
C#
using System;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using GerstITS.Common;
|
|
using GerstITS.Data;
|
|
|
|
namespace GerstITS.Examples.Logic.Shared
|
|
{
|
|
internal static class ISearchEngineExtensions
|
|
{
|
|
#region Methods
|
|
|
|
public static TEntity QueryBy<TEntity>(this IReadOnlyRepository repository, Expression<Func<TEntity, bool>> condition)
|
|
where TEntity : IEntity
|
|
{
|
|
return repository.Query<TEntity>()
|
|
.Where(condition)
|
|
.FirstOrDefault();
|
|
}
|
|
|
|
public static TModel ThrowsAnExceptionIfNotFound<TModel, TKey>(this TModel model, TKey id)
|
|
{
|
|
if (model.IsNull())
|
|
throw new EntityNotFoundException($"{typeof(TModel).Name} with id '{id}' not found.");
|
|
|
|
return model;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |