-
Notifications
You must be signed in to change notification settings - Fork 577
Expand file tree
/
Copy pathCustomFieldsController.cs
More file actions
61 lines (50 loc) · 1.74 KB
/
Copy pathCustomFieldsController.cs
File metadata and controls
61 lines (50 loc) · 1.74 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
using BlogEngine.Core.Data.Contracts;
using BlogEngine.Core.Data.Models;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Web.Http;
public class CustomFieldsController : ApiController
{
readonly ICustomFieldRepository repository;
public CustomFieldsController(ICustomFieldRepository repository)
{
this.repository = repository;
}
public IEnumerable<CustomField> Get(string filter = "")
{
// filter example: 'CustomType == "THEME" && ObjectId == "standard"'
return repository.Find(filter);
}
public HttpResponseMessage Post([FromBody]CustomField item)
{
if (item == null) throw new ApplicationException("Custom field is required");
item.BlogId = BlogEngine.Core.Blog.CurrentInstance.Id;
if (item.CustomType == "PROFILE")
{
item.ObjectId = BlogEngine.Core.Security.CurrentUser.Identity.Name;
}
var result = repository.Add(item);
if (result == null)
return Request.CreateResponse(HttpStatusCode.NotFound);
return Request.CreateResponse(HttpStatusCode.Created, result);
}
public HttpResponseMessage Put([FromBody]List<CustomField> items)
{
if (items != null && items.Count > 0)
{
repository.ClearCustomFields(items[0].CustomType, items[0].ObjectId);
foreach (var item in items)
{
repository.Add(item);
}
}
return Request.CreateResponse(HttpStatusCode.OK);
}
public HttpResponseMessage Delete([FromBody]CustomField item)
{
repository.Remove(item.CustomType, item.ObjectId, item.Key);
return Request.CreateResponse(HttpStatusCode.OK);
}
}