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("Api/GetSubscriptionPrices")] [HttpGet] public HttpResponseMessage GetSubscriptionPrices(int editionId, int duration) { List SubscriptionPriceList = new List(); try { SubscriptionPriceList = SubscriptionPriceModel.GetSubscriptionPrices(dbContext, editionId, duration); return Request.CreateResponse(HttpStatusCode.OK, SubscriptionPriceList); } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } [Route("Api/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("Api/UpdateSubscriptionPrice")] [HttpPost] public HttpResponseMessage UpdateSubscriptionPrice(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.UpdateSubscriptionPrice(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("Api/DeleteSubscriptionPrice")] [HttpPost] 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); } } protected HttpResponseMessage ToJson(dynamic obj) { var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/jsonP"); return response; } } }