/// <summary> /// goes through all the dues collection items. Generates new dues items based on the dates set by teams to start collecting dues. /// </summary> public static int CreateNewDuesCollectionDates() { int emailsSent = 0; try { var dc = new ManagementContext(); int duesType = Convert.ToInt32(Dues.Enums.FeesTypeEnum.DuesType); var getFeeManagements = (from xx in dc.FeeManagement where xx.FeeTypeEnum == duesType select xx); DateTime now = DateTime.UtcNow; DateTime monthAhead = now.AddMonths(1); foreach (var fee in getFeeManagements) { string emailFromDuesSettings = fee.EmailResponse; if (fee.Created < new DateTime(2013, 11, 23)) { RDN.Library.Util.MarkdownSharp.Markdown markdown = new RDN.Library.Util.MarkdownSharp.Markdown(); markdown.AutoHyperlink = true; markdown.LinkEmails = true; if (!String.IsNullOrEmpty(fee.EmailResponse)) { emailFromDuesSettings = HtmlSanitize.FilterHtmlToWhitelist(markdown.Transform(fee.EmailResponse)).Replace("</p>", "</p><br/>"); } } try { if (now.Day == fee.DayOfMonthToCollectDefault) { bool doesFeeExist = false; //checks for the year, month and day of the certain fee to see if its already been added to the fee collection. var feeYear = fee.Fees.Where(x => x.PayBy.Year == monthAhead.Year); if (feeYear != null) { var feeMonth = feeYear.Where(x => x.PayBy.Month == monthAhead.Month); if (feeMonth != null) { if (feeMonth.Where(x => x.PayBy.Day == monthAhead.Day).FirstOrDefault() != null) { //if fee exists, we don't want to add a brand new one. So we set the flag. doesFeeExist = true; } } } //if no fee exists for the next month, we go ahead and add one. if (!doesFeeExist) { Dues.DuesFactory.CreateNewFeeItem(monthAhead, fee); } var duesItems = fee.Fees.Where(x => x.PayBy > now && x.PayBy < monthAhead && x.Notified == false).ToList(); foreach (var due in duesItems) { DateTime dateDue = due.PayBy.AddDays(-due.DaysBeforeDeadlineToNotify); if (dateDue.Month == now.Month && dateDue.Day == now.Day && due.Notified == false) { //email members about payment var mems = fee.LeagueOwner.Members.Where(x => x.HasLeftLeague == false); foreach (var member in mems) { try { string email = string.Empty; if (member.Member.AspNetUserId != new Guid()) email = System.Web.Security.Membership.GetUser((object)member.Member.AspNetUserId).UserName; else { if (member.Member.ContactCard != null) if (member.Member.ContactCard.Emails.Where(x => x.IsDefault).FirstOrDefault() != null) email = member.Member.ContactCard.Emails.Where(x => x.IsDefault).FirstOrDefault().EmailAddress; } if (!String.IsNullOrEmpty(email)) { var emailData = new Dictionary<string, string> { { "name", member.Member.DerbyName }, { "leaguename", fee.LeagueOwner.Name }, { "duedate", due.PayBy.ToShortDateString() }, { "paymentneeded", due.CostOfFee.ToString("N2")}, { "paymentOnlineText", Dues.DuesFactory.GeneratePaymentOnlineText(fee.AcceptPaymentsOnline, fee.LeagueOwner.LeagueId)} }; if (!String.IsNullOrEmpty(fee.EmailResponse)) { emailData.Add("blanktext", emailFromDuesSettings); EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, email, EmailServer.EmailServer.DEFAULT_SUBJECT + " Dues Payment Requested", emailData, EmailServer.EmailServerLayoutsEnum.DuesCollectingNotificationBlank); emailsSent += 1; } else { EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, email, EmailServer.EmailServer.DEFAULT_SUBJECT + " Dues Payment Requested", emailData, EmailServer.EmailServerLayoutsEnum.DuesCollectingNotification); emailsSent += 1; } } } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } } Dues.DuesFactory.NotifiedMembersOfDuesItem(due); } } } } catch (Exception exception) { Error.ErrorDatabaseManager.AddException(exception, exception.GetType()); } } } catch (Exception exception) { Error.ErrorDatabaseManager.AddException(exception, exception.GetType()); } return emailsSent; }
private static ForumMessage DisplayMessage(DataModels.Forum.ForumMessage message) { try { ForumMessage me = new ForumMessage(); me.TopicId = message.Topic.TopicId; me.ForumId = message.Topic.Forum.ForumId; me.Created = message.Created; me.CreatedHumanRelative = RDN.Utilities.Dates.DateTimeExt.RelativeDateTime(message.Created); me.Member = new MemberDisplay { TotalForumPostsCount = message.Member.TotalForumPosts, MemberId = message.Member.MemberId, DerbyName = message.Member.DerbyName, }; if (message.Member.Gender == Convert.ToInt32(GenderEnum.Female)) me.Member.Gender = GenderEnum.Female; else if (message.Member.Gender == Convert.ToInt32(GenderEnum.Male)) me.Member.Gender = GenderEnum.Male; else me.Member.Gender = GenderEnum.None; if (message.Member.Photos.Count > 0) { var photo = message.Member.Photos.OrderByDescending(x => x.Created).Where(x => x.IsPrimaryPhoto == true).FirstOrDefault(); if (photo != null) { me.Member.Photos.Add(new PhotoItem(photo.ImageUrl, true, me.Member.DerbyName)); } } if (message.LastModified > new DateTime(2013, 11, 23) || message.Created > new DateTime(2013, 11, 23)) { me.MessageHTML = message.MessageHTML; } else if (me.Created < new DateTime(2013, 11, 23)) { RDN.Library.Util.MarkdownSharp.Markdown markdown = new RDN.Library.Util.MarkdownSharp.Markdown(); markdown.AutoHyperlink = true; markdown.AutoNewLines = true; markdown.LinkEmails = true; me.MessageMarkDown = message.MessageHTML; me.MessageHTML = markdown.Transform(HtmlSanitize.FilterHtmlToWhitelist(message.MessageHTML)); me.MessageHTML = me.MessageHTML.Replace("</p>", "</p><br/>"); } me.MessageId = message.MessageId; me.MessagePlain = message.MessagePlain; me.MessageLikeCount = message.MessagesLike.Sum(x => x.TotalCount); me.MessageAgreeCount = message.MessagesAgree.Sum(x => x.TotalCount); return me; } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return null; }
public static RDN.Portable.Classes.League.Classes.League DisplayLeague(DataModels.League.League league, bool isPublic = false, bool isRemovedFromLeague = false) { try { RDN.Portable.Classes.League.Classes.League leagueTemp = new Portable.Classes.League.Classes.League(); leagueTemp.LeagueId = league.LeagueId; leagueTemp.Name = league.Name; //leagues don't put the http in their profile. if (!String.IsNullOrEmpty(league.WebSite) && !league.WebSite.Contains("http://")) leagueTemp.Website = "http://" + league.WebSite; else leagueTemp.Website = league.WebSite; if (!String.IsNullOrEmpty(league.Twitter) && !league.Twitter.Contains("http://")) leagueTemp.Twitter = "http://" + league.Twitter; else leagueTemp.Twitter = league.Twitter; if (!String.IsNullOrEmpty(league.Instagram) && !league.Instagram.Contains("http://")) leagueTemp.Instagram = "http://" + league.Instagram; else leagueTemp.Instagram = league.Instagram; if (!String.IsNullOrEmpty(league.Facebook) && !league.Facebook.Contains("http://")) leagueTemp.Facebook = "http://" + league.Facebook; else leagueTemp.Facebook = league.Facebook; leagueTemp.RuleSetsPlayedEnum = (RuleSetsUsedEnum)league.RuleSetsPlayedEnum; leagueTemp.ShopUrl = StoreGateway.GetShopUrl(league.LeagueId); leagueTemp.SubscriptionPeriodEnds = league.SubscriptionPeriodEnds.GetValueOrDefault(); leagueTemp.Groups = LeagueGroupFactory.DisplayGroups(league.Groups.Where(x => x.IsGroupRemoved == false).ToList()); if (league.Founded.HasValue) leagueTemp.Founded = league.Founded.Value; //we use the contact card Id as the join code for "making contact with the league" //instead of creating a new id //and when I don't want to release to use the public LeagueId as the join key. leagueTemp.JoinCode = league.LeagueJoinCode; if (league.ContactCard != null) { if (league.ContactCard.Addresses.FirstOrDefault() != null) { leagueTemp.TimeZone = league.ContactCard.Addresses.FirstOrDefault().TimeZone; leagueTemp.Address = league.ContactCard.Addresses.FirstOrDefault().Address1; leagueTemp.City = league.ContactCard.Addresses.FirstOrDefault().CityRaw; leagueTemp.State = league.ContactCard.Addresses.FirstOrDefault().StateRaw; leagueTemp.ZipCode = league.ContactCard.Addresses.FirstOrDefault().Zip; if (league.ContactCard.Addresses.FirstOrDefault().Country != null) { leagueTemp.Country = league.ContactCard.Addresses.FirstOrDefault().Country.Name; leagueTemp.CountryId = league.ContactCard.Addresses.FirstOrDefault().Country.CountryId; } } if (league.ContactCard.Emails.FirstOrDefault() != null) leagueTemp.Email = league.ContactCard.Emails.Where(x => x.IsDefault == true).FirstOrDefault().EmailAddress; //int numberType = Convert.ToInt32(CommunicationTypeEnum.PhoneNumber); var phone = league.ContactCard.Communications.Where(x => x.CommunicationTypeEnum == (byte)CommunicationTypeEnum.PhoneNumber).FirstOrDefault(); if (phone != null) leagueTemp.PhoneNumber = phone.Data; } if (league.Logo != null) leagueTemp.Logo = new PhotoItem(league.Logo.ImageUrl, league.Logo.IsPrimaryPhoto, league.Logo.AlternativeText); if (league.InternalWelcomePicture != null) leagueTemp.InternalWelcomeImage = new PhotoItem(league.InternalWelcomePicture.ImageUrl, league.InternalWelcomePicture.IsPrimaryPhoto, league.InternalWelcomePicture.AlternativeText); leagueTemp.InternalWelcomeMessage = league.InternalWelcomeMessage; //sets culture as united states english if (league.CultureLCID == 0) leagueTemp.CultureSelected = 1033; else leagueTemp.CultureSelected = league.CultureLCID; if (league.LastModified > new DateTime(2013, 11, 23) || league.Created > new DateTime(2013, 11, 23)) { leagueTemp.InternalWelcomeMessageHtml = leagueTemp.InternalWelcomeMessage; } else if (league.Created < new DateTime(2013, 11, 23)) { RDN.Library.Util.MarkdownSharp.Markdown markdown = new RDN.Library.Util.MarkdownSharp.Markdown(); markdown.AutoHyperlink = true; markdown.AutoNewLines = true; markdown.LinkEmails = true; if (!String.IsNullOrEmpty(leagueTemp.InternalWelcomeMessage)) { leagueTemp.InternalWelcomeMessageHtml = markdown.Transform(HtmlSanitize.FilterHtmlToWhitelist(leagueTemp.InternalWelcomeMessage)); leagueTemp.InternalWelcomeMessageHtml = leagueTemp.InternalWelcomeMessageHtml.Replace("</p>", "</p><br/>"); } } List<LeagueMember> members = new List<LeagueMember>(); if (isPublic) members = league.Members.Where(x => x.HasLeftLeague == isRemovedFromLeague && x.Member.IsProfileRemovedFromPublic == false).ToList(); else members = league.Members.Where(x => x.HasLeftLeague == isRemovedFromLeague).ToList(); leagueTemp.LeagueMembers.AddRange(MemberDisplayFactory.IterateMembersForDisplay(members).OrderBy(x => x.DerbyName)); try { foreach (var color in league.Colors) { if (color != null) { var c = Color.FromArgb(color.Color.ColorIdCSharp); var hex = ColorTranslator.ToHtml(c); ColorDisplay d = new ColorDisplay(); d.ColorId = color.ColorId; d.CSharpColor = color.Color.ColorIdCSharp; d.HexColor = hex; d.NameOfColor = color.Color.ColorName; leagueTemp.ColorTempSelected += d.HexColor + ";"; leagueTemp.ColorsSelected += d.HexColor + ";"; leagueTemp.Colors.Add(d); } } } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } foreach (var team in league.Teams) { TeamDisplay teamTemp = new TeamDisplay(); teamTemp.TeamName = team.Name; teamTemp.TeamId = team.TeamId; teamTemp.Description = team.Description; leagueTemp.Teams.Add(teamTemp); } foreach (var con in league.Contacts) { try { ContactDisplayBasic c = new ContactDisplayBasic(); c.ContactId = con.Contact.ContactId; c.FirstName = con.Contact.Firstname; c.LastName = con.Contact.Lastname; c.ContactTypeForOrg = (ContactTypeForOrganizationEnum)con.ContactTypeEnum; c.ContactTypeSelected = c.ContactTypeForOrg.ToString(); if (con.Contact.ContactCard.Addresses.FirstOrDefault() != null) { c.ContactCard = new Portable.Classes.ContactCard.ContactCard(); Portable.Classes.ContactCard.Address add = new Portable.Classes.ContactCard.Address(); add.Address1 = con.Contact.ContactCard.Addresses.FirstOrDefault().Address1; add.Address2 = con.Contact.ContactCard.Addresses.FirstOrDefault().Address2; add.CityRaw = con.Contact.ContactCard.Addresses.FirstOrDefault().CityRaw; add.Zip = con.Contact.ContactCard.Addresses.FirstOrDefault().Zip; add.StateRaw = con.Contact.ContactCard.Addresses.FirstOrDefault().StateRaw; if (con.Contact.ContactCard.Addresses.FirstOrDefault().Country != null) add.Country = con.Contact.ContactCard.Addresses.FirstOrDefault().Country.Name; c.Address1 = con.Contact.ContactCard.Addresses.FirstOrDefault().Address1; c.Address2 = con.Contact.ContactCard.Addresses.FirstOrDefault().Address2; c.CityRaw = con.Contact.ContactCard.Addresses.FirstOrDefault().CityRaw; c.Zip = con.Contact.ContactCard.Addresses.FirstOrDefault().Zip; c.StateRaw = con.Contact.ContactCard.Addresses.FirstOrDefault().StateRaw; if (con.Contact.ContactCard.Addresses.FirstOrDefault().Country != null) { c.CountryId = con.Contact.ContactCard.Addresses.FirstOrDefault().Country.CountryId; c.CountryName = con.Contact.ContactCard.Addresses.FirstOrDefault().Country.Name; } c.ContactCard.Addresses.Add(add); } if (con.Contact.ContactCard.Emails.FirstOrDefault() != null) c.Email = con.Contact.ContactCard.Emails.FirstOrDefault().EmailAddress; var phone = con.Contact.ContactCard.Communications.OrderByDescending(x => x.Created).FirstOrDefault(); if (phone != null) c.PhoneNumber = phone.Data; c.CompanyName = con.Contact.CompanyName; c.Notes = con.Notes; c.Link = con.Contact.Link; leagueTemp.Contacts.Add(c); } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } } foreach (var federation in league.Federations) { FederationDisplay fed = new FederationDisplay(); fed.FederationId = federation.Federation.FederationId; fed.FederationName = federation.Federation.Name; fed.MembershipId = federation.InternalLeagueIdForFederation; leagueTemp.Federations.Add(fed); } return leagueTemp; } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return null; }
public static RDN.Library.Classes.Controls.Calendar.CalendarEvent GetEvent(Guid eventId, Guid currentMemberId, Guid calendarId = new Guid()) { RDN.Library.Classes.Controls.Calendar.CalendarEvent ev = new RDN.Library.Classes.Controls.Calendar.CalendarEvent(); try { var dc = new ManagementContext(); var e = (from xx in dc.CalendarEvents.Include("Location").Include("Location.Contact").Include("Location.Contact.Addresses").Include("Location.Contact.Communications") where xx.Calendar.CalendarId == calendarId where xx.CalendarItemId == eventId where xx.IsRemovedFromCalendar == false select new { xx.TicketUrl, xx.IsInUTCTime, xx.Calendar.TimeZone, xx.Calendar.IsCalendarInUTC, xx.AllowSelfCheckIn, xx.CalendarItemId, xx.Calendar.LeagueOwners, xx.EndDate, xx.Link, xx.Name, xx.Notes, xx.StartDate, xx.Attendees, xx.Location, xx.IsPublicEvent, contactCart = xx.Location.Contact, addresses = xx.Location.Contact.Addresses, coms = xx.Location.Contact.Communications, xx.PointsForEvent, xx.EventType, xx.ReocurringEvent, nextEventId = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate >= xx.StartDate && x.CalendarItemId != eventId).OrderBy(x => x.StartDate).Select(x => x.CalendarItemId).FirstOrDefault(), previousEventId = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate <= xx.StartDate && x.CalendarItemId != eventId).OrderByDescending(x => x.StartDate).Select(x => x.CalendarItemId).FirstOrDefault(), nextStartDate = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate >= xx.StartDate && x.CalendarItemId != eventId).OrderBy(x => x.StartDate).Select(x => x.StartDate).FirstOrDefault(), previousStartDate = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate <= xx.StartDate && x.CalendarItemId != eventId).OrderByDescending(x => x.StartDate).Select(x => x.StartDate).FirstOrDefault(), xx.LastModified, xx.Created, xx.Color, xx.Groups }).FirstOrDefault(); if (calendarId == new Guid() && e == null) { e = (from xx in dc.CalendarEvents.Include("Location").Include("Location.Contact").Include("Location.Contact.Addresses").Include("Location.Contact.Communications") where xx.CalendarItemId == eventId where xx.IsRemovedFromCalendar == false select new { xx.TicketUrl, xx.IsInUTCTime, xx.Calendar.TimeZone, xx.Calendar.IsCalendarInUTC, xx.AllowSelfCheckIn, xx.CalendarItemId, xx.Calendar.LeagueOwners, xx.EndDate, xx.Link, xx.Name, xx.Notes, xx.StartDate, xx.Attendees, xx.Location, xx.IsPublicEvent, contactCart = xx.Location.Contact, addresses = xx.Location.Contact.Addresses, coms = xx.Location.Contact.Communications, xx.PointsForEvent, xx.EventType, xx.ReocurringEvent, nextEventId = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate >= xx.StartDate && x.CalendarItemId != eventId).OrderBy(x => x.StartDate).Select(x => x.CalendarItemId).FirstOrDefault(), previousEventId = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate <= xx.StartDate && x.CalendarItemId != eventId).OrderByDescending(x => x.StartDate).Select(x => x.CalendarItemId).FirstOrDefault(), nextStartDate = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate >= xx.StartDate && x.CalendarItemId != eventId).OrderBy(x => x.StartDate).Select(x => x.StartDate).FirstOrDefault(), previousStartDate = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate <= xx.StartDate && x.CalendarItemId != eventId).OrderByDescending(x => x.StartDate).Select(x => x.StartDate).FirstOrDefault(), xx.LastModified, xx.Created, xx.Color, xx.Groups }).FirstOrDefault(); } if (e == null) { return GetEventReocurring(calendarId, eventId); } //need to get the league first for the calendar. foreach (var owner in e.LeagueOwners) { if (owner.League != null) { ev.OrganizersId = owner.League.LeagueId; ev.OrganizersName = owner.League.Name; break; } } //adding the members of the event to it. foreach (var g in e.Groups) { var gTemp = League.Classes.LeagueGroupFactory.DisplayGroup(g.Group); ev.GroupsForEvent.Add(gTemp); foreach (var mem in gTemp.GroupMembers) { if (ev.MembersApartOfEvent.Where(x => x.MemberId == mem.MemberId).FirstOrDefault() == null) { RDN.Portable.Classes.Controls.Calendar.CalendarAttendance a = new RDN.Portable.Classes.Controls.Calendar.CalendarAttendance(); a.MemberId = mem.MemberId; a.MemberName = mem.DerbyName; a.IsCheckedIn = false; a.FullName = mem.Firstname + " " + mem.LastName; a.MemberNumber = mem.PlayerNumber; ev.MembersApartOfEvent.Add(a); ev.MembersToCheckIn.Add(a); } } } //if the event had no groups attached, we add the league members to the event. if (ev.MembersApartOfEvent.Count == 0) { var members = League.LeagueFactory.GetLeagueMembers(ev.OrganizersId); for (int i = 0; i < members.Count; i++) { RDN.Portable.Classes.Controls.Calendar.CalendarAttendance a = new Portable.Classes.Controls.Calendar.CalendarAttendance(); a.MemberId = members[i].MemberId; a.MemberName = members[i].DerbyName; a.IsCheckedIn = false; a.FullName = members[i].Firstname + " " + members[i].LastName; a.MemberNumber = members[i].PlayerNumber; ev.MembersApartOfEvent.Add(a); ev.MembersToCheckIn.Add(a); } } //event type needs to stay above attendees since attendees relies on event type. ev.EventType = new Portable.Classes.Controls.Calendar.CalendarEventType(); if (e.EventType != null) { ev.EventType.EventTypeName = e.EventType.EventTypeName; ev.EventType.PointsForExcused = e.EventType.PointsForExcused; ev.EventType.PointsForNotPresent = e.EventType.PointsForNotPresent; ev.EventType.PointsForPartial = e.EventType.PointsForPartial; ev.EventType.PointsForPresent = e.EventType.PointsForPresent; ev.EventType.PointsForTardy = e.EventType.PointsForTardy; ev.EventType.CalendarEventTypeId = e.EventType.CalendarEventTypeId; } //add the attendees to the event. foreach (var att in e.Attendees) { RDN.Portable.Classes.Controls.Calendar.CalendarAttendance a = new Portable.Classes.Controls.Calendar.CalendarAttendance() { AttedanceId = att.CalendarAttendanceId, MemberId = att.Attendant.MemberId, FullName = att.Attendant.Firstname + " " + att.Attendant.Lastname, MemberName = att.Attendant.DerbyName, Note = att.Note, PointType = (CalendarEventPointTypeEnum)Enum.Parse(typeof(CalendarEventPointTypeEnum), att.PointTypeEnum.ToString()), SecondaryPointType = (CalendarEventPointTypeEnum)Enum.Parse(typeof(CalendarEventPointTypeEnum), att.SecondaryPointTypeEnum.ToString()), MemberNumber = att.Attendant.PlayerNumber, AdditionalPoints = att.AdditionalPoints, Availability = (AvailibilityEnum)Enum.Parse(typeof(AvailibilityEnum), att.AvailibityEnum.ToString()), AvailableNotes = att.AvailabilityNote, }; switch (a.PointType) { case CalendarEventPointTypeEnum.Present: if (a.SecondaryPointType == CalendarEventPointTypeEnum.Tardy && a.AdditionalPoints == 0) a.PointsStringForReading = ev.EventType.PointsForPresent + " + " + ev.EventType.PointsForTardy + " = " + (ev.EventType.PointsForPresent + ev.EventType.PointsForTardy); else if (a.SecondaryPointType == CalendarEventPointTypeEnum.Tardy) a.PointsStringForReading = ev.EventType.PointsForPresent + " + " + a.AdditionalPoints + " + " + ev.EventType.PointsForTardy + " = " + (ev.EventType.PointsForPresent + ev.EventType.PointsForTardy + a.AdditionalPoints); else if (a.AdditionalPoints != 0) a.PointsStringForReading = ev.EventType.PointsForPresent + " + " + a.AdditionalPoints + " = " + (ev.EventType.PointsForPresent + a.AdditionalPoints); else a.PointsStringForReading = ev.EventType.PointsForPresent.ToString(); break; case CalendarEventPointTypeEnum.Partial: if (a.SecondaryPointType == CalendarEventPointTypeEnum.Tardy && a.AdditionalPoints == 0) a.PointsStringForReading = ev.EventType.PointsForPartial + " + " + ev.EventType.PointsForTardy + " = " + (ev.EventType.PointsForPartial + ev.EventType.PointsForTardy); else if (a.SecondaryPointType == CalendarEventPointTypeEnum.Tardy) a.PointsStringForReading = ev.EventType.PointsForPartial + " + " + a.AdditionalPoints + " + " + ev.EventType.PointsForTardy + " = " + (ev.EventType.PointsForPartial + ev.EventType.PointsForTardy + a.AdditionalPoints); else if (a.AdditionalPoints != 0) a.PointsStringForReading = ev.EventType.PointsForPartial + " + " + a.AdditionalPoints + " = " + (ev.EventType.PointsForPartial + a.AdditionalPoints); else a.PointsStringForReading = ev.EventType.PointsForPartial.ToString(); break; case CalendarEventPointTypeEnum.Not_Present: if (a.SecondaryPointType == CalendarEventPointTypeEnum.Tardy && a.AdditionalPoints == 0) a.PointsStringForReading = ev.EventType.PointsForNotPresent + " + " + ev.EventType.PointsForTardy + " = " + (ev.EventType.PointsForNotPresent + ev.EventType.PointsForTardy); else if (a.SecondaryPointType == CalendarEventPointTypeEnum.Tardy) a.PointsStringForReading = ev.EventType.PointsForNotPresent + " + " + a.AdditionalPoints + " + " + ev.EventType.PointsForTardy + " = " + (ev.EventType.PointsForNotPresent + ev.EventType.PointsForTardy + a.AdditionalPoints); else if (a.AdditionalPoints != 0) a.PointsStringForReading = ev.EventType.PointsForNotPresent + " + " + a.AdditionalPoints + " = " + (ev.EventType.PointsForNotPresent + a.AdditionalPoints); else a.PointsStringForReading = ev.EventType.PointsForNotPresent.ToString(); break; case CalendarEventPointTypeEnum.Excused: if (a.SecondaryPointType == CalendarEventPointTypeEnum.Tardy && a.AdditionalPoints == 0) a.PointsStringForReading = ev.EventType.PointsForExcused + " + " + ev.EventType.PointsForTardy + " = " + (ev.EventType.PointsForExcused + ev.EventType.PointsForTardy); else if (a.SecondaryPointType == CalendarEventPointTypeEnum.Tardy) a.PointsStringForReading = ev.EventType.PointsForExcused + " + " + a.AdditionalPoints + " + " + ev.EventType.PointsForTardy + " = " + (ev.EventType.PointsForExcused + ev.EventType.PointsForTardy + a.AdditionalPoints); else if (a.AdditionalPoints != 0) a.PointsStringForReading = ev.EventType.PointsForExcused + " + " + a.AdditionalPoints + " = " + (ev.EventType.PointsForExcused + a.AdditionalPoints); else a.PointsStringForReading = ev.EventType.PointsForExcused.ToString(); break; } if (a.PointType != CalendarEventPointTypeEnum.None) a.IsCheckedIn = true; //since the member is attending the event, we remove them from having members to check in. var checkedInMember = ev.MembersToCheckIn.Where(x => x.MemberId == a.MemberId).FirstOrDefault(); if (checkedInMember != null) ev.MembersToCheckIn.Remove(checkedInMember); ev.Attendees.Add(a); } var avail = ev.Attendees.Where(x => x.MemberId == currentMemberId && x.Availability != AvailibilityEnum.None).FirstOrDefault(); if (avail != null) ev.HasCurrentMemberSetAvailability = true; var attend = ev.Attendees.Where(x => x.MemberId == currentMemberId && x.IsCheckedIn == true).FirstOrDefault(); if (attend != null) ev.IsCurrentMemberCheckedIn = true; if (e.Color != null) { var c = Color.FromArgb(e.Color.ColorIdCSharp); ev.ColorTempSelected = ColorTranslator.ToHtml(c); } ev.IsCalendarInUTC = e.IsCalendarInUTC; ev.IsInUTCTime = e.IsInUTCTime; ev.CalendarTimeZone = e.TimeZone; ev.AllowSelfCheckIn = e.AllowSelfCheckIn; ev.CalendarItemId = e.CalendarItemId; ev.CalendarId = calendarId; ev.RDNationLink = ServerConfig.WEBSITE_EVENT_URL + "/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(e.Name) + "/" + e.CalendarItemId.ToString().Replace("-", ""); if (!ev.IsInUTCTime) { ev.EndDate = e.EndDate; ev.StartDate = e.StartDate; } else { ev.StartDate = (e.StartDate + new TimeSpan(e.TimeZone, 0, 0)); ev.EndDate = (e.EndDate + new TimeSpan(e.TimeZone, 0, 0)); } if (!String.IsNullOrEmpty(e.Link) && !e.Link.Contains("http://")) ev.Link = "http://" + e.Link; else ev.Link = e.Link; ev.IsPublicEvent = e.IsPublicEvent; ev.TicketUrl = e.TicketUrl; if (e.ReocurringEvent != null) { ev.CalendarReoccurringId = e.ReocurringEvent.CalendarItemId; ev.IsReoccurring = true; } GoogleCalendar gc = new GoogleCalendar(); if (e.Location != null) { ev.Location.LocationName = e.Location.LocationName; ev.Location.LocationId = e.Location.LocationId; gc.Location = ev.Location.LocationName + ", "; } if (e.addresses.FirstOrDefault() != null) { Address address = new Address(); address.Address1 = e.addresses.FirstOrDefault().Address1; address.Address2 = e.addresses.FirstOrDefault().Address2; address.AddressId = e.addresses.FirstOrDefault().AddressId; address.CityRaw = e.addresses.FirstOrDefault().CityRaw; if (e.addresses.FirstOrDefault().Country != null) address.Country = e.addresses.FirstOrDefault().Country.Code; address.StateRaw = e.addresses.FirstOrDefault().StateRaw; address.Zip = e.addresses.FirstOrDefault().Zip; gc.Location += address.Address1 + " " + address.Address2 + ", " + address.CityRaw + ", " + address.StateRaw + " " + address.Zip; ev.Location.Contact.Addresses.Add(address); } ev.Name = e.Name; ev.NextEventId = e.nextEventId; ev.PreviousEventId = e.previousEventId; //if two or more events lay on the same StartDate and Time, we do this to Sort them //into previous and next so that we can walk through them one by one. //before this, if we hit next, we would skip over dates with the same datetime. if (ev.NextEventId != ev.PreviousEventId) { var oneDateManyEvents = (from xx in dc.CalendarEvents where xx.Calendar.CalendarId == calendarId where xx.IsRemovedFromCalendar == false where xx.StartDate == e.previousStartDate select xx.CalendarItemId).OrderBy(x => x).ToList(); if (oneDateManyEvents.Count > 1) { var indexOfCurrentEvent = oneDateManyEvents.IndexOf(oneDateManyEvents.Where(x => x == ev.PreviousEventId).FirstOrDefault()); //if we get to this point, the event always gets the first event with the same times. //We we need to reverse it to make it get the last event in the sequence. if (indexOfCurrentEvent == 0) { ev.NextEventId = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate > e.StartDate).OrderBy(x => x.StartDate).Select(x => x.CalendarItemId).FirstOrDefault(); ev.PreviousEventId = oneDateManyEvents[oneDateManyEvents.Count - 1]; } } } else { try { var oneDateManyEvents = (from xx in dc.CalendarEvents where xx.Calendar.CalendarId == calendarId where xx.IsRemovedFromCalendar == false where xx.StartDate == e.StartDate select xx.CalendarItemId).OrderBy(x => x).ToList(); var indexOfCurrentEvent = oneDateManyEvents.IndexOf(oneDateManyEvents.Where(x => x == eventId).FirstOrDefault()); if (indexOfCurrentEvent == 0) { try { ev.PreviousEventId = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate < e.StartDate && x.CalendarItemId != eventId).OrderByDescending(x => x.StartDate).Select(x => x.CalendarItemId).FirstOrDefault(); if (oneDateManyEvents.Count > indexOfCurrentEvent && oneDateManyEvents.Count > 1) ev.NextEventId = oneDateManyEvents[indexOfCurrentEvent + 1]; } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType(), additionalInformation: indexOfCurrentEvent + " " + oneDateManyEvents.Count); } } else if (indexOfCurrentEvent >= oneDateManyEvents.Count - 1) { if (oneDateManyEvents.Count > 1) ev.PreviousEventId = oneDateManyEvents[indexOfCurrentEvent - 1]; ev.NextEventId = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate > e.StartDate && x.CalendarItemId != eventId).OrderBy(x => x.StartDate).Select(x => x.CalendarItemId).FirstOrDefault(); } else { ev.PreviousEventId = oneDateManyEvents[indexOfCurrentEvent - 1]; ev.NextEventId = oneDateManyEvents[indexOfCurrentEvent + 1]; } } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } } ev.Notes = e.Notes; if (e.LastModified > new DateTime(2013, 11, 23) || e.Created > new DateTime(2013, 11, 23)) { ev.NotesHtml = e.Notes; } else if (e.Created < new DateTime(2013, 11, 23)) { if (!String.IsNullOrEmpty(e.Notes)) { RDN.Library.Util.MarkdownSharp.Markdown markdown = new RDN.Library.Util.MarkdownSharp.Markdown(); markdown.AutoHyperlink = true; markdown.LinkEmails = true; ev.NotesHtml = HtmlSanitize.FilterHtmlToWhitelist(markdown.Transform(e.Notes)).Replace("</p>", "</p><br/>"); } } gc.Description = ev.Notes; gc.EndDate = ev.EndDate.ToUniversalTime(); gc.StartDate = ev.StartDate.ToUniversalTime(); gc.Website = ev.Link; gc.WebsiteName = ev.Link; gc.What = ev.Name; ev.GoogleCalendarUrl = gc.GetGoogleUrl(); } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return ev; }
public static RDN.Library.Classes.Controls.Calendar.CalendarEvent GetEventReocurring(Guid eventId, Guid calendarId = new Guid()) { RDN.Library.Classes.Controls.Calendar.CalendarEvent ev = new RDN.Library.Classes.Controls.Calendar.CalendarEvent(); try { var dc = new ManagementContext(); var e = (from xx in dc.CalendarEventsReocurring.Include("Location").Include("Location.Contact").Include("Location.Contact.Addresses").Include("Location.Contact.Communications") where xx.Calendar.CalendarId == calendarId where xx.CalendarItemId == eventId where xx.IsRemovedFromCalendar == false select new { xx.TicketUrl, xx.IsInUTCTime, xx.Calendar.IsCalendarInUTC, xx.Calendar.TimeZone, xx.AllowSelfCheckIn, xx.CalendarItemId, xx.EndDate, xx.Link, xx.Calendar.LeagueOwners, xx.Name, xx.Notes, xx.StartDate, xx.Location, contactCart = xx.Location.Contact, addresses = xx.Location.Contact.Addresses, coms = xx.Location.Contact.Communications, xx.PointsForEvent, xx.EventType, xx.DaysOfWeekReocurring, xx.StartReocurring, xx.EndReocurring, xx.FrequencyReocurring, xx.IsPublic, xx.MonthlyIntervalReocurring, xx.LastModified, xx.Created, xx.Color, xx.Groups }).FirstOrDefault(); if (calendarId == new Guid() && e == null) { e = (from xx in dc.CalendarEventsReocurring.Include("Location").Include("Location.Contact").Include("Location.Contact.Addresses").Include("Location.Contact.Communications") where xx.Calendar.CalendarId == calendarId where xx.CalendarItemId == eventId where xx.IsRemovedFromCalendar == false select new { xx.TicketUrl, xx.IsInUTCTime, xx.Calendar.IsCalendarInUTC, xx.Calendar.TimeZone, xx.AllowSelfCheckIn, xx.CalendarItemId, xx.EndDate, xx.Link, xx.Calendar.LeagueOwners, xx.Name, xx.Notes, xx.StartDate, xx.Location, contactCart = xx.Location.Contact, addresses = xx.Location.Contact.Addresses, coms = xx.Location.Contact.Communications, xx.PointsForEvent, xx.EventType, xx.DaysOfWeekReocurring, xx.StartReocurring, xx.EndReocurring, xx.FrequencyReocurring, xx.IsPublic, xx.MonthlyIntervalReocurring, xx.LastModified, xx.Created, xx.Color, xx.Groups }).FirstOrDefault(); } if (e == null) return null; ev.AllowSelfCheckIn = e.AllowSelfCheckIn; ev.CalendarItemId = e.CalendarItemId; if (e.Color != null) { var c = Color.FromArgb(e.Color.ColorIdCSharp); ev.ColorTempSelected = ColorTranslator.ToHtml(c); } ev.Link = e.Link; var aEvent = new ScheduleWidget.ScheduledEvents.Event() { Title = e.Name, FrequencyTypeOptions = (FrequencyTypeEnum)Enum.Parse(typeof(FrequencyTypeEnum), e.FrequencyReocurring.ToString()), DaysOfWeek = e.DaysOfWeekReocurring, MonthlyInterval = e.MonthlyIntervalReocurring }; if (e.EndReocurring.HasValue) { ev.EndDateReoccurring = e.EndReocurring.GetValueOrDefault(); ev.EndDateReoccurringDisplay = e.EndReocurring.GetValueOrDefault().ToShortDateString(); } ev.StartDateReoccurring = e.StartReocurring; ev.StartDateReoccurringDisplay = e.StartReocurring.ToShortDateString() + " " + e.StartReocurring.ToShortTimeString(); ev.EventReoccurring = aEvent; ev.TicketUrl = e.TicketUrl; ev.RDNationLink = ServerConfig.WEBSITE_EVENT_URL + "/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(e.Name) + "/" + e.CalendarItemId.ToString().Replace("-", ""); foreach (var owner in e.LeagueOwners) { if (owner.League != null) { ev.OrganizersId = owner.League.LeagueId; ev.OrganizersName = owner.League.Name; break; } } GoogleCalendar gc = new GoogleCalendar(); if (e.Location != null) { ev.Location.LocationName = e.Location.LocationName; ev.Location.LocationId = e.Location.LocationId; } gc.Location = ev.Location.LocationName + ", "; if (e.addresses.FirstOrDefault() != null) { RDN.Portable.Classes.ContactCard.Address address = new RDN.Portable.Classes.ContactCard.Address(); address.Address1 = e.addresses.FirstOrDefault().Address1; address.Address2 = e.addresses.FirstOrDefault().Address2; address.AddressId = e.addresses.FirstOrDefault().AddressId; address.CityRaw = e.addresses.FirstOrDefault().CityRaw; if (e.addresses.FirstOrDefault().Country != null) address.Country = e.addresses.FirstOrDefault().Country.Code; address.StateRaw = e.addresses.FirstOrDefault().StateRaw; address.Zip = e.addresses.FirstOrDefault().Zip; gc.Location += address.Address1 + " " + address.Address2 + ", " + address.CityRaw + ", " + address.StateRaw + " " + address.Zip; ev.Location.Contact.Addresses.Add(address); } ev.EventType = new Portable.Classes.Controls.Calendar.CalendarEventType(); if (e.EventType != null) { ev.EventType.EventTypeName = e.EventType.EventTypeName; ev.EventType.PointsForExcused = e.EventType.PointsForExcused; ev.EventType.PointsForNotPresent = e.EventType.PointsForNotPresent; ev.EventType.PointsForPartial = e.EventType.PointsForPartial; ev.EventType.PointsForPresent = e.EventType.PointsForPresent; ev.EventType.PointsForTardy = e.EventType.PointsForTardy; ev.EventType.CalendarEventTypeId = e.EventType.CalendarEventTypeId; } ev.Name = e.Name; ev.Notes = e.Notes; foreach (var g in e.Groups) { var gTemp = League.Classes.LeagueGroupFactory.DisplayGroup(g.Group); ev.GroupsForEvent.Add(gTemp); foreach (var mem in gTemp.GroupMembers) { if (ev.MembersApartOfEvent.Where(x => x.MemberId == mem.MemberId).FirstOrDefault() == null) { RDN.Portable.Classes.Controls.Calendar.CalendarAttendance a = new Portable.Classes.Controls.Calendar.CalendarAttendance(); a.MemberId = mem.MemberId; a.MemberName = mem.DerbyName; a.IsCheckedIn = false; a.FullName = mem.Firstname + " " + mem.LastName; a.MemberNumber = mem.PlayerNumber; ev.MembersApartOfEvent.Add(a); ev.MembersToCheckIn.Add(a); } } } if (e.LastModified > new DateTime(2013, 11, 23) || e.Created > new DateTime(2013, 11, 23)) { ev.NotesHtml = e.Notes; } else if (e.Created < new DateTime(2013, 11, 23)) { if (!String.IsNullOrEmpty(e.Notes)) { RDN.Library.Util.MarkdownSharp.Markdown markdown = new RDN.Library.Util.MarkdownSharp.Markdown(); markdown.AutoHyperlink = true; markdown.LinkEmails = true; ev.NotesHtml = HtmlSanitize.FilterHtmlToWhitelist(markdown.Transform(e.Notes)).Replace("</p>", "</p><br/>"); } } ev.IsPublicEvent = e.IsPublic; gc.Description = ev.Notes; if (!e.IsInUTCTime) { ev.EndDate = e.EndDate; ev.StartDate = e.StartDate; } else { ev.StartDate = (e.StartDate + new TimeSpan(e.TimeZone, 0, 0)); ev.EndDate = (e.EndDate + new TimeSpan(e.TimeZone, 0, 0)); } gc.EndDate = ev.EndDate.ToUniversalTime(); gc.StartDate = ev.StartDate.ToUniversalTime(); gc.Website = ev.Link; gc.WebsiteName = ev.Link; gc.What = ev.Name; ev.GoogleCalendarUrl = gc.GetGoogleUrl(); } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return ev; }
public static CalendarEvent DisplayEvent(DataModels.Calendar.CalendarEvent ev, Guid currentMemberId, bool isAttendanceManagerOrBetter) { CalendarEvent calEvent = new CalendarEvent(); try { calEvent.IsAttendanceManagerOrBetter = isAttendanceManagerOrBetter; foreach (var att in ev.Attendees) { RDN.Portable.Classes.Controls.Calendar.CalendarAttendance a = new Portable.Classes.Controls.Calendar.CalendarAttendance(); a.MemberId = att.Attendant.MemberId; a.MemberName = att.Attendant.DerbyName; a.FullName = att.Attendant.Firstname + " " + att.Attendant.Lastname; a.AttedanceId = att.CalendarAttendanceId; a.Note = att.Note; a.PointType = (CalendarEventPointTypeEnum)Enum.Parse(typeof(CalendarEventPointTypeEnum), att.PointTypeEnum.ToString()); a.SecondaryPointType = (CalendarEventPointTypeEnum)Enum.Parse(typeof(CalendarEventPointTypeEnum), att.SecondaryPointTypeEnum.ToString()); a.Availability = (AvailibilityEnum)Enum.Parse(typeof(AvailibilityEnum), att.AvailibityEnum.ToString()); a.AvailableNotes = att.AvailabilityNote; if (a.PointType != CalendarEventPointTypeEnum.None) a.IsCheckedIn = true; calEvent.Attendees.Add(a); } if (ev.Groups.Count == 0) calEvent.IsCurrentMemberApartOfEvent = true; else { foreach (var g in ev.Groups) { var gTemp = League.Classes.LeagueGroupFactory.DisplayGroup(g.Group); foreach (var mem in gTemp.GroupMembers) { RDN.Portable.Classes.Controls.Calendar.CalendarAttendance a = new RDN.Portable.Classes.Controls.Calendar.CalendarAttendance(); a.MemberId = mem.MemberId; a.MemberName = mem.DerbyName; if (calEvent.MembersApartOfEvent.Where(x => x.MemberId == a.MemberId).FirstOrDefault() == null) calEvent.MembersApartOfEvent.Add(a); } } } if (ev.EventType != null) { calEvent.EventType.CalendarEventTypeId = ev.EventType.CalendarEventTypeId; calEvent.EventType.PointsForExcused = ev.EventType.PointsForExcused; calEvent.EventType.PointsForNotPresent = ev.EventType.PointsForNotPresent; calEvent.EventType.PointsForPartial = ev.EventType.PointsForPartial; calEvent.EventType.PointsForPresent = ev.EventType.PointsForPresent; calEvent.EventType.PointsForTardy = ev.EventType.PointsForTardy; } foreach (var owner in ev.Calendar.LeagueOwners) { if (owner.League != null) { calEvent.OrganizersId = owner.League.LeagueId; calEvent.OrganizersName = owner.League.Name; if (owner.League.Logo != null) calEvent.ImageUrl = owner.League.Logo.ImageUrlThumb; calEvent.OrganizerUrl = ServerConfig.WEBSITE_DEFAULT_LOCATION + "/roller-derby-league/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(calEvent.OrganizersName) + "/" + calEvent.OrganizersId.ToString().Replace("-", ""); break; } } GoogleCalendar gc = new GoogleCalendar(); if (ev.Location != null) { calEvent.Location.LocationName = ev.Location.LocationName; gc.Location = calEvent.Location.LocationName + " "; } if (ev.Location != null) { calEvent.Location.LocationName = ev.Location.LocationName; calEvent.Location.LocationId = ev.Location.LocationId; if (ev.Location.Contact != null && ev.Location.Contact.Addresses.FirstOrDefault() != null) { Address address = new Address(); address.Address1 = ev.Location.Contact.Addresses.FirstOrDefault().Address1; address.Address2 = ev.Location.Contact.Addresses.FirstOrDefault().Address2; address.AddressId = ev.Location.Contact.Addresses.FirstOrDefault().AddressId; address.CityRaw = ev.Location.Contact.Addresses.FirstOrDefault().CityRaw; if (ev.Location.Contact.Addresses.FirstOrDefault().Country != null) address.Country = ev.Location.Contact.Addresses.FirstOrDefault().Country.Code; address.StateRaw = ev.Location.Contact.Addresses.FirstOrDefault().StateRaw; address.Zip = ev.Location.Contact.Addresses.FirstOrDefault().Zip; gc.Location += address.Address1 + " " + address.Address2 + ", " + address.CityRaw + ", " + address.StateRaw + " " + address.Zip; address.Coords = new Portable.Classes.Location.GeoCoordinate(); address.Coords.Longitude = ev.Location.Contact.Addresses.FirstOrDefault().Coords.Longitude; address.Coords.Latitude = ev.Location.Contact.Addresses.FirstOrDefault().Coords.Latitude; if (!String.IsNullOrEmpty(address.CityRaw)) calEvent.Address += address.CityRaw + ", "; if (!String.IsNullOrEmpty(address.StateRaw)) calEvent.Address += address.StateRaw + ","; calEvent.Address += address.Country; calEvent.AddressUrl += "http://www.bing.com/maps/default.aspx?q="; calEvent.AddressUrl += address.Address1 + address.Address2; calEvent.AddressUrl += " ," + address.CityRaw; calEvent.AddressUrl += "," + address.StateRaw; calEvent.AddressUrl += " " + address.Zip; calEvent.AddressUrl += address.Country; calEvent.Location.Contact.Addresses.Add(address); } } if (ev.ReocurringEvent != null) calEvent.CalendarReoccurringId = ev.ReocurringEvent.CalendarItemId; calEvent.Name = ev.Name; calEvent.NameUrl = ServerConfig.WEBSITE_DEFAULT_LOCATION + "/roller-derby-event/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(ev.Name) + "/" + ev.CalendarItemId.ToString().Replace("-", ""); calEvent.TicketUrl = ev.TicketUrl; calEvent.CalendarItemId = ev.CalendarItemId; var avail = calEvent.Attendees.Where(x => x.MemberId == currentMemberId && x.Availability != AvailibilityEnum.None).FirstOrDefault(); if (avail != null) calEvent.HasCurrentMemberSetAvailability = true; var attend = calEvent.Attendees.Where(x => x.MemberId == currentMemberId && x.IsCheckedIn == true).FirstOrDefault(); if (attend != null) calEvent.IsCurrentMemberCheckedIn = true; if (ev.Color != null) { var c = Color.FromArgb(ev.Color.ColorIdCSharp); calEvent.ColorTempSelected = ColorTranslator.ToHtml(c); } if (!ev.IsInUTCTime) { calEvent.StartDate = ev.StartDate; calEvent.EndDate = ev.EndDate; } else { calEvent.StartDate = (ev.StartDate + new TimeSpan(ev.Calendar.TimeZone, 0, 0)); calEvent.EndDate = (ev.EndDate + new TimeSpan(ev.Calendar.TimeZone, 0, 0)); } calEvent.StartDateDisplay = calEvent.StartDate.ToShortDateString(); calEvent.EndDateDisplay = calEvent.EndDate.ToShortDateString(); calEvent.Link = ev.Link; if (!String.IsNullOrEmpty(ev.Link) && !ev.Link.Contains("http://") && !ev.Link.Contains("https://")) calEvent.Link = "http://" + ev.Link; else calEvent.Link = ev.Link; calEvent.Notes = ev.Notes; if (ev.LastModified > new DateTime(2013, 11, 23) || ev.Created > new DateTime(2013, 11, 23)) { calEvent.NotesHtml = ev.Notes; } else if (ev.Created < new DateTime(2013, 11, 23)) { if (!String.IsNullOrEmpty(ev.Notes)) { RDN.Library.Util.MarkdownSharp.Markdown markdown = new RDN.Library.Util.MarkdownSharp.Markdown(); markdown.AutoHyperlink = true; markdown.LinkEmails = true; calEvent.NotesHtml = HtmlSanitize.FilterHtmlToWhitelist(markdown.Transform(ev.Notes)).Replace("</p>", "</p><br/>"); } } //gc.Description = calEvent.Notes; gc.EndDate = calEvent.EndDate.ToUniversalTime(); gc.StartDate = calEvent.StartDate.ToUniversalTime(); gc.Website = calEvent.Link; gc.WebsiteName = calEvent.Link; gc.What = calEvent.Name; calEvent.AllowSelfCheckIn = ev.AllowSelfCheckIn; var isApartOfEvent = calEvent.MembersApartOfEvent.Where(x => x.MemberId == currentMemberId).FirstOrDefault(); if (calEvent.AllowSelfCheckIn && calEvent.IsCurrentMemberApartOfEvent || (calEvent.AllowSelfCheckIn && isApartOfEvent != null)) calEvent.CanCurrentUserCheckIn = true; } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return calEvent; }
private static StoreItem DisplayStoreItem(DataModels.Store.StoreItem storeItem, bool getAllReviews = false) { try { var item = new Classes.StoreItem(); item.CanPickUpLocally = storeItem.CanPickUpLocally; item.ArticleNumber = storeItem.ArticleNumber; item.CanRunOutOfStock = storeItem.CanRunOutOfStock; if (storeItem.Merchant.CurrencyRate == null) { item.Currency = "USD"; item.CurrencyCost = 1; } else { item.Currency = storeItem.Merchant.CurrencyRate.CurrencyAbbrName; item.CurrencyCost = storeItem.Merchant.CurrencyRate.CurrencyExchangePerUSD; } if (getAllReviews) { foreach (var b in storeItem.Reviews) { item.Reviews.Add(ItemReview.DisplayReviewList(b)); } } item.Description = storeItem.Description; item.Shipping = storeItem.ShippingCosts; item.ShippingAdditional = storeItem.ShippingCostsAdditional; item.Name = storeItem.Name; if (item.Name.Length > 21) item.NameTrimmed = item.Name.Remove(21) + "..."; else item.NameTrimmed = item.Name; item.Price = storeItem.Price; item.QuantityInStock = storeItem.QuantityInStock; item.StoreItemId = storeItem.StoreItemId; item.Weight = storeItem.Weight; if (storeItem.LastModified > new DateTime(2013, 11, 23) || storeItem.Created > new DateTime(2013, 11, 23)) { item.NoteHtml = storeItem.Note; } else if (storeItem.Created < new DateTime(2013, 11, 23)) { RDN.Library.Util.MarkdownSharp.Markdown markdown = new RDN.Library.Util.MarkdownSharp.Markdown(); markdown.AutoHyperlink = true; markdown.LinkEmails = true; item.NoteHtml = HtmlSanitize.FilterHtmlToWhitelist(markdown.Transform(storeItem.Note)).Replace("</p>", "</p><br/>"); } item.Note = storeItem.Note; item.IsPublished = storeItem.IsPublished; item.Store.MerchantId = storeItem.Merchant.MerchantId; item.AcceptsPayPal = storeItem.Merchant.AcceptPaymentsViaPaypal; item.AcceptsStripe = storeItem.Merchant.AcceptPaymentsViaStripe; item.Views = storeItem.Views.ToString("N0"); if (storeItem.Category != null) { item.Category.Name = storeItem.Category.Name; item.Category.StoreItemCategoryId = storeItem.Category.StoreItemCategoryId; } item.Store.Name = storeItem.Merchant.ShopName; if (!String.IsNullOrEmpty(storeItem.Merchant.ShopName) && storeItem.Merchant.ShopName.Length > 15) item.Store.NameTrimmed = storeItem.Merchant.ShopName.Remove(15) + "..."; else item.Store.NameTrimmed = storeItem.Merchant.ShopName; item.Store.Description = storeItem.Merchant.Description; item.Store.MerchantId = storeItem.Merchant.MerchantId; item.ItemType = (StoreItemTypeEnum)Enum.Parse(typeof(StoreItemTypeEnum), storeItem.ItemTypeEnum.ToString()); if (item.ItemType == StoreItemTypeEnum.Shirt) { item.ItemSize = (StoreItemShirtSizesEnum)Enum.Parse(typeof(StoreItemShirtSizesEnum), storeItem.SizesEnum.ToString()); item.ItemSizeEnum = storeItem.SizesEnum; } foreach (var photo in storeItem.Photos) { PhotoItem p = new PhotoItem(photo.ItemPhotoId, photo.ImageUrl, photo.ImageUrlThumb, photo.IsPrimaryPhoto, photo.AlternativeText); item.Photos.Add(p); } DisplayStoreItemColors(storeItem, item); return item; } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return null; }