public ActionResult CalendarEvents(int? year, int? month)
        {
            try
            {
                //we shouldn't be looking at any dates less than 2012. or greater than 2100
                if (year != null && year.Value < 2012)
                    year = null;
                else if (year != null && year.Value > 2100)
                    year = null;
                EventsOutModel mod = new EventsOutModel();
                int day = 1;
                if (DateTime.UtcNow.Day > 28)
                    day = 28;
                else if (DateTime.UtcNow.Day == 1)
                    day = 1;
                else
                    day = DateTime.UtcNow.AddDays(-1).Day;
                if (year != null && month != null)
                    mod.StartDate = new DateTime(year.Value, month.Value, day);
                else
                    mod.StartDate = DateTime.UtcNow.AddDays(-1);
                mod.EndDate = mod.StartDate.AddDays(30);

                mod.Events = SiteCache.GetCalendarEvents(mod.StartDate, mod.EndDate);

                return View(mod);
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
        }
Пример #2
0
        public static List<CalendarEvent> GetCalendarEvents(DateTime start, int page, int take)
        {
            try
            {
                var cached = GetCache(HttpContext.Current.Cache);
                EventsOutModel mod = new EventsOutModel();
                mod.StartDate = start;
                mod.EndDate = start.AddMonths(4);
                if (cached.CalendarEventsModel.StartDate < mod.StartDate && cached.CalendarEventsModel.EndDate > mod.EndDate)
                    return cached.CalendarEventsModel.Events.Where(x => x.StartDate > mod.StartDate && x.EndDate < mod.EndDate).Where(x => x.Name != null).OrderBy(x => x.StartDate).Skip(page * take).Take(take).ToList();
                else
                {
                    if (cached.CalendarEventsModel.StartDate == new DateTime() || cached.CalendarEventsModel.StartDate > mod.StartDate)
                        cached.CalendarEventsModel.StartDate = mod.StartDate;
                    if (cached.CalendarEventsModel.EndDate == new DateTime() || cached.CalendarEventsModel.EndDate < mod.EndDate)
                        cached.CalendarEventsModel.EndDate = mod.EndDate;
                    mod.Events = CalendarEventFactory.GetPublicEvents(cached.CalendarEventsModel.StartDate, cached.CalendarEventsModel.EndDate, new Guid(), false);
                    cached.CalendarEventsModel.Events = mod.Events;
                    UpdateCache(cached);
                    return cached.CalendarEventsModel.Events.Where(x => x.StartDate > mod.StartDate && x.EndDate < mod.EndDate).Where(x => x.Name != null).OrderBy(x => x.StartDate).Skip(page * take).Take(take).ToList();
                }

            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return new List<CalendarEvent>();
        }
Пример #3
0
        public static List<CalendarEvent> SearchCalendarEvents(DateTime start, double longitude, double latitude, int page, int take)
        {
            try
            {
                var cached = GetCache(HttpContext.Current.Cache);

                EventsOutModel mod = new EventsOutModel();
                mod.StartDate = start;
                mod.EndDate = start.AddMonths(4);
                if (cached.CalendarEventsModel.StartDate < mod.StartDate && cached.CalendarEventsModel.EndDate > mod.EndDate)
                {
                    var coord = new RDN.Portable.Classes.Location.GeoCoordinate(latitude, longitude);
                    var nearest = cached.CalendarEventsModel.Events.Where(x => x.Location.Contact.Addresses.Count > 0).OrderBy(x => x.Location.Contact.Addresses.FirstOrDefault().Coords.GetDistanceTo(coord)).ToList();
                }
                else
                {
                    if (cached.CalendarEventsModel.StartDate == new DateTime() || cached.CalendarEventsModel.StartDate > mod.StartDate)
                        cached.CalendarEventsModel.StartDate = mod.StartDate;
                    if (cached.CalendarEventsModel.EndDate == new DateTime() || cached.CalendarEventsModel.EndDate < mod.EndDate)
                        cached.CalendarEventsModel.EndDate = mod.EndDate;
                    mod.Events = CalendarEventFactory.GetPublicEvents(cached.CalendarEventsModel.StartDate, cached.CalendarEventsModel.EndDate, new Guid(), false);
                    cached.CalendarEventsModel.Events = mod.Events;
                    UpdateCache(cached);
                    var coord = new RDN.Portable.Classes.Location.GeoCoordinate(latitude, longitude);
                    var nearest = cached.CalendarEventsModel.Events.Where(x => x.Location.Contact.Addresses.Count > 0).OrderBy(x => x.Location.Contact.Addresses.FirstOrDefault().Coords.GetDistanceTo(coord)).Skip(page * take).Take(take).ToList();

                    return nearest;
                }

            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return new List<CalendarEvent>();
        }