本文整理汇总了C#中GenericRepository.GetByMultipleConditions方法的典型用法代码示例。如果您正苦于以下问题:C# GenericRepository.GetByMultipleConditions方法的具体用法?C# GenericRepository.GetByMultipleConditions怎么用?C# GenericRepository.GetByMultipleConditions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericRepository
的用法示例。
在下文中一共展示了GenericRepository.GetByMultipleConditions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search
public List<Trip> Search(string username, string depDate, int? depLocId, int? arrLocId, double? price, int? seatNum, int? estHour, int? hour)
{
GenericRepository<Trip> tripRepo = new GenericRepository<Trip>();
GenericRepository<User> userRepo = new GenericRepository<User>();
DateTime departDate;
List<Expression<Func<Trip, bool>>> filters = new List<Expression<Func<Trip, bool>>>();
if (!string.IsNullOrEmpty(depDate))
{
if (DateTime.TryParse(depDate, out departDate))
{
filters.Add(t => t.DepartDate >= departDate);
}
}
if (!string.IsNullOrEmpty(username))
{
User user = userRepo.First(u => u.Username.Contains(username));
filters.Add(t => t.UserId == user.UserId);
}
if (seatNum != -1)
{
filters.Add(t => t.AvailableSeatNumber >= seatNum);
}
if (depLocId != -1)
{
filters.Add(t => t.DepartLocationId == depLocId);
}
if (arrLocId != -1)
{
filters.Add(t => t.ArrivalLocationId == arrLocId);
}
if (hour != 0)
{
filters.Add(t => t.DepHour >= hour);
}
if (estHour != 0)
{
filters.Add(t => t.EstimatedHour < estHour);
}
if (price!= null)
{
filters.Add(t => t.Price <= price);
}
return tripRepo.GetByMultipleConditions(filters).ToList();
}