public async void GetAllByGender_ValidMaleGenderCodePassed_ReturnOkObjectResult() { var filter = new PersonFilterViewModel { Gender = (int)GenderType.Male }; //Act var oKResult = await _controller.Filter(filter); //Assert Assert.IsType <OkObjectResult>(oKResult); }
public async void GetAllByGender_InvalidGenderCodePassed_ReturnBadRequestObjectResult() { //Arrange var filter = new PersonFilterViewModel { Gender = 99999 }; //Act var result = await _controller.Filter(filter); //Assert Assert.IsType <BadRequestObjectResult>(result); }
public DefaultResults <IEnumerable <PersonViewModel> > Get([FromQuery] PersonFilterViewModel filter) { var result = new DefaultResults <IEnumerable <PersonViewModel> >(); try { result.Result = _personAplicationService.GetLatestCalc(filter); result.Success = true; } catch (Exception ex) { result.Erros = new string[] { ex.Message }; } return(result); }
public async Task <IActionResult> Filter(PersonFilterViewModel filters) { try { var persons = await _personService.FilterPersons(filters); return(new OkObjectResult(persons)); } catch (Exception e) { return(BadRequest(new { message = e.Message })); } }
public async Task <List <Person> > FilterPersons(PersonFilterViewModel filters) { if (filters.Gender == null) { return(new List <Person>()); } if (Enum.IsDefined(typeof(GenderType), filters.Gender)) { var gender = (GenderType)filters.Gender; var rep = new PersonRepository(); return(rep.GetAll().Where(x => x.Gender == gender).ToList()); } else { throw new Exception("Gender not recognized"); } }
public async Task <DataTablesPagedResults <PersonListViewModel> > GetDataTableAsync(DataTablesParameters table, PersonFilterViewModel filters, Lang lng = Lang.KU) { IQueryable <Person> query = _personRepository.Table; query = query.Where(x => x.IsEmployee == filters.IsEmployee); if (!string.IsNullOrEmpty(filters.FilterString)) { var mobileWithoutZero = ""; var isNumeric = double.TryParse(filters.FilterString, out _); if (isNumeric) { if (filters.FilterString.Length > 10) { mobileWithoutZero = filters.FilterString.Substring(filters.FilterString.Length - 10); } } query = query.Where(x => x.FullName.Contains(filters.FilterString) || x.FullName_Ku.Contains(filters.FilterString) || x.FullName_Ar.Contains(filters.FilterString) || x.Mobile.Contains(filters.FilterString) || (!string.IsNullOrEmpty(mobileWithoutZero) && x.Mobile.Contains(mobileWithoutZero))); } if (filters.Gender != null) { query = query.Where(x => x.Gender == filters.Gender); } if (table.Order != null && table.Order.Any()) { var orderIndex = table.Order[0].Column; var orderDir = table.Order[0].Dir; if (orderIndex == 2) { if (orderDir == DataTablesOrderDir.DESC) { query = query.OrderByDescending(x => lng == Lang.KU ? x.FullName_Ku : lng == Lang.AR ? x.FullName_Ar : x.FullName); } else { query = query.OrderBy(x => lng == Lang.KU ? x.FullName_Ku : lng == Lang.AR ? x.FullName_Ar : x.FullName); } } else if (orderIndex == 3) { if (orderDir == DataTablesOrderDir.DESC) { query = query.OrderByDescending(x => x.Mobile); } else { query = query.OrderBy(x => x.Mobile); } } else if (orderIndex == 4) { if (orderDir == DataTablesOrderDir.DESC) { query = query.OrderByDescending(x => x.Gender); } else { query = query.OrderBy(x => x.Gender); } } else if (orderIndex == 5) { query = orderDir == DataTablesOrderDir.DESC ? query.OrderByDescending(x => x.IsEmployee) : query.OrderBy(x => x.IsEmployee); } } else { query = query.OrderBy(x => lng == Lang.KU ? x.FullName_Ku : lng == Lang.AR ? x.FullName_Ar : x.FullName); } var size = await query.CountAsync(); var items = await query .AsNoTracking() .Skip((table.Start / table.Length) * table.Length) .Take(table.Length) .Select(x => new PersonListViewModel { Id = x.Id, Name = lng == Lang.KU ? x.FullName_Ku : lng == Lang.AR ? x.FullName_Ar : x.FullName, Mobile = x.Mobile, Gender = x.Gender == Gender.Male ? AN.Core.Resources.Global.Global.Male : AN.Core.Resources.Global.Global.FeMale, IsEmployee = x.IsEmployee ? AN.Core.Resources.Global.Global.Yes : AN.Core.Resources.Global.Global.No, Avatar = x.RealAvatar }) .ToListAsync(); return(new DataTablesPagedResults <PersonListViewModel> { Items = items, TotalSize = size }); }
// GET: People public async Task <IActionResult> Index(string personFirstName, string personSurname, string personLegalSurname, string personDoB, string searchString) { // Use LINQ to get list of first names, surnames, legal surnames, and date of birth from the database. //--------------------------------------------------------------------------- var deleteCurrentResults = _context.Results.ToList(); foreach (var item in deleteCurrentResults) { _context.Results.Remove(item); } var personFilterVM = new PersonFilterViewModel(); //person one's matching var people = from p in _context.Person select p; var peopletwo = from p in _context.PersonTwo select p; var result = from p in _context.Results select p; if (personFirstName == "1" && personSurname == null && personLegalSurname == null && personDoB == null) { var compareFirstNameP1 = from p1 in _context.Person from p2 in _context.PersonTwo where p1.FirstName == p2.FirstName select(p1); var compareFirstNameP2 = from p1 in _context.Person from p2 in _context.PersonTwo where p1.FirstName == p2.FirstName select(p2); personFilterVM.people = compareFirstNameP1.ToList(); personFilterVM.peopletwo = compareFirstNameP2.ToList(); foreach (var item in compareFirstNameP1.ToList()) { var results = new Results { FirstName = item.FirstName, Surname = item.Surname, LegalSurname = item.LegalSurname, DateOfBirth = item.DateOfBirth }; _context.Results.Add(results); } foreach (var item in compareFirstNameP2.ToList()) { var results = new Results { FirstName = item.FirstName, Surname = item.Surname, LegalSurname = item.LegalSurname, DateOfBirth = item.DateOfBirth }; _context.Results.Add(results); } await _context.SaveChangesAsync(); var resultsList = _context.Results.ToList(); personFilterVM.results = resultsList; } else if (personFirstName == null && personSurname == "2" && personLegalSurname == null && personDoB == null) { var compareSurnameP1 = from p1 in _context.Person from p2 in _context.PersonTwo where p1.Surname == p2.Surname select(p1); var compareSurnameP2 = from p1 in _context.Person from p2 in _context.PersonTwo where p1.Surname == p2.Surname select(p2); personFilterVM.people = compareSurnameP1.ToList(); personFilterVM.peopletwo = compareSurnameP2.ToList(); foreach (var item in compareSurnameP1.ToList()) { var results = new Results { FirstName = item.FirstName, Surname = item.Surname, LegalSurname = item.LegalSurname, DateOfBirth = item.DateOfBirth }; _context.Results.Add(results); } foreach (var item in compareSurnameP2.ToList()) { var results = new Results { FirstName = item.FirstName, Surname = item.Surname, LegalSurname = item.LegalSurname, DateOfBirth = item.DateOfBirth }; _context.Results.Add(results); } await _context.SaveChangesAsync(); var resultsList = _context.Results.ToList(); personFilterVM.results = resultsList; } else if (personFirstName == null && personSurname == null && personLegalSurname == "3" && personDoB == null) { var compareLegalSurnameP1 = from p1 in _context.Person from p2 in _context.PersonTwo where p1.LegalSurname == p2.LegalSurname select(p1); var compareLegalSurnameP2 = from p1 in _context.Person from p2 in _context.PersonTwo where p1.LegalSurname == p2.LegalSurname select(p2); personFilterVM.people = compareLegalSurnameP1.ToList(); personFilterVM.peopletwo = compareLegalSurnameP2.ToList(); foreach (var item in compareLegalSurnameP1.ToList()) { var results = new Results { FirstName = item.FirstName, Surname = item.Surname, LegalSurname = item.LegalSurname, DateOfBirth = item.DateOfBirth }; _context.Results.Add(results); } foreach (var item in compareLegalSurnameP2.ToList()) { var results = new Results { FirstName = item.FirstName, Surname = item.Surname, LegalSurname = item.LegalSurname, DateOfBirth = item.DateOfBirth }; _context.Results.Add(results); } await _context.SaveChangesAsync(); var resultsList = _context.Results.ToList(); personFilterVM.results = resultsList; } else if (personFirstName == null && personSurname == null && personLegalSurname == null && personDoB == "4") { var compareDateOfBirthP1 = from p1 in _context.Person from p2 in _context.PersonTwo where p1.DateOfBirth == p2.DateOfBirth select(p1); var compareDateOfBirthP2 = from p1 in _context.Person from p2 in _context.PersonTwo where p1.DateOfBirth == p2.DateOfBirth select(p2); personFilterVM.people = compareDateOfBirthP1.ToList(); personFilterVM.peopletwo = compareDateOfBirthP2.ToList(); foreach (var item in compareDateOfBirthP1.ToList()) { var results = new Results { FirstName = item.FirstName, Surname = item.Surname, LegalSurname = item.LegalSurname, DateOfBirth = item.DateOfBirth }; _context.Results.Add(results); } foreach (var item in compareDateOfBirthP2.ToList()) { var results = new Results { FirstName = item.FirstName, Surname = item.Surname, LegalSurname = item.LegalSurname, DateOfBirth = item.DateOfBirth }; _context.Results.Add(results); } await _context.SaveChangesAsync(); var resultsList = _context.Results.ToList(); personFilterVM.results = resultsList; } else if (personFirstName == "1" && personSurname == "2" && personLegalSurname == null && personDoB == null) { var compareFirstNAndLNameP1 = from p1 in _context.Person from p2 in _context.PersonTwo where p1.FirstName == p2.FirstName && p1.Surname == p2.Surname select(p1); var compareFirstNAndLNameP2 = from p1 in _context.Person from p2 in _context.PersonTwo where p1.FirstName == p2.FirstName && p1.Surname == p2.Surname select(p2); personFilterVM.people = compareFirstNAndLNameP1.ToList(); personFilterVM.peopletwo = compareFirstNAndLNameP2.ToList(); foreach (var item in compareFirstNAndLNameP1.ToList()) { var results = new Results { FirstName = item.FirstName, Surname = item.Surname, LegalSurname = item.LegalSurname, DateOfBirth = item.DateOfBirth }; _context.Results.Add(results); } foreach (var item in compareFirstNAndLNameP2.ToList()) { var results = new Results { FirstName = item.FirstName, Surname = item.Surname, LegalSurname = item.LegalSurname, DateOfBirth = item.DateOfBirth }; _context.Results.Add(results); } await _context.SaveChangesAsync(); var resultsList = _context.Results.ToList(); personFilterVM.results = resultsList; } else if (personFirstName == "1" && personSurname == "2" && personLegalSurname == "3" && personDoB == null) { var compareFnameLnameAndLSurnameP1 = from p1 in _context.Person from p2 in _context.PersonTwo where p1.FirstName == p2.FirstName && p1.Surname == p2.Surname && p1.LegalSurname == p2.LegalSurname select(p1); var compareFnameLnameAndLSurnameP2 = from p1 in _context.Person from p2 in _context.PersonTwo where p1.FirstName == p2.FirstName && p1.Surname == p2.Surname && p1.LegalSurname == p2.LegalSurname select(p2); personFilterVM.people = compareFnameLnameAndLSurnameP1.ToList(); personFilterVM.peopletwo = compareFnameLnameAndLSurnameP2.ToList(); foreach (var item in compareFnameLnameAndLSurnameP1.ToList()) { var results = new Results { FirstName = item.FirstName, Surname = item.Surname, LegalSurname = item.LegalSurname, DateOfBirth = item.DateOfBirth }; _context.Results.Add(results); } foreach (var item in compareFnameLnameAndLSurnameP2.ToList()) { var results = new Results { FirstName = item.FirstName, Surname = item.Surname, LegalSurname = item.LegalSurname, DateOfBirth = item.DateOfBirth }; _context.Results.Add(results); } await _context.SaveChangesAsync(); var resultsList = _context.Results.ToList(); personFilterVM.results = resultsList; } else if (personFirstName == "1" && personSurname == "2" && personLegalSurname == "3" && personDoB == "4") { var compareP1All = from p1 in _context.Person from p2 in _context.PersonTwo where p1.FirstName == p2.FirstName && p1.Surname == p2.Surname && p1.LegalSurname == p2.LegalSurname && p1.DateOfBirth == p2.DateOfBirth select(p1); var compareP2All = from p1 in _context.Person from p2 in _context.PersonTwo where p1.FirstName == p2.FirstName && p1.Surname == p2.Surname && p1.LegalSurname == p2.LegalSurname && p1.DateOfBirth == p2.DateOfBirth select(p2); personFilterVM.people = compareP1All.ToList(); personFilterVM.peopletwo = compareP2All.ToList(); foreach (var item in compareP1All.ToList()) { var results = new Results { FirstName = item.FirstName, Surname = item.Surname, LegalSurname = item.LegalSurname, DateOfBirth = item.DateOfBirth }; _context.Results.Add(results); } await _context.SaveChangesAsync(); var resultsList = _context.Results.ToList(); personFilterVM.results = resultsList; } else { personFilterVM.peopletwo = await peopletwo.ToListAsync(); personFilterVM.people = await people.ToListAsync(); } return(View(personFilterVM)); }