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("Site")] public class SiteController : ApiController { AIADatabaseV5Entities dbContext = new AIADatabaseV5Entities(); [Route("SiteDetail")] [HttpGet] public HttpResponseMessage GetSiteById(int SiteId) { SiteModel SiteEntity = new SiteModel(); try { SiteEntity = SiteModel.GetSiteById(dbContext, SiteId); return Request.CreateResponse(HttpStatusCode.OK, SiteEntity); } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } [Route("SiteAccountEditions")] [HttpGet] public HttpResponseMessage GetSiteAccountEditions(int SiteId, int LicenseId) { List> SiteAccountEditionList = new List>(); try { SiteAccountEditionList = SiteModel.GetSiteAccountEditions(dbContext, SiteId, LicenseId); return Request.CreateResponse(HttpStatusCode.OK, SiteAccountEditionList); } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } [Route("InsertUpdateSiteAccount")] [HttpPost] public HttpResponseMessage InsertUpdateSiteAccount(JObject jsonData) { bool Status = false; SiteModel SiteEntity = new SiteModel(); SiteEntity.LicenseId = jsonData["licenseId"].Value(); SiteEntity.Id = jsonData["siteId"].Value(); SiteEntity.Title = jsonData["title"].Value(); SiteEntity.Ip = jsonData["siteUrl"].Value(); SiteEntity.SiteIpTo = jsonData["siteUrlTo"].Value(); SiteEntity.MasterIpTo = jsonData["siteMasterUrlTo"].Value(); SiteEntity.InstituteName = jsonData["institutionName"].Value(); SiteEntity.Department = jsonData["departmentName"].Value(); SiteEntity.Address1 = jsonData["address1"].Value(); SiteEntity.Address2 = jsonData["address2"].Value(); SiteEntity.City = jsonData["city"].Value(); SiteEntity.Phone = jsonData["phone"].Value(); SiteEntity.Zip = jsonData["zip"].Value(); SiteEntity.CountryId = jsonData["countryId"].Value(); SiteEntity.StateId = jsonData["stateId"].Value(); SiteEntity.SiteUserId = jsonData["userId"].Value(); SiteEntity.IsActive = jsonData["isActive"].Value(); SiteEntity.IsMaster = jsonData["isMaster"].Value(); SiteEntity.SiteEditionIds = jsonData["siteEditionIds"].Value(); SiteEntity.CreationDate = jsonData["creationDate"].Value(); SiteEntity.ModifiedDate = jsonData["modifiedDate"].Value(); try { Status = SiteModel.InsertUpdateSiteAccount(dbContext, SiteEntity); 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("DeleteSiteAccount")] [HttpGet] public HttpResponseMessage DeleteSiteAccount(int SiteId, int LicenseId, int UserId) { bool Status = false; try { Status = SiteModel.DeleteSiteAccount(dbContext, SiteId, LicenseId, UserId); 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; } } }