This repository has been archived by the owner on Mar 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
TodoListController.cs
59 lines (52 loc) · 2.15 KB
/
TodoListController.cs
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
55
56
57
58
59
//----------------------------------------------------------------------------------------------
// Copyright 2014 Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//----------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
// The following using statements were added for this sample.
using System.Collections.Concurrent;
using TodoListService.Models;
using System.Security.Claims;
namespace TodoListService.Controllers
{
[Authorize]
public class TodoListController : ApiController
{
static ConcurrentBag<TodoItem> todoBag = new ConcurrentBag<TodoItem>();
// GET api/todolist
public IEnumerable<TodoItem> Get()
{
// You can use the ClaimsPrincipal to access information about the
// user making the call. In this case, we use the 'sub' or
// NameIdentifier claim to serve as a key for the tasks in the data store.
Claim subject = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier);
return from todo in todoBag
where todo.Owner == subject.Value
select todo;
}
// POST api/todolist
public void Post(TodoItem todo)
{
if (null != todo && !string.IsNullOrWhiteSpace(todo.Title))
{
todoBag.Add(new TodoItem { Title = todo.Title, Owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value });
}
}
}
}