-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy pathUserService.cs
More file actions
54 lines (48 loc) · 1.66 KB
/
Copy pathUserService.cs
File metadata and controls
54 lines (48 loc) · 1.66 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
54
using RedisStackOverflow.ServiceModel;
using ServiceStack.ServiceInterface;
namespace RedisStackOverflow.ServiceInterface
{
/// <summary>
/// Create your ServiceStack rest-ful web service implementation.
/// </summary>
public class UserService : Service
{
/// <summary>
/// Gets or sets the repository. The built-in IoC used with ServiceStack autowires this property.
/// </summary>
public IRepository Repository { get; set; }
public UserResponse Post(User request)
{
return new UserResponse
{
Result = Repository.GetOrCreateUser(request),
};
}
public object Get(UserStats request)
{
return new UserStatsResponse {
Result = Repository.GetUserStats(request.UserId)
};
}
public object Post(UserVotes request)
{
var direction = request.Direction ?? "up";
var voteUp = direction.ToLower() != "down";
if (request.QuestionId.HasValue)
{
if (voteUp)
Repository.VoteQuestionUp(request.UserId, request.QuestionId.Value);
else
Repository.VoteQuestionDown(request.UserId, request.QuestionId.Value);
}
else if (request.AnswerId.HasValue)
{
if (voteUp)
Repository.VoteAnswerUp(request.UserId, request.AnswerId.Value);
else
Repository.VoteAnswerDown(request.UserId, request.AnswerId.Value);
}
return new UserVotesResponse();
}
}
}