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("SubscriptionPrice")] public class SubscriptionPriceController : ApiController { AIADatabaseV5Entities dbContext = new AIADatabaseV5Entities(); [Route("GetSubscriptionPrices")] [HttpGet] public HttpResponseMessage GetSubscriptionPrices(int editionId, int pageNo, int pageLength) { List SubscriptionPriceList = new List(); int recordCount = 0; try { SubscriptionPriceList = SubscriptionPriceModel.GetSubscriptionPrices(dbContext, editionId, pageNo, pageLength, out recordCount); return Request.CreateResponse(HttpStatusCode.OK, new { SubscriptionPriceList = SubscriptionPriceList, RecordCount = recordCount }); } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } [Route("InsertSubscriptionPrice")] [HttpPost] public HttpResponseMessage InsertSubscriptionPrice(JObject jsonData) { bool Status = false; SubscriptionPriceModel subscriptionPriceModel = new SubscriptionPriceModel(); subscriptionPriceModel.Id = jsonData["id"].Value(); subscriptionPriceModel.Title = jsonData["title"].Value(); subscriptionPriceModel.Price = jsonData["price"].Value(); subscriptionPriceModel.Duration = jsonData["duration"].Value(); subscriptionPriceModel.EditionId = jsonData["editionId"].Value(); subscriptionPriceModel.IsActive = jsonData["isActive"].Value(); try { Status = SubscriptionPriceModel.InsertSubscriptionPrice(dbContext, subscriptionPriceModel); if (Status) { return Request.CreateResponse(HttpStatusCode.OK, Status.ToString()); } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, Status.ToString()); } } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } [Route("UpdateSubscriptionPrices")] [HttpPost] public HttpResponseMessage UpdateSubscriptionPrices(JObject jsonData) { bool Status = false; List subscriptionPriceList = new List(); SubscriptionPriceModel subscriptionPriceModel = new SubscriptionPriceModel(); for (int i = 0; i < jsonData["obj"].Count(); i++) { subscriptionPriceModel = new SubscriptionPriceModel(); subscriptionPriceModel.Id = ((Newtonsoft.Json.Linq.JValue)(jsonData["obj"][i]["Id"])).Value(); subscriptionPriceModel.Title = ((Newtonsoft.Json.Linq.JValue)(jsonData["obj"][i]["Title"])).Value(); subscriptionPriceModel.Price = ((Newtonsoft.Json.Linq.JValue)(jsonData["obj"][i]["Price"])).Value(); subscriptionPriceModel.Duration = ((Newtonsoft.Json.Linq.JValue)(jsonData["obj"][i]["Duration"])).Value(); subscriptionPriceModel.EditionId = ((Newtonsoft.Json.Linq.JValue)(jsonData["obj"][i]["EditionId"])).Value(); subscriptionPriceModel.IsActive = ((Newtonsoft.Json.Linq.JValue)(jsonData["obj"][i]["IsActive"])).Value(); subscriptionPriceList.Add(subscriptionPriceModel); } try { Status = SubscriptionPriceModel.UpdateSubscriptionPrices(dbContext, subscriptionPriceList); if (Status) { return Request.CreateResponse(HttpStatusCode.OK, Status.ToString()); } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, Status.ToString()); } } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } [Route("DeleteSubscriptionPrice")] [HttpGet] public HttpResponseMessage DeleteSubscriptionPrice(int subscriptionPriceId) { bool Status = false; try { Status = SubscriptionPriceModel.DeleteSubscriptionPrice(dbContext, subscriptionPriceId); if (Status) { return Request.CreateResponse(HttpStatusCode.OK, Status.ToString()); } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, Status.ToString()); } } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } [Route("CheckSubscriptionPlanForLicense")] [HttpGet] public HttpResponseMessage CheckSubscriptionPlanForLicense(int subscriptionPriceId) { bool Status = false; try { Status = SubscriptionPriceModel.CheckSubscriptionPlanForLicense(dbContext, subscriptionPriceId); return Request.CreateResponse(HttpStatusCode.OK, Status.ToString()); } 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; } } }