public void ProcessRequest(HttpContext context)
        {
            var jsonResponse = new JsonEvent();
            if(context.Request.QueryString["EventId"] == null) {
                jsonResponse.Success = false;
                jsonResponse.ErrorMessage = "No event id provided.";
                this.Log().Error(string.Format("Event requested from {0}?{1} with no id.",
                                               context.Request.Url,
                                               context.Request.QueryString));
            } else {
                int eventId = 0;
                if(!int.TryParse(context.Request["EventId"].ToString(), out eventId)) {
                    jsonResponse.Success = false;
                    jsonResponse.ErrorMessage = "Invalid event id provided.";
                    this.Log().Error(string.Format("Requested event {0} from {1}?{2} - invalid id",
                                                   context.Request["EventId"].ToString(),
                                                   context.Request.Url,
                                                   context.Request.QueryString));
                } else {
                    DAL.Event e = new DAL.Event().FetchObject(eventId);
                    if(e == null) {
                        jsonResponse.Success = false;
                        jsonResponse.ErrorMessage = "Event not found.";
                        this.Log().Error(string.Format("Requested event {0} from {1}?{2} - not found",
                                                       eventId,
                                                       context.Request.Url,
                                                       context.Request.QueryString));
                    } else {
                        var cf = CustomEventFields.FetchObject();
                        jsonResponse.Success = true;
                        jsonResponse.Title = e.EventTitle;
                        jsonResponse.ShortDescription = e.ShortDescription;
                        jsonResponse.Description = context.Server.HtmlDecode(e.HTML);
                        jsonResponse.When = Event.DisplayEventDateTime(e);

                        if(e.BranchID > 0) {
                            var codeObject = DAL.Codes.FetchObject(e.BranchID);
                            if(codeObject != null) {
                                jsonResponse.Where = codeObject.Description;
                            }
                        }
                        if(!string.IsNullOrWhiteSpace(e.Custom1)
                           && !string.IsNullOrWhiteSpace(cf.Label1)) {
                            jsonResponse.CustomLabel1 = cf.Label1;
                            jsonResponse.CustomValue1 = e.Custom1;
                        }
                        if(!string.IsNullOrWhiteSpace(e.Custom2)
                           && !string.IsNullOrWhiteSpace(cf.Label2)) {
                            jsonResponse.CustomLabel2 = cf.Label2;
                            jsonResponse.CustomValue2 = e.Custom2;
                        }
                        if(!string.IsNullOrWhiteSpace(e.Custom3)
                           && !string.IsNullOrWhiteSpace(cf.Label3)) {
                            jsonResponse.CustomLabel3 = cf.Label3;
                            jsonResponse.CustomValue3 = e.Custom3;
                        }
                    }
                }
            }

            context.Response.ContentType = "application/json";
            var settings = new JsonSerializerSettings();
            settings.StringEscapeHandling = StringEscapeHandling.EscapeHtml;
            context.Response.Write(JsonConvert.SerializeObject(jsonResponse, settings));
        }
예제 #2
0
        public void ProcessRequest(HttpContext context)
        {
            var jsonResponse = new JsonEvent();

            if (context.Request.QueryString["EventId"] == null)
            {
                jsonResponse.Success      = false;
                jsonResponse.ErrorMessage = "No event id provided.";
                this.Log().Error(string.Format("Event requested from {0}?{1} with no id.",
                                               context.Request.Url,
                                               context.Request.QueryString));
            }
            else
            {
                int eventId = 0;
                if (!int.TryParse(context.Request["EventId"].ToString(), out eventId))
                {
                    jsonResponse.Success      = false;
                    jsonResponse.ErrorMessage = "Invalid event id provided.";
                    this.Log().Error(string.Format("Requested event {0} from {1}?{2} - invalid id",
                                                   context.Request["EventId"].ToString(),
                                                   context.Request.Url,
                                                   context.Request.QueryString));
                }
                else
                {
                    DAL.Event e = new DAL.Event().FetchObject(eventId);
                    if (e == null)
                    {
                        jsonResponse.Success      = false;
                        jsonResponse.ErrorMessage = "Event not found.";
                        this.Log().Error(string.Format("Requested event {0} from {1}?{2} - not found",
                                                       eventId,
                                                       context.Request.Url,
                                                       context.Request.QueryString));
                    }
                    else
                    {
                        var cf = CustomEventFields.FetchObject();
                        jsonResponse.Success          = true;
                        jsonResponse.Title            = e.EventTitle;
                        jsonResponse.ShortDescription = e.ShortDescription;
                        jsonResponse.Description      = e.HTML;
                        jsonResponse.When             = Event.DisplayEventDateTime(e);

                        if (e.BranchID > 0)
                        {
                            var codeObject = DAL.Codes.FetchObject(e.BranchID);
                            if (codeObject != null)
                            {
                                jsonResponse.Where = codeObject.Description;
                            }
                        }
                        if (!string.IsNullOrWhiteSpace(e.Custom1) &&
                            !string.IsNullOrWhiteSpace(cf.Label1))
                        {
                            jsonResponse.CustomLabel1 = cf.Label1;
                            jsonResponse.CustomValue1 = e.Custom1;
                        }
                        if (!string.IsNullOrWhiteSpace(e.Custom2) &&
                            !string.IsNullOrWhiteSpace(cf.Label2))
                        {
                            jsonResponse.CustomLabel2 = cf.Label2;
                            jsonResponse.CustomValue2 = e.Custom2;
                        }
                        if (!string.IsNullOrWhiteSpace(e.Custom3) &&
                            !string.IsNullOrWhiteSpace(cf.Label3))
                        {
                            jsonResponse.CustomLabel3 = cf.Label3;
                            jsonResponse.CustomValue3 = e.Custom3;
                        }
                    }
                }
            }


            context.Response.ContentType = "application/json";
            var settings = new JsonSerializerSettings();

            settings.StringEscapeHandling = StringEscapeHandling.EscapeHtml;
            context.Response.Write(JsonConvert.SerializeObject(jsonResponse, settings));
        }
        public void ProcessRequest(HttpContext context)
        {
            var jsonResponse = new JsonEvent();
            if (context.Request.QueryString["EventId"] == null)
            {
                jsonResponse.Success = false;
                jsonResponse.ErrorMessage = "No event id provided.";
                this.Log().Error(string.Format("Event requested from {0}?{1} with no id.",
                                               context.Request.Url,
                                               context.Request.QueryString));
            }
            else
            {
                int eventId = 0;
                if (!int.TryParse(context.Request["EventId"].ToString(), out eventId))
                {
                    jsonResponse.Success = false;
                    jsonResponse.ErrorMessage = "Invalid event id provided.";
                    this.Log().Error(string.Format("Requested event {0} from {1}?{2} - invalid id",
                                                   context.Request["EventId"].ToString(),
                                                   context.Request.Url,
                                                   context.Request.QueryString));
                }
                else
                {
                    DAL.Event e = new DAL.Event().FetchObject(eventId);
                    if (e == null || e.HiddenFromPublic == true)
                    {
                        jsonResponse.Success = false;
                        jsonResponse.ErrorMessage = "Event not found.";
                        this.Log().Error(string.Format("Requested event {0} from {1}?{2} - not found",
                                                       eventId,
                                                       context.Request.Url,
                                                       context.Request.QueryString));
                    }
                    else
                    {
                        var cf = CustomEventFields.FetchObject();
                        jsonResponse.Success = true;
                        jsonResponse.Title = e.EventTitle;
                        jsonResponse.ExternalLink = e.ExternalLinkToEvent;
                        jsonResponse.Description = context.Server.HtmlDecode(e.HTML);
                        jsonResponse.When = Event.DisplayEventDateTime(e);

                        if (e.BranchID > 0)
                        {
                            string branchName = string.Empty;
                            var codeObject = DAL.Codes.FetchObject(e.BranchID);
                            if (codeObject != null)
                            {
                                jsonResponse.Where = codeObject.Description;
                            }
                            var crosswalk = DAL.LibraryCrosswalk.FetchObjectByLibraryID(e.BranchID);
                            if (crosswalk != null)
                            {
                                if (!string.IsNullOrEmpty(jsonResponse.Where)
                                    && !string.IsNullOrEmpty(crosswalk.BranchLink))
                                {
                                    jsonResponse.Where = string.Format(WebTools.BranchLinkStub,
                                        crosswalk.BranchLink,
                                        jsonResponse.Where);
                                }

                                if (!string.IsNullOrEmpty(jsonResponse.Where)
                                    && !string.IsNullOrEmpty(crosswalk.BranchAddress))
                                {
                                    jsonResponse.Where += string.Format(WebTools.BranchMapStub,
                                        HttpUtility.UrlEncode(crosswalk.BranchAddress));
                                }
                            }
                        }
                        if (!string.IsNullOrWhiteSpace(e.Custom1)
                           && !string.IsNullOrWhiteSpace(cf.Label1))
                        {
                            jsonResponse.CustomLabel1 = cf.Label1;
                            jsonResponse.CustomValue1 = e.Custom1;
                        }
                        if (!string.IsNullOrWhiteSpace(e.Custom2)
                           && !string.IsNullOrWhiteSpace(cf.Label2))
                        {
                            jsonResponse.CustomLabel2 = cf.Label2;
                            jsonResponse.CustomValue2 = e.Custom2;
                        }
                        if (!string.IsNullOrWhiteSpace(e.Custom3)
                           && !string.IsNullOrWhiteSpace(cf.Label3))
                        {
                            jsonResponse.CustomLabel3 = cf.Label3;
                            jsonResponse.CustomValue3 = e.Custom3;
                        }
                    }
                }
            }


            context.Response.ContentType = "application/json";
            var settings = new JsonSerializerSettings();
            settings.StringEscapeHandling = StringEscapeHandling.EscapeHtml;
            context.Response.Write(JsonConvert.SerializeObject(jsonResponse, settings));
        }
예제 #4
0
        public void ProcessRequest(HttpContext context)
        {
            var jsonResponse = new JsonEvent();

            if (context.Request.QueryString["EventId"] == null)
            {
                jsonResponse.Success      = false;
                jsonResponse.ErrorMessage = "No event id provided.";
                this.Log().Error(string.Format("Event requested from {0}?{1} with no id.",
                                               context.Request.Url,
                                               context.Request.QueryString));
            }
            else
            {
                int eventId = 0;
                if (!int.TryParse(context.Request["EventId"].ToString(), out eventId))
                {
                    jsonResponse.Success      = false;
                    jsonResponse.ErrorMessage = "Invalid event id provided.";
                    this.Log().Error(string.Format("Requested event {0} from {1}?{2} - invalid id",
                                                   context.Request["EventId"].ToString(),
                                                   context.Request.Url,
                                                   context.Request.QueryString));
                }
                else
                {
                    DAL.Event e = new DAL.Event().FetchObject(eventId);
                    if (e == null || e.HiddenFromPublic == true)
                    {
                        jsonResponse.Success      = false;
                        jsonResponse.ErrorMessage = "Event not found.";
                        this.Log().Error(string.Format("Requested event {0} from {1}?{2} - not found",
                                                       eventId,
                                                       context.Request.Url,
                                                       context.Request.QueryString));
                    }
                    else
                    {
                        var cf = CustomEventFields.FetchObject();
                        jsonResponse.Success      = true;
                        jsonResponse.Title        = e.EventTitle;
                        jsonResponse.ExternalLink = e.ExternalLinkToEvent;
                        jsonResponse.Description  = context.Server.HtmlDecode(e.HTML);
                        jsonResponse.When         = Event.DisplayEventDateTime(e);

                        if (e.BranchID > 0)
                        {
                            string branchName = string.Empty;
                            var    codeObject = DAL.Codes.FetchObject(e.BranchID);
                            if (codeObject != null)
                            {
                                jsonResponse.Where = codeObject.Description;
                            }
                            var crosswalk = DAL.LibraryCrosswalk.FetchObjectByLibraryID(e.BranchID);
                            if (crosswalk != null)
                            {
                                if (!string.IsNullOrEmpty(jsonResponse.Where) &&
                                    !string.IsNullOrEmpty(crosswalk.BranchLink))
                                {
                                    jsonResponse.Where = string.Format(WebTools.BranchLinkStub,
                                                                       crosswalk.BranchLink,
                                                                       jsonResponse.Where);
                                }

                                if (!string.IsNullOrEmpty(jsonResponse.Where) &&
                                    !string.IsNullOrEmpty(crosswalk.BranchAddress))
                                {
                                    jsonResponse.Where += string.Format(WebTools.BranchMapStub,
                                                                        HttpUtility.UrlEncode(crosswalk.BranchAddress));
                                }
                            }
                        }
                        if (!string.IsNullOrWhiteSpace(e.Custom1) &&
                            !string.IsNullOrWhiteSpace(cf.Label1))
                        {
                            jsonResponse.CustomLabel1 = cf.Label1;
                            jsonResponse.CustomValue1 = e.Custom1;
                        }
                        if (!string.IsNullOrWhiteSpace(e.Custom2) &&
                            !string.IsNullOrWhiteSpace(cf.Label2))
                        {
                            jsonResponse.CustomLabel2 = cf.Label2;
                            jsonResponse.CustomValue2 = e.Custom2;
                        }
                        if (!string.IsNullOrWhiteSpace(e.Custom3) &&
                            !string.IsNullOrWhiteSpace(cf.Label3))
                        {
                            jsonResponse.CustomLabel3 = cf.Label3;
                            jsonResponse.CustomValue3 = e.Custom3;
                        }
                    }
                }
            }


            context.Response.ContentType = "application/json";
            var settings = new JsonSerializerSettings();

            settings.StringEscapeHandling = StringEscapeHandling.EscapeHtml;
            context.Response.Write(JsonConvert.SerializeObject(jsonResponse, settings));
        }