Back to Devexpress

Sample Service for Tutorial

wpf-120202-controls-and-libraries-data-grid-bind-to-data-bind-to-any-data-source-with-virtual-sources-use-virtual-sources-sample-service-for-tutorial.md

latest3.5 KB
Original Source

Sample Service for Tutorial

  • Dec 30, 2021
  • 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:

csharp
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:

csharp
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 :

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

The Issues Service allows you to apply the following filters :

csharp
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:

csharp
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 :

csharp
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:

csharp
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);
}