Esempio n. 1
0
        /// <summary>
        /// NOTE: specified controller folder, as this may have been triggered by the surface controller
        /// </summary>
        /// <param name="renderModel"></param>
        /// <returns></returns>
        public override ActionResult Index(RenderModel renderModel)
        {
            RegisterHost model = (RegisterHost)renderModel.Content;

            if (this.Members.IsLoggedInPartier())
            {
                if (this.Members.GetCurrentMember() is PartyHost)
                {
                    PartyHost partyHost = (PartyHost)this.Members.GetCurrentMember();

                    if (!partyHost.HasRequestedPartyKit)
                    {
                        return(View("RegisterHost/RegisterHostPartyKit", model));
                    }

                    return(this.Redirect(partyHost.PartyUrl));
                }
                else
                {
                    // user already registered but not a host, so redirect back to home
                    return(this.Redirect(Home.GetCurrentHome(model).Url));
                }
            }

            //return View("RegisterHost", model);
            return(View("RegisterHost/RegisterHost", model));
        }
Esempio n. 2
0
        public ActionResult RenderDonateForm()
        {
            DonateForm donateForm = new DonateForm();

            // set hidden field with party guid
            donateForm.PartyGuid = ((Donate)this.CurrentPage).PartyHost.PartyGuid;

            PartyHost partyHost = this.Members.GetPartyHost(donateForm.PartyGuid);
            IPartier  partier   = this.Members.GetCurrentPartier();

            // set the default amount to the party host's suggested donation (only if user isn't the party host)
            if (partier is PartyHost && partier.Id == partyHost.Id)
            {
                donateForm.Amount = 0;
            }
            else
            {
                donateForm.Amount = partyHost.SuggestedDonation;
            }

            if (partier != null)
            {
                donateForm.FirstName = partier.FirstName;
                donateForm.LastName  = partier.LastName;

                donateForm.Address1 = partier.BillingAddress.Address1;
                donateForm.Address2 = partier.BillingAddress.Address2;
                donateForm.TownCity = partier.BillingAddress.TownCity;
                donateForm.Postcode = partier.BillingAddress.Postcode;
            }

            return(this.PartialView("Donate/Forms/DonateForm", donateForm));
        }
        public ActionResult RenderSuggestedDonationForm()
        {
            SuggestedDonationForm suggestedDonationForm = new SuggestedDonationForm();

            PartyHost partyHost = (PartyHost)this.Members.GetCurrentMember();

            suggestedDonationForm.SuggestedDonation = partyHost.SuggestedDonation;

            return(this.PartialView("Party/Forms/SuggestedDonationForm", suggestedDonationForm));
        }
        public ActionResult RenderFundraisingTargetForm()
        {
            FundraisingTargetForm fundraisingTargetForm = new FundraisingTargetForm();

            PartyHost partyHost = (PartyHost)this.Members.GetCurrentMember();

            fundraisingTargetForm.FundraisingTarget = partyHost.FundraisingTarget;

            return(this.PartialView("Party/Forms/FundraisingTargetForm", fundraisingTargetForm));
        }
Esempio n. 5
0
        private void ExportFinancialsButton_Click(object sender, EventArgs e)
        {
            StringBuilder stringBuilder = new StringBuilder();

            // headings
            stringBuilder.AppendLine(@"VpsTxId, VendorTxCode, Success, Member Id, Donor Email, Donor First Name, Donor Last Name, Donor Billing Address 1, Donor Billing Address 2, Donor Billing Town City, Donor Billing Postcode, Amount Donated, Date, Time, Gift Aid, Payment Journey, Opt In, Party Guid, Party Host Id, Party Host First Name, Party Host Last Name, Party Host Billing Address 1, Party Host Billing Address 2, Party Host Billing Town City, Party Host Billing Postcode");

            // get all db rows from wonderlandDonation
            foreach (DonationRow donationRow in this.DatabaseContext.Database.Fetch <DonationRow>("SELECT * FROM wonderlandDonation ORDER BY [Timestamp] DESC"))
            {
                PartyHost partyHost = this.Members.GetPartyHost(donationRow.PartyGuid);

                stringBuilder.AppendLine(
                    string.Join(
                        ", ",
                        new object[] {
                    donationRow.VPSTxId ?? string.Empty,                                                                                        //  1. VpsTxId
                    donationRow.VendorTxCode,                                                                                                   //  2. VendorTxCode
                    donationRow.Success ? "Y" : "N",                                                                                            //  3. Success
                    donationRow.MemberId,                                                                                                       //  4. Member Id
                    donationRow.MemberId.HasValue ? ((IPartier)this.Members.GetById(donationRow.MemberId.Value)).Email : string.Empty,          //  5. Donor Email
                    donationRow.FirstName.Replace(',', ' '),                                                                                    //  6. Donor First Name
                    donationRow.LastName.Replace(',', ' '),                                                                                     //  7. Donor Last Name
                    donationRow.Address1.Replace(',', ' '),                                                                                     //  8. Donor Billing Address 1
                    donationRow.Address2 != null ? donationRow.Address2.Replace(',', ' ') : string.Empty,                                       //  9. Donor Billing Address 2
                    donationRow.TownCity.Replace(',', ' '),                                                                                     // 10. Donor Billing Town City
                    donationRow.Postcode.Replace(',', ' '),                                                                                     // 11. Donor Billing Postcode
                    donationRow.Amount,                                                                                                         // 12. Amount Donated
                    donationRow.Timestamp.Date,                                                                                                 // 13. Date
                    donationRow.Timestamp.TimeOfDay,                                                                                            // 14. Time
                    donationRow.GiftAid ? "Y" : "N",                                                                                            // 15. Gift Aid
                    donationRow.PaymentJourney.ToString(),                                                                                      // 16. Payment Journey
                    "Y",                                                                                                                        // 17. Opt In
                    donationRow.PartyGuid,                                                                                                      // 18. Party Guid
                    partyHost.Id,                                                                                                               // 19. Party Host Id
                    partyHost.FirstName,                                                                                                        // 20. Party Host First Name
                    partyHost.LastName,                                                                                                         // 21. Party Host Last Name
                    partyHost.BillingAddress.Address1,                                                                                          // 22. Party Host Billing Address 1
                    partyHost.BillingAddress.Address2,                                                                                          // 23. Party Host Billing Address 2
                    partyHost.BillingAddress.TownCity,                                                                                          // 24. Party Host Billing Town City
                    partyHost.BillingAddress.Postcode                                                                                           // 25. Party Host Billing Postcode
                })
                    );
            }

            // steream out the response
            this.Response.Clear();
            this.Response.AddHeader("content-disposition", "attachment; filename=financials.csv");
            this.Response.ContentType     = "text/csv";
            this.Response.ContentEncoding = Encoding.UTF8;
            this.Response.Write(stringBuilder.ToString());
            this.Response.End();
        }
        public ActionResult RenderProfileTShirtSizeForm()
        {
            ProfileTShirtSizeForm profileTShirtSizeForm = new ProfileTShirtSizeForm();

            RegisterHost registerHost = (RegisterHost)this.Umbraco.TypedContentSingleAtXPath("//" + RegisterHost.Alias);

            this.ViewBag.TShirtSizes = registerHost.TShirtSizes;

            PartyHost partyHost = (PartyHost)this.Members.GetCurrentPartier();

            profileTShirtSizeForm.TShirtSize = partyHost.TShirtSize;

            return(this.PartialView("Profile/Forms/ProfileTShirtSizeForm", profileTShirtSizeForm));
        }
        public JsonResult HandlePartyDetailsForm(PartyDetailsForm partyDetailsForm)
        {
            FormResponse formResponse = new FormResponse();

            if (this.ModelState.IsValid)
            {
                PartyHost partyHost = (PartyHost)this.Members.GetCurrentMember();

                bool updateDotMailer = false;

                if (partyHost.PartyHeading != partyDetailsForm.PartyHeading)
                {
                    partyHost.PartyHeading = partyDetailsForm.PartyHeading;
                }

                if (partyHost.PartyDateTime != partyDetailsForm.PartyDateTime)
                {
                    partyHost.PartyDateTime = partyDetailsForm.PartyDateTime;

                    updateDotMailer = true;
                }

                Address address = new Address(
                    partyDetailsForm.Address1,
                    partyDetailsForm.Address2,
                    partyDetailsForm.TownCity,
                    partyDetailsForm.Postcode);

                if (partyHost.PartyAddress.ToString() != address.ToString())
                {
                    partyHost.PartyAddress = address;

                    updateDotMailer = true;
                }

                if (updateDotMailer)
                {
                    DotMailerService.UpdatePartyDetails(partyHost);
                }

                formResponse.Success = true;
            }
            else
            {
                formResponse.Errors = this.ModelState.GetErrors();
            }

            return(Json(formResponse, "text/plain"));
        }
        private void CheckPartyPageComplete(PartyHost partyHost)
        {
            if (!partyHost.DotMailerPartyPageComplete)
            {
                if (partyHost.PartyImage != null &&
                    partyHost.FundraisingTarget > 0 &&
                    !string.IsNullOrWhiteSpace(partyHost.PartyAddress.ToString()))
                {
                    partyHost.DotMailerPartyPageComplete = true;

                    // update the host to indicate that their party page is now complete
                    DotMailerService.UpdateContact((Contact)partyHost);
                }
            }
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            PartyServer server = new PartyServer("");

            string[] strs = Directory.GetFiles(@"..\..\TestFiles\");
            string   sng  = strs[(new Random()).Next(0, strs.Length)];

            Console.WriteLine(sng);

            PartyHost host = new PartyHost(sng, server);

            PartyGuest guest = new PartyGuest(server);

            Console.Write("Press [Enter] to exit...");
            Console.Read();
        }
        public ActionResult RenderPartyDetailsForm()
        {
            PartyDetailsForm partyDetailsForm = new PartyDetailsForm();

            PartyHost partyHost = (PartyHost)this.Members.GetCurrentMember();

            partyDetailsForm.PartyHeading  = partyHost.PartyHeading;
            partyDetailsForm.PartyDateTime = partyHost.PartyDateTime;

            partyDetailsForm.Address1 = partyHost.PartyAddress.Address1;
            partyDetailsForm.Address2 = partyHost.PartyAddress.Address2;
            partyDetailsForm.TownCity = partyHost.PartyAddress.TownCity;
            partyDetailsForm.Postcode = partyHost.PartyAddress.Postcode;

            return(this.PartialView("Party/Forms/PartyDetailsForm", partyDetailsForm));
        }
        public ActionResult RenderRegisterHostPartyKitForm()
        {
            // get the renderModel for the current page
            RegisterHost model = (RegisterHost)this.CurrentPage;

            this.ViewBag.TShirtSizes = model.TShirtSizes;

            // set first / last name, as this will be available if user connected via facebook

            RegisterHostPartyKitForm registerHostPartyKitForm = new RegisterHostPartyKitForm();

            PartyHost partyHost = (PartyHost)this.Members.GetCurrentMember();

            registerHostPartyKitForm.FirstName = partyHost.FirstName;
            registerHostPartyKitForm.LastName  = partyHost.LastName;

            return(this.PartialView("RegisterHost/Forms/RegisterHostPartyKitForm", registerHostPartyKitForm));
        }
        public ActionResult HandleProfileTShirtSizeForm(ProfileTShirtSizeForm profileTShirtSizeForm)
        {
            FormResponse formResponse = new FormResponse();

            if (this.ModelState.IsValid)
            {
                PartyHost partyHost = (PartyHost)this.Members.GetCurrentPartier();

                partyHost.TShirtSize = profileTShirtSizeForm.TShirtSize;

                formResponse.Success = true;
            }
            else
            {
                formResponse.Errors = this.ModelState.GetErrors();
            }

            return(Json(formResponse, "text/plain"));
        }
        public ActionResult HandleRegisterHostPartyKitForm(RegisterHostPartyKitForm registerHostPartyKitForm)
        {
            if (!ModelState.IsValid)
            {
                return(this.CurrentUmbracoPage());
            }

            PartyHost partyHost = (PartyHost)this.Members.GetCurrentMember();

            if (partyHost.FirstName != registerHostPartyKitForm.FirstName)
            {
                partyHost.FirstName = registerHostPartyKitForm.FirstName;
            }

            if (partyHost.LastName != registerHostPartyKitForm.LastName)
            {
                partyHost.LastName = registerHostPartyKitForm.LastName;
            }

            Address address = new Address(
                registerHostPartyKitForm.Address1,
                registerHostPartyKitForm.Address2,
                registerHostPartyKitForm.TownCity,
                registerHostPartyKitForm.PostCode);

            partyHost.PartyKitAddress = address;
            partyHost.PartyAddress    = address;
            partyHost.BillingAddress  = address;

            partyHost.TShirtSize = registerHostPartyKitForm.TShirtSize;

            partyHost.HasRequestedPartyKit = true;

            // update contact in DotMailer
            DotMailerService.HostRegistrationCompleted((Contact)partyHost);

            // mark as completed
            partyHost.DotMailerRegistrationComplete = true;

            //return this.CurrentUmbracoPage();
            return(this.RedirectToCurrentUmbracoPage());
        }
        public JsonResult HandlePartyCopyForm(PartyCopyForm partyCopyForm)
        {
            FormResponse formResponse = new FormResponse();

            if (this.ModelState.IsValid)
            {
                // change copy for current party host
                PartyHost partyHost = (PartyHost)this.Members.GetCurrentMember();

                partyHost.PartyCopy = partyCopyForm.Copy;

                formResponse.Success = true;
            }
            else
            {
                formResponse.Errors = this.ModelState.GetErrors();
            }

            return(Json(formResponse, "text/plain"));
        }
        public JsonResult HandleCustomPartyImageForm(CustomPartyImageForm customPartyImageForm)
        {
            FormResponse formResponse = new FormResponse();

            if (this.ModelState.IsValid && customPartyImageForm.CustomPartyImage.ContentLength > 0 && customPartyImageForm.CustomPartyImage.InputStream.IsImage())
            {
                PartyHost partyHost = (PartyHost)this.Members.GetCurrentMember();

                // get any existing party image
                IPartyImage partyImage = partyHost.PartyImage;

                string url = string.Empty;

                if (partyImage == null || partyImage is Image) // not set, or a cms default
                {
                    // create new custom party image
                    partyImage = PartyImages.CreatePartyImage(customPartyImageForm.CustomPartyImage);

                    // get new url
                    url = partyImage.Url;

                    // ensure reference
                    partyHost.PartyImage = partyImage;
                }
                else // if (partyImage is PartyImage) // it's already a custom image so update the file only within the same media item
                {
                    // update existing media item file reference
                    url = ((PartyImage)partyImage).UploadImage(customPartyImageForm.CustomPartyImage);
                }

                formResponse.Message = JsonConvert.SerializeObject(new { id = partyImage.Id, url = url }); //TODO:S3URL

                formResponse.Success = true;
            }

            return(Json(formResponse, "text/plain"));
        }
Esempio n. 16
0
        internal static void UpdatePartyDetails(PartyHost partyHost)
        {
            if (DotMailerEnabled)
            {
                // http://api.dotmailer.com/v2/api.svc#op.ApiService.ImportContacts

                StringBuilder stringBuilder = new StringBuilder();

                stringBuilder.AppendLine("Email, Party_Date, Party_Time, Party_Address_1, Party_Address_2, Party_Town_City, Party_Postcode");

                foreach (IPartier partier in new MembershipHelper(UmbracoContext.Current).GetPartiers(partyHost.PartyGuid))
                {
                    stringBuilder.AppendLine(
                        string.Join(
                            ", ",
                            new object[] {
                        partier.Email,
                        partyHost.PartyDateTime.ToString("dd/MM/yyyy"),
                        partyHost.PartyDateTime.ToString("HH:mm"),
                        partyHost.PartyAddress.Address1,
                        partyHost.PartyAddress.Address2,
                        partyHost.PartyAddress.TownCity,
                        partyHost.PartyAddress.Postcode
                    })
                        );
                }

                try
                {
                    DotMailerService.GetApiService().ImportContacts(Encoding.UTF8.GetBytes(stringBuilder.ToString()), "csv");
                }
                catch (Exception exception)
                {
                    LogHelper.Error(typeof(DotMailerService), "UpdatePartyDetails", exception);
                }
            }
        }
Esempio n. 17
0
        private void SendPaymentConfirmationEmail(DonationRow donationRow)
        {
            if (donationRow.MemberId.HasValue)
            {
                Donate donate = (Donate)this.Umbraco.TypedContentSingleAtXPath("//" + Donate.Alias);

                IPartier partier = (IPartier)this.Members.GetById(donationRow.MemberId.Value);

                PartyHost partyhost = this.Members.GetPartyHost(donationRow.PartyGuid);

                MailMessage mailMessage = new MailMessage();

                mailMessage.From = new MailAddress(donate.ServerEmailAddress);
                mailMessage.To.Add(new MailAddress(partier.Email));
                mailMessage.Subject    = donate.EmailSubject;
                mailMessage.IsBodyHtml = true;

                mailMessage.Body = donate.EmailBody
                                   .Replace("[%FIRST_NAME%]", partier.FirstName)
                                   .Replace("[%LAST_NAME%]", partier.LastName)
                                   .Replace("[%PARTY_HOST%]", partyhost.FirstName + " " + partyhost.LastName)
                                   .Replace("[%EMAIL%]", partier.Email)
                                   .Replace("[%AMOUNT%]", "£" + donationRow.Amount.ToString("F"))
                                   .Replace("[%DONATION_TIMESTAMP%]", donationRow.Timestamp.ToShortDateString())
                                   .Replace("[%VENDOR_TX_CODE%]", donationRow.VendorTxCode.ToString());

                // Fire and forget
                Task.Run(() =>
                {
                    using (SmtpClient smtpClient = new SmtpClient())
                    {
                        smtpClient.Send(mailMessage);
                    }
                });
            }
        }
        public FormResponse RegisterHost([FromBody] FacebookCredentials facebookCredentials)
        {
            FormResponse formResponse = new FormResponse();

            // using the supplied credentials query facebook to get email and names
            FacebookDetails facebookDetails = this.GetFacebookDetails(facebookCredentials);

            // no helper method on this.Members to register a user with a given memberType, so calling provider directly
            UmbracoMembershipProviderBase membersUmbracoMembershipProvider = (UmbracoMembershipProviderBase)Membership.Providers[Constants.Conventions.Member.UmbracoMemberProviderName];

            MembershipCreateStatus membershipCreateStatus;

            MembershipUser membershipUser = membersUmbracoMembershipProvider.CreateUser(
                PartyHost.Alias,                                                               // member type alias
                facebookDetails.EmailAddress,                                                  // username
                this.GetPassword(facebookDetails),                                             // password
                facebookDetails.EmailAddress,                                                  // email
                null,                                                                          // forgotten password question
                null,                                                                          // forgotten password answer
                true,                                                                          // is approved
                null,                                                                          // provider user key
                out membershipCreateStatus);

            if (membershipCreateStatus != MembershipCreateStatus.Success)
            {
                switch (membershipCreateStatus)
                {
                case MembershipCreateStatus.DuplicateEmail:
                case MembershipCreateStatus.DuplicateUserName:

                    this.ModelState.AddModelError("RegisterHostValidation", "Email already registered");

                    formResponse.Errors = this.ModelState.GetErrors();
                    break;
                }

                return(formResponse);
            }

            // cast from MembershipUser rather than use this.Members.GetCurrentMember() helper (which needs a round trip for the login)
            PartyHost partyHost = (PartyHost)membershipUser;

            partyHost.FacebookRegistration = true;

            partyHost.FirstName = facebookDetails.FirstName;
            partyHost.LastName  = facebookDetails.LastName;

            Guid partyGuid = Guid.NewGuid();

            this.DatabaseContext.Database.Insert(new PartyRow(partyGuid));

            // update database with member and party guid (duplicated data, but never changes)
            this.DatabaseContext.Database.Insert(new MemberPartyRow(partyHost.Id, partyGuid));

            // (duplicate data) store party guid in cms cache
            partyHost.PartyGuid = partyGuid;

            // set the default custom url to be the party guid
            partyHost.PartyUrlIdentifier = partyGuid.ToString();

            // set default party date
            partyHost.PartyDateTime = PartyHost.DefaultPartyDate;

            // add member to DotMailer
            DotMailerService.HostRegistrationStarted((Contact)partyHost);

            // send cookie
            FormsAuthentication.SetAuthCookie(partyHost.Username, true);

            formResponse.Success = true;

            formResponse.Message = this.Umbraco.TypedContentSingleAtXPath("//" + Wonderland.Logic.Models.Content.RegisterHost.Alias).Url;

            return(formResponse);
        }
Esempio n. 19
0
        private void AddDonationButton_Click(object sender, EventArgs e)
        {
            Guid partyGuid;

            if (Guid.TryParse(this.partyGuidTextBox.Text, out partyGuid))
            {
                // is the party known ?
                PartyHost partyHost = this.Members.GetPartyHost(partyGuid);

                if (partyHost != null)
                {
                    if (!string.IsNullOrWhiteSpace(partyHost.FirstName) &&
                        !string.IsNullOrWhiteSpace(partyHost.LastName) &&
                        !string.IsNullOrWhiteSpace(partyHost.BillingAddress.ToString()))
                    {
                        decimal amount;
                        if (decimal.TryParse(this.amountTextBox.Text, out amount))
                        {
                            // add row to wonderland donation
                            this.DatabaseContext.Database.Insert(
                                new DonationRow()
                            {
                                PartyGuid      = partyGuid,
                                Amount         = amount,
                                GiftAid        = this.giftAidCheckBox.Checked,
                                MemberId       = partyHost.Id,
                                FirstName      = partyHost.FirstName,
                                LastName       = partyHost.LastName,
                                Address1       = partyHost.BillingAddress.Address1,
                                Address2       = partyHost.BillingAddress.Address2,
                                TownCity       = partyHost.BillingAddress.TownCity,
                                Postcode       = partyHost.BillingAddress.Postcode,
                                PaymentJourney = PaymentJourney.Manual,
                                Success        = true
                            }
                                );

                            this.partyGuidTextBox.Text = string.Empty;
                            this.amountTextBox.Text    = string.Empty;
                            this.resultLiteral.Text    = "Added: £" + amount.ToString() + ", to Party: " + partyGuid.ToString();
                        }
                        else
                        {
                            this.resultLiteral.Text = "Invalid Amount";
                        }
                    }
                    else
                    {
                        this.resultLiteral.Text = "Missing Party Host Details";
                    }
                }
                else
                {
                    this.resultLiteral.Text = "Unknown Party";
                }
            }
            else
            {
                this.resultLiteral.Text = "Invalid Party Guid";
            }
        }
Esempio n. 20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="members"></param>
        /// <param name="leaderboardType"></param>
        /// <param name="take"></param>
        /// <returns></returns>
        public static IEnumerable <PartyHost> GetTopPartyHosts(this MembershipHelper members, LeaderboardType leaderboardType, int take)
        {
            List <PartyHost> partyHosts = new List <PartyHost>();

            PartyHost partyHost = null;

            DatabaseContext databaseContext = ApplicationContext.Current.DatabaseContext;

            switch (leaderboardType)
            {
            case LeaderboardType.MostGuests:

                foreach (dynamic mostGuest in databaseContext.Database.Fetch <dynamic>(@"
                                                                                            SELECT      TOP " + take + @"  
                                                                                                        PartyGuid,
                                                                                                        COUNT(MemberId) AS Partiers
                                                                                            FROM        wonderlandMemberParty
                                                                                            GROUP BY    PartyGuid
                                                                                            ORDER BY    Partiers DESC
                                                                                        "))
                {
                    partyHost = members.GetPartyHost((Guid)mostGuest.PartyGuid);

                    if (partyHost != null)
                    {
                        partyHost.TotalGuests = mostGuest.Partiers;
                        partyHosts.Add(partyHost);
                    }
                    else
                    {
                        LogHelper.Error(typeof(MembershipHelperExtensions), "GetTopPartyHosts", new Exception("Host with party guid: " + ((Guid)mostGuest.PartyGuid).ToString() + " not found in Examine"));
                    }
                }

                break;

            case LeaderboardType.TopFundraisers:

                foreach (dynamic topFundraiser in databaseContext.Database.Fetch <dynamic>(@"
                                                                                                SELECT      TOP " + take + @"
                                                                                                            PartyGuid,
                                                                                                            SUM(Amount) AS Amount
                                                                                                FROM        wonderlandDonation
                                                                                                WHERE       Success = 1
                                                                                                GROUP BY    PartyGuid
                                                                                                ORDER BY    Amount DESC
                                                                                            "))
                {
                    partyHost = members.GetPartyHost((Guid)topFundraiser.PartyGuid);

                    if (partyHost != null)
                    {
                        partyHost.AmountRaised = topFundraiser.Amount;
                        partyHosts.Add(partyHost);
                    }
                    else
                    {
                        LogHelper.Error(typeof(MembershipHelperExtensions), "GetTopPartyHosts", new Exception("Host with party guid: " + ((Guid)topFundraiser.PartyGuid).ToString() + " not found in Examine"));
                    }
                }

                break;
            }

            return(partyHosts);
        }
        public ActionResult HandleRegisterHostForm(RegisterHostForm registerHostForm)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.CurrentUmbracoPage());
            }

            // no helper method on this.Members to register a user with a given memberType, so calling provider directly
            UmbracoMembershipProviderBase membersUmbracoMembershipProvider = (UmbracoMembershipProviderBase)Membership.Providers[Constants.Conventions.Member.UmbracoMemberProviderName];

            MembershipCreateStatus membershipCreateStatus;

            MembershipUser membershipUser = membersUmbracoMembershipProvider.CreateUser(
                PartyHost.Alias,                                                                // member type alias
                registerHostForm.EmailAddress,                                                  // username
                registerHostForm.Password,                                                      // password
                registerHostForm.EmailAddress,                                                  // email
                null,                                                                           // forgotten password question
                null,                                                                           // forgotten password answer
                true,                                                                           // is approved
                null,                                                                           // provider user key
                out membershipCreateStatus);

            if (membershipCreateStatus != MembershipCreateStatus.Success)
            {
                switch (membershipCreateStatus)
                {
                case MembershipCreateStatus.DuplicateEmail:
                case MembershipCreateStatus.DuplicateUserName:

                    this.ModelState.AddModelError("RegisterHostValidation", "Email already registered");

                    break;
                }

                return(this.CurrentUmbracoPage());
            }

            // cast from MembershipUser rather than use this.Members.GetCurrentMember() helper (which needs a round trip for the login)
            PartyHost partyHost = (PartyHost)membershipUser;

            partyHost.FacebookRegistration = false;

            partyHost.MarketingSource = registerHostForm.MarketingSource;

            Guid partyGuid = Guid.NewGuid();

            this.DatabaseContext.Database.Insert(new PartyRow(partyGuid));

            // update database with member and party guid (duplicated data, but never changes)
            this.DatabaseContext.Database.Insert(new MemberPartyRow(partyHost.Id, partyGuid));

            // (duplicate data) store party guid in cms cache
            partyHost.PartyGuid = partyGuid;

            // set the default custom url to be the party guid
            partyHost.PartyUrlIdentifier = partyGuid.ToString();

            // set default party date
            partyHost.PartyDateTime = PartyHost.DefaultPartyDate;

            // add member to DotMailer
            DotMailerService.HostRegistrationStarted((Contact)partyHost);

            // send cookie
            FormsAuthentication.SetAuthCookie(partyHost.Username, true);

            // cause redirect, so that the login takes effect
            return(this.RedirectToCurrentUmbracoPage());
        }
        private void ExportRegistrationsButton_Click(object sender, EventArgs e)
        {
            StringBuilder stringBuilder = new StringBuilder();

            // headings
            stringBuilder.AppendLine("Member Id, Member Type, Email, First Name, Last Name, Heard About Us, Registration Date, Address 1, Address 2, Town, Postcode, T-Shirt Size, Party Guid, Party Title, Party DateTime, Party Address 1, Party Address 2, Party Town, Party Postcode, Join Wonderland Story, Party Background Image, Profile Photo, Fundraising Target, Suggested Donation, Guest Count, Amount Raised, Party Blocked, DotMailer Id, DotMailer Registration Complete, DotMailer Party Page Copmlete");

            foreach (IPartier partier in this.Members.GetAllPartiers())
            {
                if (partier is PartyHost)
                {
                    PartyHost partyHost = (PartyHost)partier;

                    stringBuilder.AppendLine(
                        string.Join(
                            ", ",
                            new object[] {
                        partier.Id,                                                                                             // 1.  Member Id
                        PartyHost.Alias,                                                                                        // 2.  Member Type
                        partier.Email.Replace(',', ' '),                                                                        // 3.  Email
                        partier.FirstName.Replace(',', ' '),                                                                    // 4.  First Name
                        partier.LastName.Replace(',', ' '),                                                                     // 5.  Last Name
                        partyHost.MarketingSource != null ? partyHost.MarketingSource.Replace(',', ' ') : string.Empty,         // 6.  Heard About Us
                        partyHost.CreateDate,                                                                                   // 7.  Registration Date
                        partier.BillingAddress.Address1.Replace(',', ' '),                                                      // 8.  Billing Address 1
                        partier.BillingAddress.Address2.Replace(',', ' '),                                                      // 9.  Billing Address 2
                        partier.BillingAddress.TownCity.Replace(',', ' '),                                                      // 10. Billing TownCity
                        partier.BillingAddress.Postcode.Replace(',', ' '),                                                      // 11. Billing Postcode
                        partyHost.TShirtSize,                                                                                   // 12. T-Shirt Size
                        partier.PartyGuid,                                                                                      // 13. Party Guid
                        partyHost.PartyHeading != null ? partyHost.PartyHeading.Replace(',', ' ') : string.Empty,               // 14. Party Title
                        partyHost.PartyDateTime,                                                                                // 15. Party DateTime
                        partyHost.PartyAddress.Address1.Replace(',', ' '),                                                      // 16. Party Address 1
                        partyHost.PartyAddress.Address2.Replace(',', ' '),                                                      // 17. Party Address 2
                        partyHost.PartyAddress.TownCity.Replace(',', ' '),                                                      // 18. Party TownCity
                        partyHost.PartyAddress.Postcode.Replace(',', ' '),                                                      // 19. Party Postcode
                        partyHost.PartyCopy != null ? partyHost.PartyCopy.Replace(',', ' ') : string.Empty,                     // 20. Join Wonderland Story
                        partyHost.PartyImage != null ? "Y" : "N",                                                               // 21. Party Background Image
                        partier.ProfileImage != null ? "Y" : "N",                                                               // 22. Profile Photo
                        partyHost.FundraisingTarget,                                                                            // 23. Fundraising Target
                        partyHost.SuggestedDonation,                                                                            // 24. Suggested Donation
                        this.Members.GetPartiers(partyHost.PartyGuid).Count(),                                                  // 25. Guest Count
                        partyHost.AmountRaised,                                                                                 // 26. Amount Raised
                        partyHost.Blocked ? "Y" : "N",                                                                          // 27. Party Blocked
                        partier.DotMailerId,                                                                                    // 28. DotMailer Id
                        partier.DotMailerRegistrationComplete ? "Y" : "N",                                                      // 29. DotMailer Registration Complete
                        partyHost.DotMailerPartyPageComplete ? "Y" : "N"                                                        // 30. DotMailer Party Page Complete
                    }
                            )
                        );
                }
                else // must be a guest
                {
                    PartyGuest partyGuest = (PartyGuest)partier;

                    stringBuilder.AppendLine(
                        string.Join(
                            ", ",
                            new object[] {
                        partier.Id,                                                                                     // 1.  Member Id
                        PartyGuest.Alias,                                                                               // 2.  Member Type
                        partier.Email.Replace(',', ' '),                                                                // 3.  Email
                        partier.FirstName.Replace(',', ' '),                                                            // 4.  First Name
                        partier.LastName.Replace(',', ' '),                                                             // 5.  Last Name
                        string.Empty,                                                                                   // 6.  Heard About Us
                        partyGuest.CreateDate,                                                                          // 7.  Registration Date
                        partier.BillingAddress.Address1.Replace(',', ' '),                                              // 8.  Billing Address 1
                        partier.BillingAddress.Address2.Replace(',', ' '),                                              // 9.  Billing Address 2
                        partier.BillingAddress.TownCity.Replace(',', ' '),                                              // 10. Billing TownCity
                        partier.BillingAddress.Postcode.Replace(',', ' '),                                              // 11. Billing Postcode
                        string.Empty,                                                                                   // 12. T-Shirt Size
                        partier.PartyGuid,                                                                              // 13. Party Guid
                        string.Empty,                                                                                   // 14. Party Title
                        string.Empty,                                                                                   // 15. Party DateTime
                        string.Empty,                                                                                   // 16. Party Address 1
                        string.Empty,                                                                                   // 17. Party Address 2
                        string.Empty,                                                                                   // 18. Party TownCity
                        string.Empty,                                                                                   // 19. Party Postcode
                        string.Empty,                                                                                   // 20. Join Wonderland Story
                        string.Empty,                                                                                   // 21. Party Background Image
                        partier.ProfileImage != null ? "Y" : "N",                                                       // 22. Profile Photo
                        string.Empty,                                                                                   // 23. Fundraising Target
                        string.Empty,                                                                                   // 24. Suggested Donation
                        string.Empty,                                                                                   // 25. Guest Count
                        string.Empty,                                                                                   // 26. Amount Raised
                        string.Empty,                                                                                   // 27. Party Blocked
                        partier.DotMailerId,                                                                            // 28. DotMailer Id
                        partier.DotMailerRegistrationComplete ? "Y" : "N",                                              // 29. DotMailer Registration Complete
                        string.Empty                                                                                    // 30. DotMailer Party Page Complete
                    }
                            )
                        );
                }
            }

            // steream out the response
            this.Response.Clear();
            this.Response.AddHeader("content-disposition", "attachment; filename=registrations.csv");
            this.Response.ContentType     = "text/csv";
            this.Response.ContentEncoding = Encoding.UTF8;
            this.Response.Write(stringBuilder.ToString());
            this.Response.End();
        }