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 CountryList = new List(); 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 StateList = new List(); 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 SecurityQuestionList = new List(); 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); } } [Route("GetEdition")] [HttpGet] public IHttpActionResult GetEdition() { dbContext.Configuration.ProxyCreationEnabled = false; List lstEdition1 = new List(); var lstEdition = dbContext.Editions.Where(e => e.IsActive == true).OrderBy(e => e.Priority).ToList(); lstEdition1 = lstEdition.Select(l => new Edition { Id = l.Id, Title = l.Title }).ToList(); //lstCountry1.Insert(0, new Country { Id = 0, CountryName = "All" }); return Ok(lstEdition1); } [Route("GetDiscountCode")] [HttpGet] public IHttpActionResult GetDiscountCode() { dbContext.Configuration.ProxyCreationEnabled = false; List lstDiscountCode1 = new List(); string sStartDate = DateTime.MinValue.ToShortDateString(); string sEndDate = DateTime.MaxValue.ToShortDateString(); var spRecordCount = new System.Data.Objects.ObjectParameter("recordCount", 0); var lstDiscountCode = dbContext.usp_GetDiscountCodes("", "", "","Id","asc",false, 1, 1, spRecordCount).ToList(); lstDiscountCode1 = lstDiscountCode.Select(l => new usp_GetDiscountCodes_Result { Id = l.Id, DiscountCode = l.DiscountCode }).ToList(); return Ok(lstDiscountCode1); } [Route("GetAccountType")] [HttpGet] public IHttpActionResult GetAccountType() { List AccountTypeList = new List(); //try //{ AccountTypeList = AccountTypeModel.GetAccountTypes(dbContext); return Ok(AccountTypeList); //} //catch (Exception ex) //{ // // Log exception code goes here // //return 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; } } }