CommonController.cs
2.72 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using AIAHTML5.ADMIN.API.Models;
using System.Web.Http.Cors;
using System.Web.Cors;
using AIAHTML5.Server.Constants;
using log4net;
using System.Text;
using AIAHTML5.ADMIN.API.Entity;
namespace AIAHTML5.ADMIN.API.Controllers
{
[EnableCors(origins: "http://localhost:4200", headers: "*", methods: "*")]
[RoutePrefix("Common")]
public class CommonController : ApiController
{
AIADatabaseV5Entities dbContext = new AIADatabaseV5Entities();
[Route("Countries")]
[HttpGet]
public HttpResponseMessage GetCountries()
{
List<CountryModel> CountryList = new List<CountryModel>();
try
{
CountryList = CountryModel.GetCountries(dbContext);
return Request.CreateResponse(HttpStatusCode.OK, CountryList);
}
catch (Exception ex)
{
// Log exception code goes here
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
[Route("States")]
[HttpGet]
public HttpResponseMessage GetUsStates()
{
List<StateModel> StateList = new List<StateModel>();
try
{
StateList = StateModel.GetUsStates(dbContext);
return Request.CreateResponse(HttpStatusCode.OK, StateList);
}
catch (Exception ex)
{
// Log exception code goes here
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
[Route("SecurityQuestions")]
[HttpGet]
public HttpResponseMessage GetSecurityQuestions()
{
List<SecurityQuestionModel> SecurityQuestionList = new List<SecurityQuestionModel>();
try
{
SecurityQuestionList = SecurityQuestionModel.GetSecurityQuestions(dbContext);
return Request.CreateResponse(HttpStatusCode.OK, SecurityQuestionList);
}
catch (Exception ex)
{
// Log exception code goes here
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
protected HttpResponseMessage ToJson(dynamic obj)
{
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/jsonP");
return response;
}
}
}