-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathEmployeesController.cs
More file actions
57 lines (56 loc) · 1.79 KB
/
EmployeesController.cs
File metadata and controls
57 lines (56 loc) · 1.79 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
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using DevExpress.ExpressApp;
using DevExtreme.AspNet.Data;
using DevExtreme.AspNet.Mvc;
using BusinessObjectsLibrary.BusinessObjects;
namespace MvcApplication.Controllers {
[Authorize]
[Route("api/[controller]")]
public class EmployeesController : Microsoft.AspNetCore.Mvc.Controller {
SecurityProvider securityProvider;
IObjectSpace objectSpace;
public EmployeesController(SecurityProvider securityProvider) {
this.securityProvider = securityProvider;
objectSpace = securityProvider.ObjectSpaceProvider.CreateObjectSpace();
}
[HttpGet]
public object Get(DataSourceLoadOptions loadOptions) {
IQueryable<Employee> employees = objectSpace.GetObjectsQuery<Employee>();
return DataSourceLoader.Load(employees, loadOptions);
}
[HttpDelete]
public ActionResult Delete(Guid key) {
Employee existing = objectSpace.GetObjectByKey<Employee>(key);
if(existing != null) {
objectSpace.Delete(existing);
objectSpace.CommitChanges();
return NoContent();
}
return NotFound();
}
[HttpPut]
public ActionResult Update(Guid key, string values) {
Employee employee = objectSpace.GetObjectByKey<Employee>(key);
if(employee != null) {
JsonParser.ParseJObject<Employee>(JObject.Parse(values), employee, objectSpace);
return Ok(employee);
}
return NotFound();
}
[HttpPost]
public ActionResult Add(string values) {
Employee employee = objectSpace.CreateObject<Employee>();
JsonParser.ParseJObject<Employee>(JObject.Parse(values), employee, objectSpace);
return Ok(employee);
}
protected override void Dispose(bool disposing) {
if(disposing) {
objectSpace?.Dispose();
securityProvider?.Dispose();
}
base.Dispose(disposing);
}
}
}