// Returns the queryable object to the DB. private static IQueryable <Person> getQueryable( DbRequest dbRequest, PersonDataContext dataContext) { var query = dataContext.Persons.AsQueryable(); if (dbRequest.ForceMe && CurrentMisparIshi.GetCurrentMisparIshi().Length > 0) { query = query.Where(person => person.MisparIshi == CurrentMisparIshi.GetCurrentMisparIshi()); return(query); } if (dbRequest.Tags > 1) { query = query.Where(person => person.Tags % dbRequest.Tags == 0); } if (dbRequest.StandardInputTextValues.Count != 0) { // Note that WhereMatches is defined in WhereMatchesQuery.cs. query = query.WhereMatches( dbRequest.StandardInputTextValues, dbRequest.IsOnlyNumbers); } return(query); }
private static IEnumerable <PersonFromDbWrapper> search( DbRequest dbRequest, PersonDataContext dataContext) { return(getQueryable(dbRequest, dataContext) .Take(dbRequest.NumberToTake) .Select(person => new PersonFromDbWrapper( person.MisparIshi, person.GivenName, person.Surname, person.Mail, person.Mobile, person.JobTitle, person.WorkPhone, person.OtherTelephone, person.Fax, person.HomeTelephone, person.LongWorkTitle, person.Picture, person.BirthdayDisplayString, person.Darga, person.Sex, person.Tags, person.WhatIDo)) .ToList()); }
// (1) Validate the query and return an empty list if the query is invalid. // (2) Convert the input query to a SQL query. // (3) Post-process each SQL output to convert it to the JSON the client // expects. // (4) Return a list containing a Metadata object and the list of JSON // objects for each person. public IEnumerable <object> GetPersons( string inputMaybeInEnglish, bool shouldShowAll, bool forceMe = false) { var input = EnglishToHebrew.maybeConvertToHebrew(inputMaybeInEnglish); var timer = new Timer(input, shouldShowAll); var dbRequest = new DbRequest(input, shouldShowAll, forceMe); // If we could not crate a valid DB request, get out of here. if (!dbRequest.IsValid) { return(new object[] { }); } // Generate the list of people and the metadata. var allMatchingPersons = createMatchingPersonsList(dbRequest); var metadataObject = createMetadataObject(input, allMatchingPersons, dbRequest); // Push them both into a nice list which we will return. var returnObjects = new List <object> { metadataObject }; returnObjects.AddRange(allMatchingPersons.Take(dbRequest.NumberToShow)); timer.Stop(); return(returnObjects); }
// Retrieves the matching people form the Database and wraps each one in a // PersonFromDbWrapper object. public static IEnumerable <PersonFromDbWrapper> GetPersonsFromDb( DbRequest dbRequest) { var dataContext = new PersonDataContext(); dataContext.Log = new DebugWriter(); // Toggle comment to log SQL. return(search(dbRequest, dataContext)); }
private List <object> createMatchingPersonsList(DbRequest dbRequest) { // Post process the selected entities; adjusting and renaming some fields. return(DbReader.GetPersonsFromDb(dbRequest) .Select(person => new PersonJsonConstructor(person)) .OrderByDescending(person => person.IsMe) .ThenByDescending(person => person.MailFirstCharacter) .ThenBy(person => person.Name) .Select(person => person.JsonFromClient) .ToList()); }
private object createMetadataObject(string input, IEnumerable <object> persons, DbRequest dbRequest) { // We requested more than we will show as a means to know if // the list was cut off. var listWasCutOff = persons.Count() > dbRequest.NumberToShow; return(new { query = input, shouldShowSeeMore = listWasCutOff }); }