public JsonResult GetEvents(string title, string description, DateTime startTime, DateTime endTime, string visibilityTypeString, string locationName, double latitude, double longitude)
 {
     QueryEventModel qem = new QueryEventModel();
     qem.Description = description;
     qem.EndTime = endTime;
     qem.StartTime = startTime;
     qem.Title = title;
     return Json(eventServices.QueryEvents(qem));
 }
        public override bool Execute()
        {
            QueryEventModel qem = new QueryEventModel();
            qem.Title = random.Next(1, 100)+"";
            qem.Description = random.Next(1, 100) + "";

            IEnumerable<EventModel> results = eventServices.QueryEvents(qem);
            Console.WriteLine("Results of event search:");

            foreach (EventModel evt in results)
            {
                Console.WriteLine("\t{0} {1}\n", evt.Title, evt.Description);
            }

            return true;
        }
        public IEnumerable<EventModel> QueryEvents(QueryEventModel queryModel)
        {
            IEnumerable<Event> titleMatches;
            titleMatches = db.Events.Where(x => queryModel.Title != null ? x.Title.Equals(queryModel.Title, StringComparison.CurrentCultureIgnoreCase) : true);

            IEnumerable<Event> descriptionMatches;
            descriptionMatches = db.Events.Where(x => queryModel.Description != null ? x.Description.Contains(queryModel.Description) : true);

            IEnumerable<Event> startTimeMatches = null;
            IEnumerable<Event> endTimeMatches = null;
            if (queryModel.DateSearch)
            {

                startTimeMatches = db.Events.Where(x => queryModel.StartTime != null ? x.StartTime >= queryModel.StartTime : true);

                endTimeMatches = db.Events.Where(x => queryModel.EndTime != null ? x.EndTime <= queryModel.EndTime : true);
            }
            //IEnumerable<Event> locationMatches;
            //locationMatches = db.Events.Where(x => x.Location != null ? Utilities.AreWithinRadius(x.Location, queryModel.Location, 0.1) : true);

            IEnumerable<Event> result = titleMatches;
            result = result.Union(descriptionMatches);
            if (startTimeMatches != null)
            {
                result = result.Union(startTimeMatches);
            }

            if (endTimeMatches != null)
            {
                result = result.Union(endTimeMatches);
            }

            List<EventModel> eventModels = new List<EventModel>();
            EventModel evtModel = null;

            foreach (Event evt in result)
            {
                evtModel = Utilities.EventToEventModel(evt);
                eventModels.Add(evtModel);
            }

            return eventModels.AsQueryable();
        }