public ActionResult EventFilter(FormCollection formCollection)
 {
     try
     {
         string guid        = Guid.NewGuid().ToString();
         string filterValue = CreateFilterXml(formCollection);
         using (EventOrganizerEntities db = new EventOrganizerEntities())
         {
             ObjectParameter guidOutput = new ObjectParameter("Guid", typeof(string));
             guidOutput.Value = guid;
             db.usp_AddEventFilter(filterValue, guidOutput);
             guid = Convert.ToString(guidOutput.Value);
         }
         using (EventOrganizerEntities db = new EventOrganizerEntities())
         {
             List <CalendarEvent> calendarEvents = db.usp_GetEventsByGuid(guid).ToList();
             if (calendarEvents == null || calendarEvents.Count == 0)
             {
                 return(Content("No event is associated with your filter criteria. Please try different filter settings.,0"));
             }
         }
         //guid changed to base 64 encrypted string
         guid = Extensions.EncodeTo64(guid);
         ViewData["eventUrl"] = HttpContext.Request.Url.ToString().Replace("EventFilter", "DownloadEvent/") + guid;
         return(Content("Your filter has been applied, please download the calendar event!," + HttpContext.Request.Url.ToString().Replace("EventFilter", "DownloadEvent/") + guid));
     }
     catch (Exception)
     {
         return(Content("There is problem while working on filter. Please try again."));
     }
 }
 /// <summary>
 /// ics file download
 /// </summary>
 /// <param name="guid"></param>
 private void Download(string guid)
 {
     if (!string.IsNullOrEmpty(guid))
     {
         List <CalendarEvent> calendarEvents;
         using (EventOrganizerEntities db = new EventOrganizerEntities())
         {
             calendarEvents = db.usp_GetEventsByGuid(Extensions.DecodeFrom64(guid)).ToList();
         }
         string fileName = Guid.NewGuid().ToString() + ".ics";
         Response.Write("BEGIN:VCALENDAR" + Environment.NewLine);
         Response.Write("VERSION:2.0" + Environment.NewLine);
         Response.Write("PRODID: -//ScheduleOnce//EN" + Environment.NewLine);
         Response.Write("METHOD:PUBLISH" + Environment.NewLine);
         Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
         StringBuilder eventInICSFormat = new StringBuilder();
         foreach (CalendarEvent calEvent in calendarEvents)
         {
             eventInICSFormat.Append("BEGIN:VEVENT" + Environment.NewLine);
             eventInICSFormat.Append("DTEND:" + (calEvent.EndDate.ToString("s").Replace("-", "").Replace(":", "")) + Environment.NewLine);
             eventInICSFormat.Append("DTSTART:" + calEvent.StartDate.ToString("s").Replace("-", "").Replace(":", "") + Environment.NewLine);
             StringBuilder eventDescription = new StringBuilder();
             if (!string.IsNullOrWhiteSpace(calEvent.Abstract))
             {
                 eventDescription.Append(calEvent.Abstract + "\\n");
             }
             if (!string.IsNullOrWhiteSpace(calEvent.EventDescription))
             {
                 eventDescription.Append("Event Details : " + calEvent.EventDescription.Replace(Environment.NewLine, "\\n") + "\\n");
             }
             if (!string.IsNullOrWhiteSpace(calEvent.Url))
             {
                 eventDescription.Append("Url : " + calEvent.Url + "\\n");
             }
             if (calEvent.Price.HasValue)
             {
                 eventDescription.Append("Price : " + calEvent.Price.Value.ToString());
             }
             eventInICSFormat.Append("DESCRIPTION:" + eventDescription.ToString() + Environment.NewLine);
             eventInICSFormat.Append("LOCATION:" + calEvent.Location + Environment.NewLine);
             eventInICSFormat.Append("PRIORITY:5" + Environment.NewLine);
             eventInICSFormat.Append("SEQUENCE:0" + Environment.NewLine);
             eventInICSFormat.Append("SUMMARY;LANGUAGE=en-us:" + calEvent.EventTitle + Environment.NewLine);
             eventInICSFormat.Append("TRANSP:OPAQUE" + Environment.NewLine);
             eventInICSFormat.Append(string.Format("UID:{0}", Guid.NewGuid().ToString().ToUpper()) + Environment.NewLine);
             eventInICSFormat.Append("BEGIN:VALARM" + Environment.NewLine);
             eventInICSFormat.Append("TRIGGER:-PT15M" + Environment.NewLine);
             eventInICSFormat.Append("ACTION:DISPLAY" + Environment.NewLine);
             eventInICSFormat.Append("DESCRIPTION:Reminder" + Environment.NewLine);
             eventInICSFormat.Append("END:VALARM" + Environment.NewLine);
             eventInICSFormat.Append("END:VEVENT" + Environment.NewLine);
         }
         eventInICSFormat.Append("END:VCALENDAR" + Environment.NewLine);
         Response.Write(eventInICSFormat);
         Response.End();
     }
 }