public static ConfirmPayoutResult ConfirmPayout(string protoIdentity) { protoIdentity = HttpUtility.UrlDecode(protoIdentity); AuthenticationData authData = GetAuthenticationDataAndCulture(); if ( !authData.Authority.HasAccess(new Access(authData.CurrentOrganization, AccessAspect.Financials, AccessType.Write))) { throw new SecurityException("Insufficient privileges for operation"); } ConfirmPayoutResult result = new ConfirmPayoutResult(); Payout payout = Payout.CreateFromProtoIdentity(authData.CurrentUser, protoIdentity); PWEvents.CreateEvent(EventSource.PirateWeb, EventType.PayoutCreated, authData.CurrentUser.Identity, 1, 1, 0, payout.Identity, protoIdentity); // Create result and return it result.AssignedId = payout.Identity; result.DisplayMessage = String.Format(Resources.Pages.Financial.PayOutMoney_PayoutCreated, payout.Identity, payout.Recipient); return(result); }
protected void Page_Load(object sender, EventArgs e) { string attendeeIdString = Request.QueryString["AttendeeId"]; ParleyAttendee attendee = ParleyAttendee.FromIdentity(Int32.Parse(attendeeIdString)); Parley parley = attendee.Parley; string expectedSecurityCode = SHA1.Hash(attendee.PersonId.ToString() + parley.Identity.ToString()).Replace(" ", "").Substring(0, 8); if (attendee.Active) { this.LabelResult.Text = "This attendee has already been confirmed."; } else if (expectedSecurityCode == Request.QueryString["SecurityCode"]) { attendee.Active = true; PWEvents.CreateEvent(EventSource.SignupPage, EventType.ParleyAttendeeConfirmed, attendee.PersonId, parley.OrganizationId, parley.GeographyId, attendee.PersonId, attendee.Identity, string.Empty); this.LabelResult.Text = "Attendance has been confirmed. Thank you for registering for the conference, and have fun!"; } else { this.LabelResult.Text = "We were unable to match the attendee identity with the security code. No attendance was confirmed."; } }
static public void Run() { DateTime today = DateTime.Today; string lastRun = Persistence.Key["LastSalaryRun"]; string expectedLastRun = today.ToString("yyyyMM", CultureInfo.InvariantCulture); if (lastRun != null && String.Compare(lastRun, expectedLastRun) >= 0) { // nothing to do, return return; } Persistence.Key["LastSalaryRun"] = expectedLastRun; // Process the payroll for all organizations. Assume payday is 25th. Payroll payroll = Payroll.GetAll(); DateTime payday = new DateTime(today.Year, today.Month, 25); Dictionary <int, double> salariesTotalPerBudget = new Dictionary <int, double>(); foreach (PayrollItem payrollItem in payroll) { Salary salary = Salary.Create(payrollItem, payday); PWEvents.CreateEvent(EventSource.PirateBot, EventType.SalaryCreated, 0, payrollItem.OrganizationId, 0, payrollItem.Person.Identity, salary.Identity, string.Empty); } }
public static Parley Create(Organization organization, Person person, FinancialAccount budgetInitial, string name, Geography geography, string description, string informationUrl, DateTime startDate, DateTime endDate, Int64 budgetCents, Int64 guaranteeCents, Int64 attendanceFeeCents) { Parley newParley = FromIdentity(SwarmDb.GetDatabaseForWriting().CreateParley(organization.Identity, person.Identity, -(budgetInitial.Identity), name, geography.Identity, description, informationUrl, startDate, endDate, budgetCents, guaranteeCents, attendanceFeeCents)); PWEvents.CreateEvent(EventSource.PirateWeb, EventType.ParleyCreated, person.Identity, organization.Identity, 0, 0, newParley.Identity, string.Empty); return(newParley); }
public void SendInvoice() { DateTime invoiceDue = DateTime.Today.AddDays(14); DateTime maxInvoiceDue = this.Parley.StartDate.AddDays(-10); if (invoiceDue > maxInvoiceDue) { invoiceDue = maxInvoiceDue; } OutboundInvoice invoice = OutboundInvoice.Create(this.Parley.Organization, this.Parley.Person, invoiceDue, this.Parley.Budget, this.Person.Name, this.Person.Mail, string.Empty, this.Parley.Organization.DefaultCountry.Currency, true, string.Empty); invoice.AddItem("Deltagarkostnad " + this.Parley.Name, this.Parley.AttendanceFeeCents); // TODO: Localize ParleyOptions options = this.Options; foreach (ParleyOption option in options) { invoice.AddItem(option.Description, option.AmountCents); } // Create the financial transaction with rows FinancialTransaction transaction = FinancialTransaction.Create(this.Parley.OrganizationId, DateTime.Now, "Outbound Invoice #" + invoice.Identity + " to " + this.Person.Name); transaction.AddRow(this.Parley.Organization.FinancialAccounts.AssetsOutboundInvoices, invoice.AmountCents, null); transaction.AddRow(this.Parley.Budget, -invoice.AmountCents, null); // Make the transaction dependent on the outbound invoice transaction.Dependency = invoice; // Create the event for PirateBot-Mono to send off mails PWEvents.CreateEvent(EventSource.PirateWeb, EventType.OutboundInvoiceCreated, this.PersonId, this.Parley.OrganizationId, 1, this.PersonId, invoice.Identity, string.Empty); // Update the attendee as invoiced base.Invoiced = true; base.OutboundInvoiceId = invoice.Identity; SwarmDb.GetDatabaseForWriting().SetParleyAttendeeInvoiced(this.Identity, invoice.Identity); }
public static Refund Create(Payment payment, Person creatingPerson, Int64 amountCents) { if (amountCents > payment.AmountCents) { throw new ArgumentException("Refund amount cannot exceed payment amount"); } Refund refund = FromIdentity(SwarmDb.GetDatabaseForWriting().CreateRefund(payment.Identity, creatingPerson.Identity, amountCents)); PWEvents.CreateEvent(EventSource.PirateWeb, EventType.RefundCreated, 0, refund.Payment.OutboundInvoice.Organization.Identity, Geography.RootIdentity, 0, refund.Identity, string.Empty); return(refund); }
public static Payment Create(PaymentGroup group, double amount, string reference, string fromAccount, string key, bool hasImage) { // Match against outbound invoice, too OutboundInvoice invoice = OutboundInvoice.FromReference(reference); // TODO: Verify that invoice is not already closed; if so, issue refund // TODO: Verify correct amount invoice.Open = false; PWEvents.CreateEvent(EventSource.PirateWeb, EventType.OutboundInvoicePaid, 0, group.Organization.Identity, Geography.RootIdentity, 0, invoice.Identity, string.Empty); return(FromIdentity(SwarmDb.GetDatabaseForWriting().CreatePayment(group.Identity, amount, reference, fromAccount, key, hasImage, invoice.Identity))); }
//public void Terminate () //{ // Terminate(EventSource.Unknown); //} public void Terminate(EventSource eventSource, Person actingPerson, string description) { // TODO: This needs a new overload for v5, which adds the Position and possibly removes the EventSource if (base.Active) { // REMOVED: everything Roles related; being phased out //PWLog.Write (actingPerson.Identity, PWLogItem.Person, Person.Identity, PWLogAction.MemberLost, // eventSource + ":" + description, string.Empty); PWEvents.CreateEvent(EventSource.PirateWeb, EventType.LostMember, actingPerson.Identity, OrganizationId, Person.GeographyId, Person.Identity, 0, OrganizationId.ToString()); //Added LogChurn here to make SURE they always are logged with the membership. if (PersonId > 0 && OrganizationId > 0 && base.Expires.IsDefined()) { ChurnData.LogChurn(PersonId, OrganizationId); } SwarmDb.GetDatabaseForWriting().TerminateParticipation(Identity); base.Active = false; base.DateTerminated = DateTime.Now; // Remove all newsletter subscriptions once the membership is terminated (to make sure default is now off and only turn off explicitly turned-on subscriptions) // HACK HACK HACK: uses feed IDs in an extremely ugly way to loop 1-9. Should use NewsletterFeeds.ForOrganization() once support for newsletters in different orgs are established. for (int newsletterFeedId = 1; newsletterFeedId < 10; newsletterFeedId++) { try { if (this._person.IsSubscribing(newsletterFeedId)) { this._person.SetSubscription(newsletterFeedId, false); } } catch (Exception) { // ignore nonexisting newsletter feeds -- this is a hack anyway } } } }
protected void Page_Load(object sender, EventArgs e) { string address = Request.QueryString["Address"]; Response.ContentType = "text/plain"; if (string.IsNullOrEmpty(address)) { Response.Write("No Address parameter (e.g. [email protected]) was given on the URL.\r\n"); return; } address = address.ToLowerInvariant(); string account = address.Substring(0, address.IndexOf('@')).Replace(".", " "); People candidates = People.FromNamePattern(account); bool found = false; foreach (Person candidate in candidates) { if (candidate.PartyEmail == address) { found = true; if (candidate.CryptoFingerprint.Length > 4) { Response.Write(candidate.CryptoFingerprint + "\r\nis the pubkey fingerprint for " + HttpUtility.HtmlEncode(candidate.Canonical) + ".\r\n"); } else { Response.Write("No key has been pregenerated for " + HttpUtility.HtmlEncode(candidate.Canonical) + ".\r\nA crypto key has been requested. Return in a few minutes to collect its pubkey fingerprint.\r\n"); PWEvents.CreateEvent(EventSource.PirateWeb, EventType.CryptoKeyRequested, 0, 0, 0, candidate.Identity, 0, string.Empty); } } } if (!found) { Response.Write("No person was found with the supplied address.\r\n"); } }
protected void ButtonGo_Click(object sender, EventArgs e) { Person candidate = Person.FromIdentity((int)ViewState[this.ClientID + "SelectedCandidate"]); Election.September2010.SetCandidateDocumented(Organization.PPSE, candidate); candidate.PersonalNumber = Formatting.CleanNumber(this.TextPersonalNumber.Text); candidate.Phone = Formatting.CleanNumber(this.TextPhone.Text); PWEvents.CreateEvent(EventSource.PirateWeb, EventType.CandidateDocumentationReceived, _currentUser.Identity, Organization.PPSEid, 1, candidate.Identity, Election.September2010.Identity, string.Empty); this.TextPersonalNumber.Text = string.Empty; this.TextPhone.Text = string.Empty; this.LabelBallots.Text = string.Empty; this.ComboCandidate.Text = string.Empty; this.LabelCandidateName.Text = "---"; Page.ClientScript.RegisterStartupScript(typeof(Page), "OkMessage", @"alert ('" + HttpUtility.HtmlEncode(candidate.Canonical + " är klarerad att gå till val.").Replace("'", "''") + "');", true); }
private void ProcessUpload() { string serverPath = @"C:\Data\Uploads\PirateWeb"; // TODO: Read from web.config foreach (Telerik.Web.UI.UploadedFile file in this.Upload.UploadedFiles) { string clientFileName = file.GetName(); string extension = file.GetExtension(); string base64 = Convert.ToBase64String(File.ReadAllBytes(serverPath + Path.DirectorySeparatorChar + file.GetName())); PWEvents.CreateEvent(EventSource.PirateWeb, EventType.FinancialDataUploaded, _currentUser.Identity, Int32.Parse(this.DropOrganizations.SelectedValue), Geography.RootIdentity, _currentUser.Identity, Int32.Parse(this.DropFilters.SelectedValue), base64); File.Delete(serverPath + Path.DirectorySeparatorChar + file.GetName()); Page.ClientScript.RegisterStartupScript(Page.GetType(), "alldone", "alert ('File " + file.GetName().Replace("'", "''") + " was sent for further processing using the " + this.DropFilters.SelectedItem.Text + " filter. You will receive mail and/or SMS when processing has completed.');", true); } }
protected void ButtonSignup_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; // no action } // Sign up this attendee, and create event to send confirmation mail ParleyAttendee newAttendee = _parley.CreateAttendee(this.TextNameFirst.Text, this.TextNameLast.Text, this.TextEmail.Text, false); // Add options ParleyOptions options = _parley.Options; foreach (ParleyOption option in options) { CheckBox checkOption = (CheckBox)this.PlaceholderOptions.FindControl("CheckOption" + option.Identity.ToString()); if (checkOption.Checked) { newAttendee.AddOption(option); } } PWEvents.CreateEvent(EventSource.SignupPage, EventType.ParleyAttendeeCreated, newAttendee.PersonId, _parley.OrganizationId, _parley.GeographyId, newAttendee.PersonId, newAttendee.Identity, string.Empty); if (Request.UserLanguages.Length > 0) { newAttendee.Person.PreferredCulture = Request.UserLanguages[0]; } this.PanelSignupCompleted.Visible = true; this.PanelSignup.Visible = false; }
private static void FetchBatchOfLogs(ref DateTime specificDate, ref DateTime yearLimit, List <int> idlist, Dictionary <int, List <BasicPWEvent> > personLogs) { Dictionary <int, List <BasicPWEvent> > eventRecs = PWEvents.ForPersons(idlist.ToArray(), new EventType[] { EventType.AddedMember, EventType.AddedMembership, EventType.ExtendedMembership }); List <BasicPWEvent> recs = null; foreach (List <BasicPWEvent> eventList in eventRecs.Values) { recs = new List <BasicPWEvent>(); foreach (BasicPWEvent evtRec in eventList) { if (evtRec.DateTime >= yearLimit.AddMonths(-1) && evtRec.DateTime < yearLimit.AddYears(1)) { int organizationId = 0; string parameterText = ""; switch (evtRec.EventType) { case EventType.AddedMember: { string[] split1 = ("" + evtRec.ParameterText).Split(','); if (split1.Length < 2) { split1 = new string[2]; split1[1] = FindIPForEventInLog(evtRec.DateTime, evtRec.AffectedPersonId, evtRec.ActingPersonId); } if (!string.IsNullOrEmpty(split1[0])) { string[] split2 = ("" + split1[0]).Split(' '); foreach (string orgnr in split2) { if (int.Parse(orgnr) != evtRec.OrganizationId) { organizationId = int.Parse(orgnr); parameterText = split1[0]; BasicPWEvent addR = new BasicPWEvent( evtRec.EventId, evtRec.DateTime, evtRec.Open, evtRec.ProcessedDateTime, evtRec.EventType, evtRec.EventSource, evtRec.ActingPersonId, evtRec.AffectedPersonId, organizationId, evtRec.GeographyId, evtRec.ParameterInt, parameterText); recs.Add(addR); } } } parameterText = split1[1]; BasicPWEvent addR2 = new BasicPWEvent( evtRec.EventId, evtRec.DateTime, evtRec.Open, evtRec.ProcessedDateTime, evtRec.EventType, evtRec.EventSource, evtRec.ActingPersonId, evtRec.AffectedPersonId, evtRec.OrganizationId, evtRec.GeographyId, evtRec.ParameterInt, parameterText); recs.Add(addR2); } break; case EventType.AddedMembership: { parameterText = FindIPForEventInLog(evtRec.DateTime, evtRec.AffectedPersonId, evtRec.ActingPersonId); BasicPWEvent addR2 = new BasicPWEvent( evtRec.EventId, evtRec.DateTime, evtRec.Open, evtRec.ProcessedDateTime, evtRec.EventType, evtRec.EventSource, evtRec.ActingPersonId, evtRec.AffectedPersonId, evtRec.OrganizationId, evtRec.GeographyId, evtRec.ParameterInt, parameterText); recs.Add(addR2); } break; case EventType.ExtendedMembership: { string[] split1 = ("" + evtRec.ParameterText).Split(' '); if (split1.Length < 1 || split1[0].Trim() == "") { if (split1.Length < 1) { split1 = new string[1]; } split1[0] = FindIPForEventInLog(evtRec.DateTime, evtRec.AffectedPersonId, evtRec.ActingPersonId); } if (split1.Length > 1) { foreach (string orgnr in split1) { if (orgnr.Length < 7 && int.Parse(orgnr) != evtRec.OrganizationId) { organizationId = int.Parse(orgnr); parameterText = split1[0]; BasicPWEvent addR = new BasicPWEvent( evtRec.EventId, evtRec.DateTime, evtRec.Open, evtRec.ProcessedDateTime, evtRec.EventType, evtRec.EventSource, evtRec.ActingPersonId, evtRec.AffectedPersonId, organizationId, evtRec.GeographyId, evtRec.ParameterInt, parameterText); recs.Add(addR); } } } parameterText = split1[0]; BasicPWEvent addR2 = new BasicPWEvent( evtRec.EventId, evtRec.DateTime, evtRec.Open, evtRec.ProcessedDateTime, evtRec.EventType, evtRec.EventSource, evtRec.ActingPersonId, evtRec.AffectedPersonId, evtRec.OrganizationId, evtRec.GeographyId, evtRec.ParameterInt, parameterText); recs.Add(addR2); } break; } } } if (recs.Count > 0) { personLogs[recs[0].AffectedPersonId] = recs; } } }
public void Attest(Person attester) { if (Attested) { return; } // If needed, create new account for parley FinancialAccount ourBudget; FinancialAccount parentBudget; int year = DateTime.Today.Year; if (base.BudgetId < 0) // no account created yet { ourBudget = FinancialAccount.Create(Budget.Organization, "Conf: " + Name, FinancialAccountType.Cost, Budget); parentBudget = Budget; base.BudgetId = ourBudget.Identity; ourBudget.Owner = Person; SwarmDb.GetDatabaseForWriting().SetParleyBudget(Identity, ourBudget.Identity); } else { // The budget has been created already - we should already be initialized. Verify this // by checking that we were already attested once. if (!AttestedOnce) { throw new InvalidOperationException( "Budget exists despite parley not having been attested. This should not be possible."); } ourBudget = Budget; parentBudget = ParentBudget; } ourBudget.SetBudgetCents(DateTime.Today.Year, -BudgetCents); parentBudget.SetBudgetCents(DateTime.Today.Year, parentBudget.GetBudgetCents(year) + BudgetCents); // cost budgets are negative // Reserve the guarantee money FinancialTransaction guaranteeFundsTx = FinancialTransaction.Create(OrganizationId, DateTime.Now, "Conference #" + Identity + " Guarantee"); guaranteeFundsTx.AddRow(Budget, -GuaranteeCents, attester); guaranteeFundsTx.AddRow(Budget.Parent, GuaranteeCents, attester); // Finally, set as attested PWEvents.CreateEvent( EventSource.PirateWeb, EventType.ParleyAttested, attester.Identity, OrganizationId, 0, 0, Identity, string.Empty); base.Attested = true; SwarmDb.GetDatabaseForWriting().SetParleyAttested(Identity, true); SwarmDb.GetDatabaseForWriting().CreateFinancialValidation(FinancialValidationType.Attestation, FinancialDependencyType.Parley, Identity, DateTime.Now, attester.Identity, (double)(GuaranteeDecimal)); }
public OutboundInvoice Credit(Person creditingPerson) { OutboundInvoice credit = Create(Organization, DateTime.Now, Budget, CustomerName, InvoiceAddressMail, InvoiceAddressPaper, Currency, Domestic, TheirReference, creditingPerson); if (Domestic) // TODO: LANGUAGE { credit.AddItem("Kredit för faktura " + Reference, -AmountCents); credit.AddItem("DETTA ÄR EN KREDITFAKTURA OCH SKA EJ BETALAS", 0.00); AddItem( String.Format("KREDITERAD {0:yyyy-MM-dd} i kreditfaktura {1}", DateTime.Today, credit.Reference), 0.00); } else { credit.AddItem("Credit for invoice " + Reference, -AmountCents); credit.AddItem("THIS IS A CREDIT. DO NOT PAY.", 0.00); AddItem( String.Format("CREDITED {0:yyyy-MM-dd} in credit invoice {1}", DateTime.Today, credit.Reference), 0.00); } CreditInvoice = credit; credit.CreditsInvoice = this; credit.Open = false; // Create the financial transaction with rows FinancialTransaction transaction = FinancialTransaction.Create(credit.OrganizationId, DateTime.Now, "Credit Invoice #" + credit.Identity + " to " + credit.CustomerName); transaction.AddRow( Organization.FromIdentity(credit.OrganizationId).FinancialAccounts.AssetsOutboundInvoices, credit.AmountCents, creditingPerson); transaction.AddRow(credit.Budget, -credit.AmountCents, creditingPerson); // Make the transaction dependent on the credit transaction.Dependency = credit; // Create the event for PirateBot-Mono to send off mails PWEvents.CreateEvent(EventSource.PirateWeb, EventType.OutboundInvoiceCreated, creditingPerson.Identity, OrganizationId, Geography.RootIdentity, 0, credit.Identity, string.Empty); // If this invoice was already closed, issue a credit. If not closed, close it. if (Open) { Open = false; } else { Payment payment = Payment; if (payment != null) { payment.Refund(creditingPerson); } } return(credit); }
public void SetPaid() { Open = false; PWEvents.CreateEvent(EventSource.PirateWeb, EventType.OutboundInvoicePaid, 0, OrganizationId, Geography.RootIdentity, 0, Identity, string.Empty); }
//public void Terminate () //{ // Terminate(EventSource.Unknown); //} public void Terminate(EventSource eventSource, Person actingPerson, string description) { if (base.Active) { //Added removal of Roles here to make SURE they always are removed with the membership. Authority authority = Person.GetAuthority(); int actingPersonId = actingPerson == null ? 0 : actingPerson.Identity; BasicPersonRole[] roles = authority.AllPersonRoles; List <PersonRole> theRoles = new List <PersonRole>(); foreach (BasicPersonRole basicRole in roles) { PersonRole personRole = PersonRole.FromBasic(basicRole); theRoles.Add(personRole); if (personRole.OrganizationId == OrganizationId) { PWEvents.CreateEvent(eventSource, EventType.DeletedRole, actingPersonId, personRole.OrganizationId, personRole.GeographyId, Person.Identity, (int)personRole.Type, string.Empty); PWLog.Write(actingPersonId, PWLogItem.Person, Person.Identity, PWLogAction.RoleDeleted, "Role " + personRole.Type + " of " + personRole.Geography.Name + " was deleted with membership.", string.Empty); personRole.Delete(); } } //now check if this means that you no longer are a member of some uplevel org, then remove those roles as well foreach (PersonRole personRole in theRoles) { if (!Person.MemberOfWithInherited(personRole.Organization)) { PWEvents.CreateEvent(eventSource, EventType.DeletedRole, actingPersonId, personRole.OrganizationId, personRole.GeographyId, Person.Identity, (int)personRole.Type, string.Empty); PWLog.Write(actingPersonId, PWLogItem.Person, Person.Identity, PWLogAction.RoleDeleted, "Role " + personRole.Type + " of " + personRole.Geography.Name + " was deleted with membership of all suborgs.", string.Empty); personRole.Delete(); } } EventSource src = EventSource.PirateWeb; try { if (HttpContext.Current == null) { src = EventSource.PirateBot; } } catch { src = EventSource.PirateBot; } PWLog.Write(actingPersonId, PWLogItem.Person, Person.Identity, PWLogAction.MemberLost, eventSource + ":" + description, string.Empty); PWEvents.CreateEvent(src, EventType.LostMember, actingPersonId, OrganizationId, Person.GeographyId, Person.Identity, 0, OrganizationId.ToString()); //Added LogChurn here to make SURE they always are logged with the membership. if (PersonId > 0 && OrganizationId > 0 && base.Expires != new DateTime(1900, 1, 1)) { ChurnData.LogChurn(PersonId, OrganizationId); } SwarmDb.GetDatabaseForWriting().TerminateMembership(Identity); base.Active = false; base.DateTerminated = DateTime.Now; // Remove all newsletter subscriptions once the membership is terminated (to make sure default is now off and only turn off explicitly turned-on subscriptions) // HACK HACK HACK: uses feed IDs in an extremely ugly way to loop 1-9. Should use NewsletterFeeds.ForOrganization() once support for newsletters in different orgs are established. for (int newsletterFeedId = 1; newsletterFeedId < 10; newsletterFeedId++) { try { if (this.person.IsSubscribing(newsletterFeedId)) { this.person.SetSubscription(newsletterFeedId, false); } } catch (Exception) { // ignore nonexisting newsletter feeds -- this is a hack anyway } } } }
// This should run daily, suggested right after midnight. public static void ChurnExpiredMembers() { Organizations organizations = Organizations.GetAll(); foreach (Organization organization in organizations) { Memberships memberships = Memberships.GetExpired(organization); // Mail each expiring member foreach (Membership membership in memberships) { //only remove expired memberships if (membership.Expires > DateTime.Now.Date) { continue; } Person person = membership.Person; // Remove all roles and responsibilities for this person in the org Authority authority = person.GetAuthority(); foreach (BasicPersonRole basicRole in authority.LocalPersonRoles) { PersonRole personRole = PersonRole.FromBasic(basicRole); if (personRole.OrganizationId == membership.OrganizationId) { PWEvents.CreateEvent(EventSource.PirateBot, EventType.DeletedRole, person.Identity, personRole.OrganizationId, personRole.GeographyId, person.Identity, (int)personRole.Type, string.Empty); personRole.Delete(); } } // Mail Memberships personMemberships = person.GetMemberships(); Memberships membershipsToDelete = new Memberships(); foreach (Membership personMembership in personMemberships) { if (personMembership.Expires <= DateTime.Now.Date) { membershipsToDelete.Add(personMembership); } } ExpiredMail expiredmail = new ExpiredMail(); string membershipsIds = ""; if (membershipsToDelete.Count > 1) { foreach (Membership personMembership in membershipsToDelete) { membershipsIds += "," + personMembership.MembershipId; } membershipsIds = membershipsIds.Substring(1); string expiredMemberships = ""; foreach (Membership personMembership in membershipsToDelete) { if (personMembership.OrganizationId != organization.Identity) { expiredMemberships += ", " + personMembership.Organization.Name; } } expiredMemberships += ". "; expiredmail.pMemberships = expiredMemberships.Substring(2).Trim(); } //TODO: URL for renewal, recieving end of this is NOT yet implemented... // intended to recreate the memberships in MID string tokenBase = person.PasswordHash + "-" + membership.Expires.Year; string stdLink = "https://pirateweb.net/Pages/Public/SE/People/MemberRenew.aspx?MemberId=" + person.Identity + "&SecHash=" + SHA1.Hash(tokenBase).Replace(" ", "").Substring(0, 8) + "&MID=" + membershipsIds; expiredmail.pStdRenewLink = stdLink; expiredmail.pOrgName = organization.MailPrefixInherited; person.SendNotice(expiredmail, organization.Identity); person.DeleteSubscriptionData(); string orgIdString = string.Empty; foreach (Membership personMembership in membershipsToDelete) { if (personMembership.Active) { orgIdString += " " + personMembership.OrganizationId; personMembership.Terminate(EventSource.PirateBot, null, "Member churned in housekeeping."); } } } } }
public override bool Handle(PhoneMessage msg) { // renew memberships // if there is a third parameter it is the person# string[] smsParts = msg.Message.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int personId = 0; if (smsParts.Length > 2) { // personid is specified try { personId = Int32.Parse(smsParts[2]); PWEvents.CreateEvent(EventSource.CustomServiceInterface, EventType.ReceivedMembershipPayment, personId, Organization.PPSEid, 0, personId, 0, msg.Message.Replace(" ", "_") + "/" + msg.FromNumber); msg.ReplyMessage = "Det kommer strax ett e-mail som bekräftar förnyelsen."; return(true); // Handled; } catch (Exception) { msg.ReplyMessage += "Kunde inte tolka tredje parametern (medlemsnummer)."; msg.ErrorMessage += "Person# parameter not valid.\r\nHave replied: " + msg.ReplyMessage; } } else { // personid is NOT specified, base on phone number if (msg.People.Count > 0) { int countOfMembers = 0; Person person = null; foreach (BasicPerson bPerson in msg.People.Values) { person = Person.FromBasic(bPerson); if (person.GetRecentMemberships(Membership.GracePeriod).Count > 0) { countOfMembers++; } } if (countOfMembers == 1) { PWEvents.CreateEvent(EventSource.CustomServiceInterface, EventType.ReceivedMembershipPayment, person.PersonId, Organization.PPSEid, 0, personId, 0, msg.Message.Replace(" ", "_") + "/" + msg.FromNumber); msg.ReplyMessage = "Det kommer strax ett e-mail som bekräftar förnyelsen."; return(true); // Handled; } else { msg.ReplyMessage = "Misslyckades utföra åtgärden."; msg.ErrorMessage = "\r\nRequest to renew membership."; msg.ErrorMessage = "\r\nMultiple hits.\r\n\r\nHave replied:" + msg.ReplyMessage; } } else { msg.ReplyMessage = "Misslyckades utföra åtgärden: Vi kunde inte hitta ditt telefonnummer i vårt register."; msg.ErrorMessage = "\r\nRequest to renew membership."; msg.ErrorMessage = "\r\nDid not find the phone number in the database.\r\n\r\nHave replied:" + msg.ReplyMessage; } } return(false); }