protected FinancialAccount SelectBudget(Geography geo) { //TODO: Greate a general funtion to select local budget based on geography int financialAccountId = 0; if (geo.Identity == 32 || geo.Inherits(32)) { financialAccountId = 18; } else if (geo.Identity == 33 || geo.Inherits(33)) { financialAccountId = 15; } else if (geo.Identity == 34 || geo.Inherits(34)) { financialAccountId = 17; } else if (geo.Identity == 35 || geo.Inherits(35)) { financialAccountId = 16; } else if (geo.Identity == 39 || geo.Inherits(39)) { financialAccountId = 19; } else { financialAccountId = 27; } return(FinancialAccount.FromIdentity(financialAccountId)); }
static public void Run() { MeetingElections polls = MeetingElections.GetAll(); foreach (MeetingElection poll in polls) { Console.Write("Looking at poll #" + poll.Identity.ToString() + "..."); if (DateTime.Now > poll.VotingCloses) { Console.Write(" after closedatetime " + poll.VotingCloses.ToString("yyyy-MM-dd HH:mm") + "..."); // Poll should be CLOSED, definitely CLOSED. if (poll.VotingOpen) { Console.WriteLine(" CLOSING."); poll.VotingOpen = false; // Closes poll poll.Creator.SendNotice("Poll Closed: " + poll.Name, string.Empty, poll.OrganizationId); Person.FromIdentity(1).SendNotice("Poll Closed: " + poll.Name, string.Empty, poll.OrganizationId); ReportPollResults(poll, false); } else { Console.WriteLine(" no action."); } } else if (DateTime.Now > poll.VotingOpens) { try { // Poll should be OPEN. Console.Write("after opendatetime " + poll.VotingOpens.ToString("yyyy-MM-dd HH:mm") + "..."); if (!poll.VotingOpen) { Console.WriteLine("OPENING for " + poll.Organization.Name + ":"); // Populate voters, then open for voting Organizations orgTree = poll.Organization.GetTree(); Memberships memberships = Memberships.ForOrganizations(orgTree); Dictionary <int, bool> dupeCheck = new Dictionary <int, bool>(); int count = 0; foreach (Membership membership in memberships) { Console.Write("\r - voters: {0:D6}/{1:D6} (person #{2:D6})...", ++count, memberships.Count, membership.PersonId); if (!membership.Active) { continue; // paranoid programming } if (!membership.Organization.IsOrInherits(poll.Organization)) { continue; // more paranoid programming } if (!dupeCheck.ContainsKey(membership.PersonId)) { if (membership.Person.GeographyId == 0) { // It's a trap! Console.Write(" GEOGRAPHY ZERO, ignoring\r\n"); } else { Geography geo = membership.Person.Geography; if (geo.Inherits(poll.GeographyId) || geo.Identity == poll.GeographyId) { poll.AddVoter(membership.Person); dupeCheck[membership.PersonId] = true; } } } } Console.WriteLine(" done."); Console.Write(" - opening poll..."); poll.VotingOpen = true; Console.WriteLine(" done."); Console.Write("Sending notices... "); string body = "Electoral roll for poll \"" + poll.Name + "\" primed. " + dupeCheck.Count.ToString() + " people can vote. The vote is now OPEN."; string subject = "Poll Open: " + poll.Name; poll.Creator.SendNotice(subject, body, poll.OrganizationId); Person.FromIdentity(1).SendNotice(subject, body, poll.OrganizationId); Console.WriteLine(" done."); } else { Console.WriteLine(" already open, no action."); // Report intermediate results to owner ReportPollResults(poll, true); } } catch (Exception exception) { Console.WriteLine(exception.ToString()); throw exception; } } } }
public bool HasLocalRoleAtOrganizationGeography(Organization organization, Geography geography, RoleType[] roleTypes, Authorization.Flag flags) { if (organization != null && organization.Identity == Organization.SandboxIdentity) { return(true); // UGLY UGLY HACK } if (organization == null && (flags & Authorization.Flag.AnyOrganization) == 0) { return(false); } if (geography == null && (flags & Authorization.Flag.AnyGeography) == 0) { return(false); } foreach (BasicPersonRole role in LocalPersonRoles) { foreach (RoleType type in roleTypes) { if (type == role.Type) { // Expensive op. The org/geo lookups need a cache at the logic layer. bool organizationClear = false; bool geographyClear = false; // First, check if the organization and geography match identically. if ((flags & Authorization.Flag.AnyOrganization) != 0) { // then it is used to check if they have a local role for any org organizationClear = true; } else if (organization != null && organization.Identity == role.OrganizationId) { organizationClear = true; } if ((flags & Authorization.Flag.AnyGeography) != 0) { // then it is used to check if they have a local role anywhere geographyClear = true; } else if (geography != null && geography.Identity == role.GeographyId) { geographyClear = true; } // If not clear, then check if there is inherited authority. if (!organizationClear && (flags & Authorization.Flag.ExactOrganization) == 0) { if (organization != null && organization.Inherits(role.OrganizationId)) { organizationClear = true; } } if (!geographyClear && (flags & Authorization.Flag.ExactGeography) == 0) { if (geography != null && geography.Inherits(role.GeographyId)) { geographyClear = true; } } // If both are ok, return that there is authority at this org & geo. if (organizationClear && geographyClear) { return(true); } } } } return(false); }
protected FinancialAccount SelectBudget (Geography geo) { //TODO: Greate a general funtion to select local budget based on geography int financialAccountId = 0; if (geo.Identity == 32 || geo.Inherits(32)) { financialAccountId = 18; } else if (geo.Identity == 33 || geo.Inherits(33)) { financialAccountId = 15; } else if (geo.Identity == 34 || geo.Inherits(34)) { financialAccountId = 17; } else if (geo.Identity == 35 || geo.Inherits(35)) { financialAccountId = 16; } else if (geo.Identity == 39 || geo.Inherits(39)) { financialAccountId = 19; } else { financialAccountId = 27; } return FinancialAccount.FromIdentity(financialAccountId); }