Sample Service for Tutorial

  • 2 minutes to read

This topic describes the Issues Service. This service is used as a sample data source in this tutorial. Its API is similar to the StackExchange Questions API.

Overview

The Issues Service is a static class:

public static class IssuesService {
    public async static Task<IssueData[]> GetIssuesAsync(int skip, int take, IssueSortOrder sortOrder, IssueFilter filter);
    public async static Task<UserData[]> GetUsersAsync();
    public async static Task<IssuesSummaries> GetSummariesAsync(IssueFilter filter);
    public async static Task UpdateRowAsync(IssueData row);
}

GetIssuesAsync Method

The GetIssuesAsync method returns a task that allows you to get a page with the following data:

public class IssueData {
    public int Id { get; private set; }
    public string Subject { get; set; }
    public int UserId { get; set; }
    public DateTime Created { get; set; }
    public int Votes { get; set; }
    public Priority Priority { get; set; }
}

The Issues Service allows you to apply the following sort orders:

public enum IssueSortOrder {
    Default,
    CreatedDescending,
    VotesAscending,
    VotesDescending,
}

The Issues Service allows you to apply the following filters:

public class IssueFilter {
    public Priority? Priority { get; private set; }
    public DateTime? CreatedFrom { get; private set; }
    public DateTime? CreatedTo { get; private set; }
    public int? MinVotes { get; private set; }
}

GetUsersAsync Method

The GetUsersAsync method returns a task that allows you to get a collection of users:

public class UserData {
    public int Id { get; }
    public string FirstName { get; }
    public string LastName { get; }
    public string FullName => FirstName + " " + LastName;
}

GetSummariesAsync Method

The GetSummariesAsync method returns a task that allows you to get the total count of rows and the last created object’s datetime:

public class IssuesSummaries {   
    public int Count { get; private set; }
    public DateTime? LastCreated { get; private set; }
}

UpdateRowAsync Method

The UpdateRowAsync method returns a task that allows you to commit changes to the data source.

Miscellaneous

The GridControl displays a loading indicator during fetch operations because the Issues Service returns data with a short time delay:

VirtualSourcesLoadingPanel

public async static Task<IssueData[]> GetIssuesAsync(int skip, int take, IssueSortOrder sortOrder, IssueFilter filter) {
    await Task.Delay(300).ConfigureAwait(false);
    // ...
}
public async static Task<UserData[]> GetUsersAsync() {
    await Task.Delay(300).ConfigureAwait(false);
    // ...
}
public async static Task<IssuesSummaries> GetSummariesAsync(IssueFilter filter) {
    await Task.Delay(300).ConfigureAwait(false);
    // ...
}
public async static Task UpdateRowAsync(IssueData row) {
    // ...
    await Task.Delay(500).ConfigureAwait(false);
}