forked from ServiceStack/ServiceStack.Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestionsService.cs
More file actions
53 lines (45 loc) · 1.68 KB
/
Copy pathQuestionsService.cs
File metadata and controls
53 lines (45 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using RedisStackOverflow.ServiceModel;
using ServiceStack.Common.Extensions;
using ServiceStack.ServiceInterface;
namespace RedisStackOverflow.ServiceInterface
{
/// <summary>
/// Create your ServiceStack rest-ful web service implementation.
/// </summary>
public class QuestionsService : Service
{
/// <summary>
/// Gets or sets the repository. The built-in IoC used with ServiceStack autowires this property.
/// </summary>
public IRepository Repository { get; set; }
public object Get(Questions request)
{
if (!request.Tag.IsNullOrEmpty())
return new QuestionsResponse { Results = Repository.GetQuestionsTaggedWith(request.Tag) };
if (request.UserId.HasValue)
return new QuestionsResponse { Results = Repository.GetQuestionsByUser(request.UserId.Value) };
var pageOffset = request.Page.GetValueOrDefault(0) * 10;
return new QuestionsResponse { Results = Repository.GetRecentQuestionResults(pageOffset, pageOffset + 10) };
}
public object Get(Question question)
{
return new QuestionResponse {
Result = Repository.GetQuestion(question.Id),
};
}
public void Post(Question question)
{
Repository.StoreQuestion(question);
}
public void Delete(Question request)
{
Repository.DeleteQuestion(request.Id);
}
public object Post(QuestionStats request)
{
return new QuestionStatsResponse {
Result = Repository.GetQuestionStats(request.QuestionId)
};
}
}
}