-
Notifications
You must be signed in to change notification settings - Fork 577
Expand file tree
/
Copy pathPingServicesController.cs
More file actions
63 lines (54 loc) · 1.59 KB
/
Copy pathPingServicesController.cs
File metadata and controls
63 lines (54 loc) · 1.59 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
55
56
57
58
59
60
61
62
63
using BlogEngine.Core.Providers;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Web.Http;
public class PingServicesController : ApiController
{
public IEnumerable<PingItem> Get()
{
var pings = new List<PingItem>();
foreach (var s in BlogService.LoadPingServices())
{
pings.Add(new PingItem { IsChecked = false, ServiceUrl = s });
}
return pings;
}
public HttpResponseMessage Post([FromBody]PingItem item)
{
var sc = BlogService.LoadPingServices();
if (!sc.Contains(item.ServiceUrl))
{
sc.Add(item.ServiceUrl);
}
BlogService.SavePingServices(sc);
var pings = new List<PingItem>();
foreach (var s in sc)
{
pings.Add(new PingItem { IsChecked = false, ServiceUrl = s });
}
return Request.CreateResponse(HttpStatusCode.Created, pings);
}
[HttpPut]
public HttpResponseMessage ProcessChecked([FromBody]List<PingItem> items)
{
if (items == null || items.Count == 0)
throw new HttpResponseException(HttpStatusCode.ExpectationFailed);
var sc = BlogService.LoadPingServices();
foreach (var item in items)
{
if (item.IsChecked)
{
sc.Remove(item.ServiceUrl);
}
}
BlogService.SavePingServices(sc);
return Request.CreateResponse(HttpStatusCode.OK);
}
}
public class PingItem
{
public bool IsChecked { get; set; }
public string ServiceUrl { get; set; }
}