void PullDues() { Dispatcher.BeginInvoke(delegate { progressIndicator.IsVisible = true; }); try { Task.Run(new Action(() => { calendarModel = CalendarMobile.GetCalendarEvents(SettingsMobile.Instance.User.MemberId, SettingsMobile.Instance.User.LoginId, SettingsMobile.Instance.AccountSettings.CalendarId, CalendarOwnerEntityEnum.league, DateTime.UtcNow.Year, DateTime.UtcNow.Month); Dispatcher.BeginInvoke(delegate { EventList.ItemsSource = calendarModel.Events; progressIndicator.IsVisible = false; }); })); } catch (Exception exception) { ErrorHandler.Save(exception, MobileTypeEnum.WP8); } }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); try { calendarModel = new Portable.Classes.Controls.Calendar.Calendar(); //(App.Current as App).SecondPageObject = null; progressIndicator = SystemTray.ProgressIndicator; progressIndicator = new ProgressIndicator(); SystemTray.SetProgressIndicator(this, progressIndicator); progressIndicator.IsIndeterminate = true; progressIndicator.Text = "Pulling Events..."; if (SettingsMobile.Instance.User == null) { SqlFactory fact = new SqlFactory(); SettingsMobile.Instance.User = fact.GetProfile(); } if (SettingsMobile.Instance.AccountSettings.IsEventsCoordinatorOrBetter) { ApplicationBar.IsVisible = true; } PullDues(); } catch (Exception exception) { ErrorHandler.Save(exception, MobileTypeEnum.WP8); } }
public ActionResult LoadCalendarView(string lid, string startDt, string endDt) { Calendar cal = new Calendar(); try { cal.CalendarId = new Guid(); if (new Guid(lid) != new Guid()) { DateTime st = DateTimeExt.FromUnixTime(Convert.ToInt64(startDt)); DateTime en = DateTimeExt.FromUnixTime(Convert.ToInt64(endDt)); var topics = CalendarFactory.GetPublicCalendarOfLeagueScheduleForView(new Guid(lid), st, en); return Json(new { events = topics }, JsonRequestBehavior.AllowGet); } } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return Json(new { view = "" }, JsonRequestBehavior.AllowGet); }
public ActionResult CreateCalendar(string OwnerEntity) { Calendar cal = new Calendar(); try { Guid memberId = RDN.Library.Classes.Account.User.GetMemberId(); if (OwnerEntity == CalendarOwnerEntityEnum.league.ToString()) { Guid ownerId = MemberCache.GetLeagueIdOfMember(memberId); cal = CalendarFactory.CreateCalendar(ownerId, CalendarOwnerEntityEnum.league); } else if (OwnerEntity == CalendarOwnerEntityEnum.federation.ToString()) { Guid ownerId = MemberCache.GetFederationIdOfMember(memberId); cal = CalendarFactory.CreateCalendar(ownerId, CalendarOwnerEntityEnum.federation); } MemberCache.Clear(memberId); MemberCache.ClearApiCache(memberId); } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return Redirect(Url.Content("~/calendar/" + OwnerEntity + "/" + cal.CalendarId.ToString().Replace("-", ""))); }
public ActionResult CalendarSettings(Calendar calendar) { try { CalendarFactory.UpdateCalendarSettings(calendar); var calen = CalendarFactory.GetCalendar(calendar.CalendarId, calendar.OwnerEntity); ViewBag.IsSuccessful = true; if (calen == null) return Redirect(Url.Content("~/calendar/" + calendar.OwnerEntity.ToString() + "/" + calendar.CalendarId.ToString().Replace("-", ""))); return View(calen); } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return View(calendar); }
public ActionResult CalendarView(string type, string id) { Calendar cal = new Calendar(); Guid memberId = RDN.Library.Classes.Account.User.GetMemberId(); bool isAttendanceManagerOrBetter = MemberCache.IsAttendanceManagerOrBetterOfLeague(memberId); CalendarMessages(Request.Url.Query); try { cal.CalendarId = new Guid(); cal.OwnerEntity = (CalendarOwnerEntityEnum)Enum.Parse(typeof(CalendarOwnerEntityEnum), type); if (new Guid(id) != new Guid()) { var topics = CalendarFactory.GetCalendarSchedule(new Guid(id), (CalendarOwnerEntityEnum)Enum.Parse(typeof(CalendarOwnerEntityEnum), type), DateTime.Today.AddDays(-2), DateTime.Today.AddDays(31), memberId, isAttendanceManagerOrBetter); if (!topics.IsCalendarInUTC) { SiteMessage message = new SiteMessage(); message.MessageType = SiteMessageType.Info; message.Message = "Please set the TimeZone of your calendar in Settings."; this.AddMessage(message); } topics.Events.AddRange(MemberCache.GetMemberBirthdays(memberId, DateTime.UtcNow.AddDays(-2), DateTime.UtcNow.AddDays(31))); topics.Events.AddRange(MemberCache.GetMemberStartDates(memberId, DateTime.UtcNow.AddDays(-2), DateTime.UtcNow.AddDays(31))); return View(topics); } else { return Redirect(Url.Content("~/calendar/league/" + id)); } } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return View(cal); }
public ActionResult LoadCalendarView(string type, string id, string startDt, string endDt) { RDN.Portable.Classes.Controls.Calendar.Calendar cal = new Calendar(); Guid memberId = RDN.Library.Classes.Account.User.GetMemberId(); CalendarMessages(Request.Url.Query); try { cal.CalendarId = new Guid(); cal.OwnerEntity = (CalendarOwnerEntityEnum)Enum.Parse(typeof(CalendarOwnerEntityEnum), type); if (new Guid(id) != new Guid()) { DateTime st = DateTimeExt.FromUnixTime(Convert.ToInt64(startDt)); DateTime en = DateTimeExt.FromUnixTime(Convert.ToInt64(endDt)); var topics = CalendarFactory.GetCalendarScheduleForView(new Guid(id), (CalendarOwnerEntityEnum)Enum.Parse(typeof(CalendarOwnerEntityEnum), type), st, en, memberId); if (!topics.DisableBirthdays) topics.EventsJson.AddRange(MemberCache.GetMemberBirthdaysJson(memberId, st, en)); if (!topics.DisableSkatingStartDates) topics.EventsJson.AddRange(MemberCache.GetMemberStartDatesJson(memberId, st, en)); return Json(new { events = topics.EventsJson }, JsonRequestBehavior.AllowGet); } } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return Json(new { view = "" }, JsonRequestBehavior.AllowGet); }
public ActionResult CalendarList(string type, string id, int? year, int? month) { RDN.Portable.Classes.Controls.Calendar.Calendar cal = new RDN.Portable.Classes.Controls.Calendar.Calendar(); try { Guid memberId = RDN.Library.Classes.Account.User.GetMemberId(); bool isAttendanceManagerOrBetter = MemberCache.IsAttendanceManagerOrBetterOfLeague(memberId); var league = MemberCache.GetLeagueOfMember(memberId); if (league != null) SetCulture(league.CultureSelected); CalendarMessages(Request.Url.Query); cal.CalendarId = new Guid(); cal.OwnerEntity = (CalendarOwnerEntityEnum)Enum.Parse(typeof(CalendarOwnerEntityEnum), type); if (year != null && month != null) cal.CurrentDateSelected = new DateTime(year.Value, month.Value, 15); else cal.CurrentDateSelected = DateTime.Now; if (new Guid(id) != new Guid()) { var topics = CalendarFactory.GetCalendarSchedule(new Guid(id), (CalendarOwnerEntityEnum)Enum.Parse(typeof(CalendarOwnerEntityEnum), type), DateTimeExt.FirstDayOfMonthFromDateTime(cal.CurrentDateSelected).AddDays(-2), DateTimeExt.LastDayOfMonthFromDateTime(cal.CurrentDateSelected).AddDays(2), memberId, isAttendanceManagerOrBetter); if (!topics.IsCalendarInUTC) { SiteMessage message = new SiteMessage(); message.MessageType = SiteMessageType.Info; message.Message = "Please set the TimeZone of your calendar in Settings."; this.AddMessage(message); } topics.CurrentDateSelected = cal.CurrentDateSelected; if (!topics.DisableBirthdays) topics.Events.AddRange(MemberCache.GetMemberBirthdays(memberId, DateTimeExt.FirstDayOfMonthFromDateTime(cal.CurrentDateSelected).AddDays(-1), DateTimeExt.LastDayOfMonthFromDateTime(cal.CurrentDateSelected).AddDays(1))); if (!topics.DisableSkatingStartDates) topics.Events.AddRange(MemberCache.GetMemberStartDates(memberId, DateTimeExt.FirstDayOfMonthFromDateTime(cal.CurrentDateSelected).AddDays(-1), DateTimeExt.LastDayOfMonthFromDateTime(cal.CurrentDateSelected).AddDays(1))); return View(topics); } } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return View(cal); }
/// <summary> /// any changes made here need to be mirrored in getcalendarscheduleForView /// </summary> /// <param name="id"></param> /// <param name="ownerEntity"></param> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <returns></returns> public static RDN.Portable.Classes.Controls.Calendar.Calendar GetCalendarSchedule(Guid id, CalendarOwnerEntityEnum ownerEntity, DateTime startDate, DateTime endDate, Guid memberId, bool isAttendanceManagerOrBetter) { RDN.Portable.Classes.Controls.Calendar.Calendar newCal = new RDN.Portable.Classes.Controls.Calendar.Calendar(); try { var dc = new ManagementContext(); var calDb = (from xx in dc.Calendar.Include("CalendarEventsReocurring").Include("CalendarEvents").Include("CalendarEvents.ReocurringEvent").Include("CalendarEvents.PointsForEvent") where xx.CalendarId == id select new { xx.IsCalendarInUTC, xx.TimeZone, Events = xx.CalendarEvents.Where(x => x.StartDate >= startDate && x.EndDate <= endDate && x.IsRemovedFromCalendar == false), FedOwners = xx.FederationOwners, LeagueOwners = xx.LeagueOwners, AllowSelfCheckIn = xx.AllowSelfCheckIn, xx.DisableBirthdaysFromShowing, xx.DisableStartSkatingDays, EventsReocurring = xx.CalendarEventsReocurring.Where(x => (x.EndReocurring >= startDate || x.EndReocurring == null) && x.StartReocurring <= endDate && x.IsRemovedFromCalendar == false), }).FirstOrDefault(); newCal.IsCalendarInUTC = calDb.IsCalendarInUTC; newCal.TimeZone = calDb.TimeZone; newCal.CalendarId = id; newCal.OwnerEntity = ownerEntity; newCal.AllowSelfCheckIn = calDb.AllowSelfCheckIn; newCal.DisableBirthdays = calDb.DisableBirthdaysFromShowing; newCal.DisableSkatingStartDates = calDb.DisableStartSkatingDays; if (ownerEntity == CalendarOwnerEntityEnum.federation) { foreach (var own in calDb.FedOwners) { CalendarOwner owner = new CalendarOwner(); owner.OwnerId = own.Federation.FederationId; owner.OwnerName = own.Federation.Name; newCal.EntityName = own.Federation.Name; newCal.Owners.Add(owner); } } else if (ownerEntity == CalendarOwnerEntityEnum.league) { foreach (var own in calDb.LeagueOwners) { CalendarOwner owner = new CalendarOwner(); owner.OwnerId = own.League.LeagueId; owner.OwnerName = own.League.Name; newCal.EntityName = own.League.Name; newCal.Owners.Add(owner); } } foreach (var ev in calDb.Events) { newCal.Events.Add(CalendarEventFactory.DisplayEvent(ev, memberId, isAttendanceManagerOrBetter)); } foreach (var ev in calDb.EventsReocurring) { //used so we can refresh the last day events were created.. // ev.LastDateEventsWereCreated = endDate.AddMonths(-1); if (ev.LastDateEventsWereCreated.GetValueOrDefault() < endDate) { var eventRe = dc.CalendarEventsReocurring.Where(x => x.CalendarItemId == ev.CalendarItemId && x.IsRemovedFromCalendar == false).FirstOrDefault(); eventRe.LastDateEventsWereCreated = endDate; eventRe.Calendar = eventRe.Calendar; dc.SaveChanges(); var aEvent = new CalendarViewEventJson() { id = ev.CalendarItemId, Title = ev.Name, Frequency = ev.FrequencyReocurring, DaysOfWeek = ev.DaysOfWeekReocurring, MonthlyInterval = ev.MonthlyIntervalReocurring }; var schedule = new Schedule(aEvent); var range = new DateRange() { StartDateTime = ev.StartReocurring }; //date is null if the event is never ending. if (ev.EndReocurring.HasValue) range.EndDateTime = ev.EndReocurring.Value; else range.EndDateTime = endDate.AddMonths(1); foreach (var date in schedule.Occurrences(range)) { CalendarEvent calEvent = new CalendarEvent(); Guid locationId = new Guid(); if (ev.Location != null) { calEvent.Location.LocationName = ev.Location.LocationName; locationId = ev.Location.LocationId; } calEvent.Name = ev.Name; calEvent.CalendarItemId = ev.CalendarItemId; if (eventRe.Color != null) { var c = Color.FromArgb(eventRe.Color.ColorIdCSharp); calEvent.ColorTempSelected = ColorTranslator.ToHtml(c); } if (!ev.IsInUTCTime) { calEvent.StartDate = new DateTime(date.Year, date.Month, date.Day, ev.StartDate.Hour, ev.StartDate.Minute, ev.StartDate.Second); calEvent.EndDate = new DateTime(date.Year, date.Month, date.Day, ev.EndDate.Hour, ev.EndDate.Minute, ev.EndDate.Second); } else { //we have to create a temp dates so we can add the timezone information without going back a day //if the time being used is on the border. //without the tempdates 1/4/2013 7pm turned into 1/3/2013 7pm because the timezones didn't account for the //fact the dates were already in utc. var startTempDate = new DateTime(date.Year, date.Month, date.Day, ev.StartDate.Hour, ev.StartDate.Minute, ev.StartDate.Second) + new TimeSpan(ev.Calendar.TimeZone, 0, 0); var endTempDate = new DateTime(date.Year, date.Month, date.Day, ev.EndDate.Hour, ev.EndDate.Minute, ev.EndDate.Second) + new TimeSpan(ev.Calendar.TimeZone, 0, 0); calEvent.StartDate = new DateTime(date.Year, date.Month, date.Day, startTempDate.Hour, startTempDate.Minute, startTempDate.Second); calEvent.EndDate = new DateTime(date.Year, date.Month, date.Day, endTempDate.Hour, endTempDate.Minute, endTempDate.Second); } calEvent.Notes = ev.Notes; calEvent.AllowSelfCheckIn = ev.AllowSelfCheckIn; //var evs = (from xx in newCal.Events // where xx.CalendarReoccurringId == ev.CalendarItemId // where xx.StartDate == calEvent.StartDate // where xx.EndDate == calEvent.EndDate // select xx).FirstOrDefault(); ////dirty bit to check if event was already in list. If it is, we don't add it. ////the date check here is to only create events within the calendar selected dates //if (evs == null && calEvent.StartDate >= startDate && calEvent.EndDate <= endDate) //{ // string colorHex = String.Empty; // if (ev.Color != null) // { // var c = Color.FromArgb(ev.Color.ColorIdCSharp); // colorHex = ColorTranslator.ToHtml(c); // } // Guid calItemId = CalendarEventFactory.CreateNewEvent(ev.Calendar.CalendarId, calEvent.StartDate, calEvent.EndDate, locationId, ev.Name, ev.Link, ev.Notes, ev.AllowSelfCheckIn, ev.IsPublic, true, calEvent.CalendarItemId, ev.EventType.CalendarEventTypeId, false, ev.TicketUrl, colorHex, new List<long>(), memberId); // calEvent.CalendarItemId = calItemId; // newCal.Events.Add(calEvent); //} } } } } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return newCal; }
public static RDN.Portable.Classes.Controls.Calendar.Calendar GetCalendar(Guid id, CalendarOwnerEntityEnum ownerEntity) { RDN.Portable.Classes.Controls.Calendar.Calendar newCal = new RDN.Portable.Classes.Controls.Calendar.Calendar(); try { var dc = new ManagementContext(); var calDb = (from xx in dc.Calendar where xx.CalendarId == id select new { xx.CalendarId, xx.AllowSelfCheckIn, xx.NotPresentCheckIn, xx.DisableBirthdaysFromShowing, xx.DisableStartSkatingDays, xx.ImportFeedUrl, xx.CalendarImportTypeEnum, xx.TimeZone, xx.TimeZoneSelection, xx.IsCalendarInUTC }).FirstOrDefault(); if (calDb == null) return null; newCal.CalendarId = id; newCal.OwnerEntity = ownerEntity; newCal.AllowSelfCheckIn = calDb.AllowSelfCheckIn; newCal.NotPresentCheckIn = calDb.NotPresentCheckIn; newCal.DisableSkatingStartDates = calDb.DisableStartSkatingDays; newCal.DisableBirthdays = calDb.DisableBirthdaysFromShowing; newCal.ImportFeedType = (CalendarImportTypeEnum)calDb.CalendarImportTypeEnum; newCal.ImportFeedUrl = calDb.ImportFeedUrl; if (calDb.TimeZoneSelection != null) newCal.TimeZoneId = calDb.TimeZoneSelection.ZoneId; newCal.TimeZone = (int)calDb.TimeZone; newCal.TimeZones = Classes.Location.TimeZoneFactory.GetTimeZones(); newCal.IsCalendarInUTC = calDb.IsCalendarInUTC; var types = dc.CalendarEventTypes.Where(x => x.CalendarOwner.CalendarId == id); foreach (var type in types) { CalendarEventType t = new CalendarEventType(); t.CalendarEventTypeId = type.CalendarEventTypeId; t.EventTypeName = type.EventTypeName; t.PointsForExcused = type.PointsForExcused; t.PointsForNotPresent = type.PointsForNotPresent; t.PointsForPartial = type.PointsForPartial; t.PointsForPresent = type.PointsForPresent; t.PointsForTardy = type.PointsForTardy; if (type.DefaultColor != null) { var c = Color.FromArgb(type.DefaultColor.ColorIdCSharp); t.ColorTempSelected = ColorTranslator.ToHtml(c); t.ColorName = type.DefaultColor.ColorName; } newCal.EventTypes.Add(t); } } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return newCal; }
public static RDN.Portable.Classes.Controls.Calendar.Calendar CreateCalendar(Guid ownerId, CalendarOwnerEntityEnum ownerType) { RDN.Portable.Classes.Controls.Calendar.Calendar calNew = new RDN.Portable.Classes.Controls.Calendar.Calendar(); try { var dc = new ManagementContext(); DataModels.Calendar.Calendar cal = new DataModels.Calendar.Calendar(); cal.AllowSelfCheckIn = false; cal.IsCalendarInUTC = true; if (ownerType == CalendarOwnerEntityEnum.federation) { DataModels.Calendar.CalendarFederationOwnership owner = new DataModels.Calendar.CalendarFederationOwnership(); owner.Calendar = cal; owner.Federation = dc.Federations.Where(x => x.FederationId == ownerId).FirstOrDefault(); owner.OwnerType = Convert.ToInt32(CalendarOwnerTypeEnum.Owner); cal.FederationOwners.Add(owner); } else if (ownerType == CalendarOwnerEntityEnum.league) { DataModels.Calendar.CalendarLeagueOwnership owner = new DataModels.Calendar.CalendarLeagueOwnership(); owner.Calendar = cal; owner.League = dc.Leagues.Where(x => x.LeagueId == ownerId).FirstOrDefault(); owner.OwnerType = Convert.ToInt32(CalendarOwnerTypeEnum.Owner); cal.LeagueOwners.Add(owner); } else if (ownerType == CalendarOwnerEntityEnum.member) { DataModels.Calendar.CalendarMemberOwnership owner = new DataModels.Calendar.CalendarMemberOwnership(); owner.Calendar = cal; owner.Member = dc.Members.Where(x => x.MemberId == ownerId).FirstOrDefault(); owner.OwnerType = Convert.ToInt32(CalendarOwnerTypeEnum.Owner); cal.MemberOwners.Add(owner); } dc.Calendar.Add(cal); dc.SaveChanges(); calNew.CalendarId = cal.CalendarId; calNew.OwnerEntity = ownerType; calNew.AllowSelfCheckIn = false; } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return calNew; }
/// <summary> /// any changes made here need to be mirrored in getcalendarschedule /// </summary> /// <param name="id"></param> /// <param name="ownerEntity"></param> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <returns></returns> public static RDN.Portable.Classes.Controls.Calendar.Calendar GetCalendarScheduleForView(Guid id, CalendarOwnerEntityEnum ownerEntity, DateTime startDate, DateTime endDate, Guid memberId) { RDN.Portable.Classes.Controls.Calendar.Calendar cal = new RDN.Portable.Classes.Controls.Calendar.Calendar(); try { var dc = new ManagementContext(); var calDb = (from xx in dc.Calendar.Include("CalendarEventsReocurring").Include("CalendarEvents").Include("CalendarEvents.ReocurringEvent").Include("CalendarEvents.PointsForEvent") where xx.CalendarId == id select new { xx.IsCalendarInUTC, xx.TimeZone, xx.TimeZoneSelection, xx.DisableStartSkatingDays, xx.DisableBirthdaysFromShowing, Events = xx.CalendarEvents.Where(x => x.StartDate >= startDate && x.EndDate <= endDate && x.IsRemovedFromCalendar == false), EventsReocurring = xx.CalendarEventsReocurring.Where(x => (x.EndReocurring >= startDate || x.EndReocurring == null) && x.StartReocurring <= endDate && x.IsRemovedFromCalendar == false), }).FirstOrDefault(); string baseUrl = VirtualPathUtility.ToAbsolute("~/calendar/event/" + ownerEntity.ToString() + "/" + id.ToString().Replace("-", "") + "/"); cal.DisableSkatingStartDates = calDb.DisableStartSkatingDays; cal.DisableBirthdays = calDb.DisableBirthdaysFromShowing; //adds all the events from the database that were in the date range selected. foreach (var ev in calDb.Events) { try { CalendarEventJson calEvent = new CalendarEventJson(); if (ev.Color != null) { var c = Color.FromArgb(ev.Color.ColorIdCSharp); calEvent.backColor = ColorTranslator.ToHtml(c); } calEvent.title = ev.Name; //removes length less than 14 chars //because the title is too long for the calendar display. if (ev.Name.Length > 14) calEvent.title = calEvent.title.Remove(14); calEvent.id = ev.CalendarItemId; if (ev.ReocurringEvent != null) calEvent.ReocurringId = ev.ReocurringEvent.CalendarItemId; calEvent.url = baseUrl + ev.CalendarItemId.ToString().Replace("-", ""); if (!ev.IsInUTCTime) { calEvent.start = ev.StartDate.ToString("o"); calEvent.end = ev.EndDate.ToString("o"); calEvent.StartDate = ev.StartDate; calEvent.EndDate = ev.EndDate; } else { calEvent.StartDate = ev.StartDate + new TimeSpan(calDb.TimeZone, 0, 0); calEvent.EndDate = ev.EndDate + new TimeSpan(calDb.TimeZone, 0, 0); if (calEvent.StartDate != null) calEvent.start = calEvent.StartDate.ToString("o"); if (calEvent.EndDate != null) calEvent.end = calEvent.EndDate.ToString("o"); } cal.EventsJson.Add(calEvent); } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType(), additionalInformation: calDb.TimeZone + ":" + ev.StartDate + ":" + ev.EndDate); } } int amount = dc.SaveChanges(); } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return cal; }
public static RDN.Portable.Classes.Controls.Calendar.Calendar GetCalendarEvents(Guid id, int count, Guid currentMemberId, bool isAttendanceManagerOrBetter) { RDN.Portable.Classes.Controls.Calendar.Calendar newCal = new RDN.Portable.Classes.Controls.Calendar.Calendar(); try { var dc = new ManagementContext(); var events = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == id && x.StartDate >= DateTime.UtcNow && x.IsRemovedFromCalendar == false).OrderBy(x => x.StartDate).Take(count).AsParallel().ToList(); newCal.CalendarId = id; foreach (var ev in events) { newCal.Events.Add(CalendarEventFactory.DisplayEvent(ev, currentMemberId, isAttendanceManagerOrBetter)); } if (newCal.Events.Count > 0) { TimeSpan ts = newCal.Events.OrderBy(x => x.StartDate).FirstOrDefault().StartDate - DateTime.UtcNow; newCal.DaysToNextEvent = ts.Days; } } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return newCal; }
public ActionResult CalendarList() { Calendar cal = new Calendar(); try { if (HttpContext.Request.InputStream != null) { Stream stream = HttpContext.Request.InputStream; var ob = Network.LoadObject<CalendarSendParams>(ref stream); var mem = MemberCache.GetMemberDisplay(ob.CurrentMemberId); if (ob.UserId == mem.UserId) { var league = MemberCache.GetLeagueOfMember(ob.CurrentMemberId); var isAttendanceManagerOrBetter = MemberCache.IsAttendanceManagerOrBetterOfLeague(ob.CurrentMemberId); cal.CurrentDateSelected = new DateTime(ob.Year, ob.Month, 15); cal = CalendarFactory.GetCalendarSchedule(ob.CalendarId, ob.CalendarType, DateTimeExt.FirstDayOfMonthFromDateTime(cal.CurrentDateSelected).AddDays(-1), DateTimeExt.LastDayOfMonthFromDateTime(cal.CurrentDateSelected).AddDays(1), ob.CurrentMemberId, isAttendanceManagerOrBetter); cal.CurrentDateSelected = new DateTime(ob.Year, ob.Month, 15); if (!cal.DisableBirthdays) cal.Events.AddRange(MemberCache.GetMemberBirthdays(ob.CurrentMemberId, DateTimeExt.FirstDayOfMonthFromDateTime(cal.CurrentDateSelected).AddDays(-1), DateTimeExt.LastDayOfMonthFromDateTime(cal.CurrentDateSelected).AddDays(1))); if (!cal.DisableSkatingStartDates) cal.Events.AddRange(MemberCache.GetMemberStartDates(ob.CurrentMemberId, DateTimeExt.FirstDayOfMonthFromDateTime(cal.CurrentDateSelected).AddDays(-1), DateTimeExt.LastDayOfMonthFromDateTime(cal.CurrentDateSelected).AddDays(1))); cal.Events = cal.Events.OrderBy(x => x.StartDate).ToList(); cal.IsSuccessful = true; return Json(cal, JsonRequestBehavior.AllowGet); } } } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return Json(cal, JsonRequestBehavior.AllowGet); }