/// <summary> /// The find persons. /// </summary> /// <param name="passport"> /// The passport. /// </param> /// <param name="sort"> /// The sort. /// </param> /// <param name="direction"> /// The direction. /// </param> /// <param name="skip"> /// The skip. /// </param> /// <returns> /// The <see cref="List"/>. /// </returns> public static List<Passport> FindPassports(Passport passport, int sort, bool direction, int skip) { List<Passport> list = new List<Passport>(); //using (var db = new PassContext()) { if (passport.Surname != string.Empty) sort = 2; // IQueryable<Passport> query = db.Passports; foreach (var item in GenerateQuery(passport, Sorting(sort, direction)).Skip(skip).Take(20).ToList()) { list.Add( new Passport { Name = item.Name, Surname = item.Surname, Address = item.Address, Birthday = item.Birthday, Patronymic = item.Patronymic, PassportNumber = item.PassportNumber, Sex = item.Sex, City = item.City, IssuedBy = item.IssuedBy, DateOfIssue = item.DateOfIssue, Code = item.Code }); } return list; } }
/// <summary> /// The post. /// </summary> /// <param name="data"> /// The data. /// </param> /// <returns> /// The <see cref="List"/>. /// </returns> public List<Passport> Post(Passport data) { List<Passport> pass = new List<Passport>(); // pass = PassportRepository.FindPersons(data); return pass; }
/// <summary> /// The generate query. /// </summary> /// <param name="passport"> /// The passport. /// </param> /// <param name="query"> /// The query. /// </param> /// <returns> /// The <see cref="IQueryable"/>. /// </returns> private static IQueryable <Passport> GenerateQuery(Passport passport, IQueryable <Passport> query) { //var db = new PassContext(); if (passport.Name != string.Empty) { query = query.Where(a => a.Name == passport.Name); } if (passport.Surname != string.Empty) { query = query.Where(a => a.Surname == passport.Surname); //query = query.Where(a=>a.Surname } if (passport.Patronymic != string.Empty) { query = query.Where(a => a.Patronymic == passport.Patronymic); } if (passport.PassportNumber != string.Empty) { query = query.Where(a => a.PassportNumber == passport.PassportNumber); } if (passport.Sex != string.Empty) { query = query.Where(a => a.Sex == passport.Sex); } if (passport.Birthday != new DateTime()) { query = query.Where(a => a.Birthday.CompareTo(passport.Birthday) == 0); } if (passport.City != string.Empty) { query = query.Where(a => a.City == passport.City); } if (passport.Address != string.Empty) { query = query.Where(a => a.Address == passport.Address); } if (passport.IssuedBy != string.Empty) { query = query.Where(a => a.IssuedBy.Contains(passport.IssuedBy)); } if (passport.DateOfIssue != new DateTime()) { query = query.Where(a => a.DateOfIssue.CompareTo(passport.DateOfIssue) == 0); } if (passport.Code != string.Empty) { query = query.Where(a => a.Code.Contains(passport.Code)); } return(query); }
/// <summary> /// The generate query. /// </summary> /// <param name="passport"> /// The passport. /// </param> /// <param name="query"> /// The query. /// </param> /// <returns> /// The <see cref="IQueryable"/>. /// </returns> private static IQueryable<Passport> GenerateQuery(Passport passport, IQueryable<Passport> query) { //var db = new PassContext(); if (passport.Name != string.Empty) { query = query.Where(a => a.Name == passport.Name); } if (passport.Surname != string.Empty) { query = query.Where(a => a.Surname == passport.Surname); //query = query.Where(a=>a.Surname } if (passport.Patronymic != string.Empty) { query = query.Where(a => a.Patronymic == passport.Patronymic); } if (passport.PassportNumber != string.Empty) { query = query.Where(a => a.PassportNumber == passport.PassportNumber); } if (passport.Sex != string.Empty) { query = query.Where(a => a.Sex == passport.Sex); } if (passport.Birthday != new DateTime()) { query = query.Where(a => a.Birthday.CompareTo(passport.Birthday) == 0); } if (passport.City != string.Empty) { query = query.Where(a => a.City == passport.City); } if (passport.Address != string.Empty) { query = query.Where(a => a.Address == passport.Address); } if (passport.IssuedBy != string.Empty) { query = query.Where(a => a.IssuedBy.Contains(passport.IssuedBy)); } if (passport.DateOfIssue != new DateTime()) { query = query.Where(a => a.DateOfIssue.CompareTo(passport.DateOfIssue) == 0); } if (passport.Code != string.Empty) { query = query.Where(a => a.Code.Contains(passport.Code)); } return query; }