Whenever a user of the mobile client application initiates the synchronization process, the Tailspin Surveys service must build a list of new surveys that the user is interested in. The current version of the application uses the user’s list of preferred tenants to select the list of surveys, but Tailspin may expand the set of selection criteria in the future. The mobile client invokes the GetSurveys web method in SurveysService class to get a list of new surveys. The GetSurveys method uses the GetSurveysForUser method of the FilteringService class to get the list of surveys that it will return to the client.
The following code example shows how the FilteringService class gets the list of surveys for a user.
C#
private readonly ISurveyFilter[] filters;
…
public IEnumerable<Survey> GetSurveysForUser(
string username, DateTime fromDate)
{
return
(from filter in this.filters
from survey in filter.GetSurveys(username, fromDate)
select survey).Distinct(new SurveysComparer());
}
This method can use one or more ISurveyFilter objects to filter the list of surveys. The current version of the application uses a single filter named TenantFilter. The following code example shows the GetSurveys method of the TenantFilter class that first retrieves a list of tenants for the user, and then it retrieves a list of surveys for those tenants.
C#
public IEnumerable<Survey> GetSurveys(
string username, DateTime fromDate)
{
var tenants = this.tenantFilterStore.GetTenants(username);
if (tenants.Count() == 0)
{
tenants = this.tenantStore.GetTenants().Select(t =>
t.Name.ToLowerInvariant());
}
return
(from tenant in this.tenantFilterStore.GetTenants(username)
from survey in this.surveyStore.GetSurveys(
tenant, fromDate)
select survey).Distinct(new SurveysComparer());
}