/// <summary> /// approves the league and attaches owners and members to the league. /// </summary> /// <param name="id"></param> /// <returns></returns> public static bool ApproveLeague(string id) { int result = 0; try { Guid leagueId; var guidConversion = Guid.TryParse(id, out leagueId); if (!guidConversion) return false; var dc = new ManagementContext(); var pendingLeague = dc.LeaguePendings.Include("Creator").Include("Federation").Include("Country").FirstOrDefault(x => x.LeagueId.Equals(leagueId)); if (pendingLeague == null) return false; var contactCard = new DataModels.ContactCard.ContactCard(); var add = new Address { Country = pendingLeague.Country, StateRaw = pendingLeague.StateRaw, CityRaw = pendingLeague.CityRaw, TimeZone = pendingLeague.TimeZone }; var coords = OpenStreetMap.FindLatLongOfAddress(string.Empty, string.Empty, string.Empty, add.CityRaw, add.StateRaw, add.Country != null ? add.Country.Name : string.Empty); if (coords != null) { add.Coords = new System.Device.Location.GeoCoordinate(); add.Coords.Latitude = coords.Latitude; add.Coords.Longitude = coords.Longitude; add.Coords.Altitude = 0; add.Coords.Course = 0; add.Coords.HorizontalAccuracy = 1; add.Coords.Speed = 0; add.Coords.VerticalAccuracy = 1; } else { add.Coords = new System.Device.Location.GeoCoordinate(); add.Coords.Latitude = 0.0; add.Coords.Longitude = 0.0; add.Coords.Altitude = 0; add.Coords.Course = 0; add.Coords.HorizontalAccuracy = 1; add.Coords.Speed = 0; add.Coords.VerticalAccuracy = 1; } contactCard.Addresses.Add(add); contactCard.Emails.Add(new RDN.Library.DataModels.ContactCard.Email { EmailAddress = pendingLeague.ContactEmail, IsDefault = true }); if (!String.IsNullOrEmpty(pendingLeague.ContactTelephone)) { var communication = new DataModels.ContactCard.Communication(); communication.Data = pendingLeague.ContactTelephone; communication.IsDefault = true; //int comType = Convert.ToInt32(CommunicationTypeEnum.PhoneNumber); //communication.CommunicationType = dc.CommunicationType.Where(x => x.CommunicationTypeId == comType).FirstOrDefault(); communication.CommunicationTypeEnum = (byte)CommunicationTypeEnum.PhoneNumber; contactCard.Communications.Add(communication); } var league = new DataModels.League.League { ContactCard = contactCard, Name = pendingLeague.LeagueName, LoweredName = pendingLeague.LeagueName.ToLower(), SubscriptionPeriodEnds = DateTime.UtcNow.AddDays(InvoiceSubscription.NUMBER_OF_DAYS_FOR_TRIAL_SUBSCRIPTION), LeagueJoinCode = Guid.NewGuid(), SubscriptionWillAutoRenew = false }; //we clear it by hitting a URL setup to clear the cache. LeagueMember me = new LeagueMember(); me.League = league; me.Member = pendingLeague.Creator; me.MembershipDate = DateTime.UtcNow; me.LeagueOwnersEnums = (int)LeagueOwnersEnum.Owner; league.Members.Add(me); if (pendingLeague.Federation != null) { FederationLeague l = new FederationLeague(); l.Federation = pendingLeague.Federation; l.League = league; l.MembershipDate = DateTime.UtcNow; league.Federations.Add(l); } //league.Members.Add(pendingLeague.Creator); dc.Leagues.Add(league); result = dc.SaveChanges(); pendingLeague.Creator.CurrentLeagueId = league.LeagueId; result = dc.SaveChanges(); // var result = 1; if (result == 0) return false; Forum.Forum.CreateNewForum(league.LeagueId, ForumOwnerTypeEnum.league, league.Name + "'s Forum"); var defaultEmail = pendingLeague.Creator.ContactCard.Emails.FirstOrDefault(x => x.IsDefault.Equals(true)); if (defaultEmail != null) { var emailData = new Dictionary<string, string>(); emailData.Add("name", pendingLeague.Creator.Firstname); emailData.Add("derbyname", pendingLeague.Creator.DerbyName); emailData.Add("leaguename", pendingLeague.LeagueName); EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, defaultEmail.EmailAddress, EmailServer.EmailServer.DEFAULT_SUBJECT + " Your league has been approved", emailData, EmailServer.EmailServerLayoutsEnum.LeagueApproved); } try { WebClient client = new WebClient(); client.DownloadStringAsync(new Uri(ServerConfig.URL_TO_CLEAR_MEMBER_CACHE + pendingLeague.Creator.MemberId.ToString())); WebClient client1 = new WebClient(); client1.DownloadStringAsync(new Uri(ServerConfig.URL_TO_CLEAR_MEMBER_CACHE_API + pendingLeague.Creator.MemberId.ToString())); } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } dc.LeaguePendings.Remove(pendingLeague); result = dc.SaveChanges(); } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return result != 0; }
/// <summary> /// approves the league for federation purposes. /// </summary> /// <param name="id"></param> /// <returns></returns> public static bool ApproveLeagueForFederation(string id) { Guid leagueId; var guidConversion = Guid.TryParse(id, out leagueId); if (!guidConversion) return false; var dc = new ManagementContext(); var pendingLeague = dc.LeaguePendings.Include("Creator").Include("Federation").Include("Country").FirstOrDefault(x => x.LeagueId.Equals(leagueId)); if (pendingLeague == null) return false; var contactCard = new DataModels.ContactCard.ContactCard(); var add = new Address { Country = pendingLeague.Country, StateRaw = pendingLeague.StateRaw, CityRaw = pendingLeague.CityRaw, TimeZone = pendingLeague.TimeZone }; var coords = OpenStreetMap.FindLatLongOfAddress(string.Empty, string.Empty, string.Empty, add.CityRaw, add.StateRaw, add.Country != null ? add.Country.Name : string.Empty); if (coords != null) { add.Coords = new System.Device.Location.GeoCoordinate(); add.Coords.Latitude = coords.Latitude; add.Coords.Longitude = coords.Longitude; add.Coords.Altitude = 0; add.Coords.Course = 0; add.Coords.HorizontalAccuracy = 1; add.Coords.Speed = 0; add.Coords.VerticalAccuracy = 1; } contactCard.Addresses.Add(add); contactCard.Emails.Add(new RDN.Library.DataModels.ContactCard.Email { EmailAddress = pendingLeague.ContactEmail, IsDefault = true }); if (!String.IsNullOrEmpty(pendingLeague.ContactTelephone)) { var communication = new DataModels.ContactCard.Communication(); communication.Data = pendingLeague.ContactTelephone; communication.IsDefault = true; //int comType = Convert.ToInt32(CommunicationTypeEnum.PhoneNumber); //communication.CommunicationType = dc.CommunicationType.Where(x => x.CommunicationTypeId == comType).FirstOrDefault(); communication.CommunicationTypeEnum = (byte)CommunicationTypeEnum.PhoneNumber; contactCard.Communications.Add(communication); } var league = new DataModels.League.League { ContactCard = contactCard, Name = pendingLeague.LeagueName, LoweredName = pendingLeague.LeagueName.ToLower(), SubscriptionPeriodEnds = DateTime.UtcNow.AddDays(InvoiceSubscription.NUMBER_OF_DAYS_FOR_TRIAL_SUBSCRIPTION), SubscriptionWillAutoRenew = false }; if (pendingLeague.Federation != null) { FederationLeague l = new FederationLeague(); l.League = league; l.Federation = pendingLeague.Federation; l.MembershipDate = DateTime.UtcNow; league.Federations.Add(l); } //league.Members.Add(pendingLeague.Creator); dc.Leagues.Add(league); var result = dc.SaveChanges(); if (result == 0) return false; var membership = Membership.Providers["LeagueManagement"]; var roles = Roles.Providers["LeagueManagement"]; var user = membership.GetUser(pendingLeague.Creator.MemberId, false); //roles.AddUsersToRoles(new[] { user.UserName }, new[] { "League_President", "League_Member" }); var defaultEmail = pendingLeague.Creator.ContactCard.Emails.FirstOrDefault(x => x.IsDefault.Equals(true)); if (defaultEmail != null) { var emailData = new Dictionary<string, string>(); emailData.Add("name", pendingLeague.Creator.Firstname); emailData.Add("derbyname", pendingLeague.Creator.DerbyName); emailData.Add("leaguename", pendingLeague.LeagueName); EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, defaultEmail.EmailAddress, EmailServer.EmailServer.DEFAULT_SUBJECT + " Your league has been approved", emailData, EmailServer.EmailServerLayoutsEnum.LeagueApproved); } // ToDo: To be removed // var message = string.Format(@" // Hello {0} {1}, // The league '{2}' has now been created. You can now login and administer the league. // ", pendingLeague.Creator.Firstname, pendingLeague.Creator.DerbyName, pendingLeague.LeagueName); // SendEmail(, "ContactLeague creation successful", message); dc.LeaguePendings.Remove(pendingLeague); result = dc.SaveChanges(); return result != 0; }
public static Portable.Classes.Location.Location CreateNewLocation(LocationOwnerType ownerType, string name, string address1, string address2, string city, int country, string state, string zip, string website, Guid idOfOwner) { Portable.Classes.Location.Location l = new Portable.Classes.Location.Location(); string log = string.Empty; try { var dc = new ManagementContext(); DataModels.Location.Location location = new DataModels.Location.Location(); if (ownerType == LocationOwnerType.calendar) { var cal = dc.Calendar.Where(x => x.CalendarId == idOfOwner).FirstOrDefault(); cal.Locations.Add(location); } else if (ownerType == LocationOwnerType.shop) { var shop = dc.Merchants.Where(x => x.PrivateManagerId == idOfOwner).FirstOrDefault(); shop.Locations.Add(location); } location.LocationName = name; location.Contact = new DataModels.ContactCard.ContactCard(); Address a = new Address(); a.Address1 = address1; a.Address2 = address2; a.CityRaw = city; a.Country = dc.Countries.Where(x => x.CountryId == country).FirstOrDefault(); a.StateRaw = state; a.ContactCard = location.Contact; var coords = OpenStreetMap.FindLatLongOfAddress(a.Address1, a.Address2, a.Zip, a.CityRaw, a.StateRaw, a.Country != null ? a.Country.Name : string.Empty); a.Coords = new System.Device.Location.GeoCoordinate(); if (coords != null) { log += "not" + coords.Latitude + " " + coords.Longitude; a.Coords.Latitude = coords.Latitude; a.Coords.Longitude = coords.Longitude; } else { a.Coords.Latitude = 0.0; a.Coords.Longitude = 0.0; } a.Coords.Altitude = 0.0; a.Coords.Course = 0.0; a.Coords.HorizontalAccuracy = 1.0; a.Coords.Speed = 0.0; a.Coords.VerticalAccuracy = 1.0; location.Contact.Addresses.Add(a); if (!String.IsNullOrEmpty(website)) { string comType = CommunicationTypeEnum.Website.ToString(); Communication web = new Communication(); web.Data = website; web.CommunicationTypeEnum = (byte)CommunicationTypeEnum.Website; location.Contact.Communications.Add(web); } dc.Locations.Add(location); int c = dc.SaveChanges(); l.LocationId = location.LocationId; l.LocationName = name; Portable.Classes.ContactCard.Address address = new Portable.Classes.ContactCard.Address(); address.Address1 = address1; address.Address2 = address2; address.CityRaw = city; if (a.Country != null) address.Country = a.Country.Name; address.StateRaw = a.StateRaw; address.Zip = a.Zip; l.Contact.Addresses.Add(address); } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType(), additionalInformation: name + " " + address1 + " " + address2 + " " + city + " " + country + " " + state + " " + zip + " " + website + " " + idOfOwner); } return l; }
/// <summary> /// updates the leagues basic information basically coming from a new user registering a new league. /// </summary> /// <param name="leagueId"></param> /// <param name="leagueName"></param> /// <param name="emailOfLeague"></param> /// <param name="phoneNumber"></param> /// <param name="city"></param> /// <param name="country"></param> /// <param name="state"></param> /// <param name="timezone"></param> public static bool UpdateLeagueForOwner(Guid leagueId, string leagueName, string emailOfLeague, string phoneNumber, string city, int country, string state, double timezone) { try { var dc = new ManagementContext(); var league = dc.Leagues.Include("Owners").Include("Teams").Include("Members").Include("ContactCard").Where(x => x.LeagueId == leagueId).FirstOrDefault(); league.Name = leagueName; league.SubscriptionPeriodEnds = DateTime.UtcNow.AddDays(InvoiceSubscription.NUMBER_OF_DAYS_FOR_TRIAL_SUBSCRIPTION); var emailDb = league.ContactCard.Emails.Where(x => x.IsDefault == true).FirstOrDefault(); if (emailDb != null) { emailDb.EmailAddress = emailOfLeague; } else { Email em = new Email(); em.ContactCard = league.ContactCard; em.EmailAddress = emailOfLeague; em.IsDefault = true; } var addresses = league.ContactCard.Addresses.Where(x => x.IsDefault == true).FirstOrDefault(); if (addresses != null) { addresses.CityRaw = city; addresses.StateRaw = state; var countryDb = dc.Countries.Where(x => x.CountryId == country).FirstOrDefault(); addresses.Country = countryDb; addresses.TimeZone = timezone; var coords = OpenStreetMap.FindLatLongOfAddress(addresses.Address1, addresses.Address2, addresses.Zip, addresses.CityRaw, addresses.StateRaw, addresses.Country != null ? addresses.Country.Name : string.Empty); if (coords != null) { addresses.Coords = new System.Device.Location.GeoCoordinate(); addresses.Coords.Latitude = coords.Latitude; addresses.Coords.Longitude = coords.Longitude; addresses.Coords.Altitude = 0; addresses.Coords.Course = 0; addresses.Coords.HorizontalAccuracy = 1; addresses.Coords.Speed = 0; addresses.Coords.VerticalAccuracy = 1; } } else if (league.ContactCard.Addresses.Count > 0) { addresses = league.ContactCard.Addresses.FirstOrDefault(); addresses.CityRaw = city; addresses.StateRaw = state; var countryDb = dc.Countries.Where(x => x.CountryId == country).FirstOrDefault(); addresses.Country = countryDb; addresses.TimeZone = timezone; addresses.IsDefault = true; var coords = OpenStreetMap.FindLatLongOfAddress(addresses.Address1, addresses.Address2, addresses.Zip, addresses.CityRaw, addresses.StateRaw, addresses.Country != null ? addresses.Country.Name : string.Empty); if (coords != null) { addresses.Coords = new System.Device.Location.GeoCoordinate(); addresses.Coords.Latitude = coords.Latitude; addresses.Coords.Longitude = coords.Longitude; addresses.Coords.Altitude = 0; addresses.Coords.Course = 0; addresses.Coords.HorizontalAccuracy = 1; addresses.Coords.Speed = 0; addresses.Coords.VerticalAccuracy = 1; } } else { Address add = new Address(); add.IsDefault = true; add.CityRaw = city; add.StateRaw = state; var countryDb = dc.Countries.Where(x => x.CountryId == country).FirstOrDefault(); add.Country = countryDb; add.TimeZone = timezone; add.IsDefault = true; var coords = OpenStreetMap.FindLatLongOfAddress(addresses.Address1, addresses.Address2, addresses.Zip, addresses.CityRaw, addresses.StateRaw, addresses.Country != null ? addresses.Country.Name : string.Empty); if (coords != null) { add.Coords = new System.Device.Location.GeoCoordinate(); add.Coords.Latitude = coords.Latitude; add.Coords.Longitude = coords.Longitude; add.Coords.Altitude = 0; add.Coords.Course = 0; add.Coords.HorizontalAccuracy = 1; add.Coords.Speed = 0; add.Coords.VerticalAccuracy = 1; } add.ContactCard = league.ContactCard; } var member = RDN.Library.Classes.Account.User.GetMember(); var emailData = new Dictionary<string, string> { { "name", leagueName }, { "leagueId", leagueId.ToString() }, { "email", emailOfLeague }, { "phone", phoneNumber }, { "country", country.ToString() }, { "memberId", member.MemberId.ToString() }, { "memberName", member.DerbyName} }; EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, ServerConfig.DEFAULT_INFO_EMAIL, EmailServer.EmailServer.DEFAULT_SUBJECT + " A league has found its owner", emailData, layout: EmailServer.EmailServerLayoutsEnum.OwnershipTakenOfLeague); dc.SaveChanges(); return true; } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return false; }
public static bool UpdateLeagueFromMobile(LeagueBase leagueToUpdate) { try { var dc = new ManagementContext(); var league = dc.Leagues.Include("ContactCard").Where(x => x.LeagueId == leagueToUpdate.LeagueId).FirstOrDefault(); league.Name = leagueToUpdate.Name; league.WebSite = leagueToUpdate.Website; league.Twitter = leagueToUpdate.Twitter; league.Instagram = leagueToUpdate.Instagram; league.Facebook = leagueToUpdate.Facebook; league.RuleSetsPlayedEnum = (long)leagueToUpdate.RuleSetsPlayedEnum; league.CultureLCID = leagueToUpdate.CultureSelected; if (leagueToUpdate.Founded != null && leagueToUpdate.Founded != new DateTime() && leagueToUpdate.Founded > DateTime.UtcNow.AddYears(-100)) league.Founded = leagueToUpdate.Founded; var emailDb = league.ContactCard.Emails.Where(x => x.IsDefault == true).FirstOrDefault(); if (emailDb != null) { emailDb.EmailAddress = leagueToUpdate.Email; } else { Email em = new Email(); em.ContactCard = league.ContactCard; em.EmailAddress = leagueToUpdate.Email; em.IsDefault = true; league.ContactCard.Emails.Add(em); } //int numberType = Convert.ToInt32(CommunicationTypeEnum.PhoneNumber); var phone = league.ContactCard.Communications.Where(x => x.CommunicationTypeEnum == (byte)CommunicationTypeEnum.PhoneNumber).FirstOrDefault(); if (phone != null) phone.Data = leagueToUpdate.PhoneNumber; else { Communication com = new Communication(); com.Data = leagueToUpdate.PhoneNumber; //com.CommunicationType = dc.CommunicationType.Where(x => x.CommunicationTypeId == numberType).FirstOrDefault(); com.CommunicationTypeEnum = (byte)CommunicationTypeEnum.PhoneNumber; com.ContactCard = league.ContactCard; com.IsDefault = true; league.ContactCard.Communications.Add(com); } var addresses = league.ContactCard.Addresses.Where(x => x.IsDefault == true).FirstOrDefault(); if (addresses == null) if (league.ContactCard.Addresses.Count > 0) addresses = league.ContactCard.Addresses.FirstOrDefault(); if (addresses == null) { addresses = new Address(); addresses.ContactCard = league.ContactCard; } addresses.CityRaw = leagueToUpdate.City; addresses.StateRaw = leagueToUpdate.State; addresses.Zip = leagueToUpdate.ZipCode; var countryDb = dc.Countries.Where(x => x.Name.ToLower() == leagueToUpdate.Country.ToLower()).FirstOrDefault(); if (countryDb == null) countryDb = dc.Countries.Where(x => x.Code.ToLower() == leagueToUpdate.Country.ToLower()).FirstOrDefault(); addresses.Country = countryDb; var coords = OpenStreetMap.FindLatLongOfAddress(addresses.Address1, addresses.Address2, addresses.Zip, addresses.CityRaw, addresses.StateRaw, addresses.Country != null ? addresses.Country.Name : string.Empty); if (coords != null) { addresses.Coords = new System.Device.Location.GeoCoordinate(); addresses.Coords.Latitude = coords.Latitude; addresses.Coords.Longitude = coords.Longitude; addresses.Coords.Altitude = 0; addresses.Coords.Course = 0; addresses.Coords.HorizontalAccuracy = 1; addresses.Coords.Speed = 0; addresses.Coords.VerticalAccuracy = 1; } addresses.IsDefault = true; int c = dc.SaveChanges(); return c > 0; } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return false; }
public static Guid CreateLeagueForImport(string leagueName, string country, string state, string city, double timeZone, string email, string telephoneNumber, Guid federationId) { int result = 0; try { var dc = new ManagementContext(); var count = dc.Countries.Where(x => x.CountryId == 0).FirstOrDefault(); var contactCard = new DataModels.ContactCard.ContactCard(); var add = new Address { Country = count, StateRaw = state, CityRaw = city, TimeZone = timeZone }; var coords = OpenStreetMap.FindLatLongOfAddress(add.Address1, add.Address2, add.Zip, add.CityRaw, add.StateRaw, add.Country != null ? add.Country.Name : string.Empty); if (coords != null) { add.Coords = new System.Device.Location.GeoCoordinate(); add.Coords.Latitude = coords.Latitude; add.Coords.Longitude = coords.Longitude; add.Coords.Altitude = 0; add.Coords.Course = 0; add.Coords.HorizontalAccuracy = 1; add.Coords.Speed = 0; add.Coords.VerticalAccuracy = 1; } contactCard.Addresses.Add(add); contactCard.Emails.Add(new RDN.Library.DataModels.ContactCard.Email { EmailAddress = email, IsDefault = true }); if (!String.IsNullOrEmpty(telephoneNumber)) { var communication = new DataModels.ContactCard.Communication(); communication.Data = telephoneNumber; communication.IsDefault = true; int comType = Convert.ToInt32(CommunicationTypeEnum.PhoneNumber); communication.CommunicationTypeEnum = (byte)CommunicationTypeEnum.PhoneNumber; contactCard.Communications.Add(communication); } var league = new DataModels.League.League { ContactCard = contactCard, Name = leagueName, LoweredName = leagueName.ToLower() }; //we clear it by hitting a URL setup to clear the cache. var fed = dc.Federations.Where(x => x.FederationId == federationId).FirstOrDefault(); FederationLeague fl = new FederationLeague(); fl.League = league; fl.Federation = fed; fed.Leagues.Add(fl); //league.Members.Add(pendingLeague.Creator); dc.Leagues.Add(league); result = dc.SaveChanges(); // var result = 1; return league.LeagueId; } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } return new Guid(); }