91 lines
2.6 KiB
C#
91 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using xCommons.Extensions;
|
|
using xDataService.Configuration;
|
|
using xIdentityModels.Models;
|
|
|
|
namespace xIds.Extensions
|
|
{
|
|
public static class XModelExtensions
|
|
{
|
|
/// <summary>
|
|
/// Determine a banned time is passed or not
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <param name="delaySeconds"></param>
|
|
/// <returns></returns>
|
|
public static bool IsDelayTimePassed(
|
|
this XBannedDevice source,
|
|
int delaySeconds
|
|
)
|
|
{
|
|
//
|
|
var passedTime = source.BannedOn.AddSeconds(delaySeconds);
|
|
|
|
//
|
|
var result = DateTime.UtcNow >= passedTime;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Applying Filter to IQueryable
|
|
/// /// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
public static async Task<IQueryable<T>> ApplyFilterAsync<T>(
|
|
this IQueryable<T> source,
|
|
string filter
|
|
) where T : class
|
|
{
|
|
//
|
|
// Apply Filter ...
|
|
if (!filter.IsNullOrEmpty())
|
|
{
|
|
//
|
|
var items = source.AsAsyncEnumerable();
|
|
var filteredItems = new List<T>();
|
|
await
|
|
foreach (var item in items)
|
|
{
|
|
//
|
|
if (item.GetPropValues()
|
|
.ToNormalString()
|
|
.Contains(filter
|
|
.ToNormalString()))
|
|
{
|
|
//
|
|
filteredItems.Add(item);
|
|
}
|
|
}
|
|
|
|
//
|
|
return filteredItems.AsQueryable();
|
|
}
|
|
|
|
//
|
|
return source;
|
|
}
|
|
|
|
public static XDataServiceConfiguration ToXDataServiceConfig(this Configurations.XDataServiceConfiguration config)
|
|
{
|
|
//
|
|
var result = new XDataServiceConfiguration();
|
|
|
|
//
|
|
if (!config.IsNullOrDefault())
|
|
{
|
|
//
|
|
result.PagingConfiguration.DefaultPageSize = config.PagingConfiguration.DefaultPageSize;
|
|
result.PagingConfiguration.MaxAvailablePageSize = config.PagingConfiguration.MaxAvailablePageSize;
|
|
result.PagingConfiguration.MinAvailablePageSize = config.PagingConfiguration.MinAvailablePageSize;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|
|
} |