コード例 #1
0
 public bool AddUserToMailingList(RequestMailingCommand command)
 {
     var input = new listSubscribeInput
                     {
                         api_Validate = true,
                         parms =
                             {
                                 // TODO: this id needs to come from a config file.
                                 id = "",
                                 // "Interested in MueVue List ID"
                                 email_address = command.Email,
                                 email_type = command.HtmlEmail ? EnumValues.emailType.html : EnumValues.emailType.text,
                                 apikey = MCAPISettings.default_apikey,
                                 double_optin = false,
                                 replace_interests = false,
                                 update_existing = true,
                                 merge_vars = new Dictionary<string, object>
                                              	{
                                              		{"OPTIN_IP", command.Ip},
                                              		{"OPTIN_TIME", DateTime.UtcNow.ToString()},
                                              		{"FNAME", command.FirstName},
                                              		{"LNAME", command.LastName}
                                              	},
                             },
                         api_AccessType = EnumValues.AccessType.Serial,
                         api_OutputType = EnumValues.OutputType.JSON
                     };
     var cmd = new listSubscribe(input);
     var output = cmd.Execute();
     bool mailingListSuccess = output.result;
     logger.Info(String.Format("MailChimp result - {0}, {1}", mailingListSuccess, output.api_ErrorMessages));
     return mailingListSuccess;
 }
コード例 #2
0
        public bool Process(RequestMailingCommand command, bool sendEmailNotice=true)
        {
            bool mailingListSuccess = false;
            bool mailSuccess =false;

            // TODO: create RequestMailingEvent, then RequestMailingEvent handler
            // TODO: Add Versant Database code here...
            try
            {
                var mailingListEntry = new MailingListEntry(Guid.NewGuid());

                mailingListSuccess = AddUserToMailingList(command);

                var e = new AddedToMailingList
                            {
                                StreamId = mailingListEntry.Id,
                                FirstName = command.FirstName,
                                LastName = command.LastName,
                                Email = command.Email
                            };

                MueVueEvents.Add(e);
                mailingListEntry.OnReceiving(e);
            }
            catch (Exception ex)
            {
                logger.Error("Failed to add new user to MailChimp", ex);
            }

            if (sendEmailNotice)
            {
                try
                {
                    logger.Debug("Calling SmtpMail.send()");
                    //SmtpMail.Send("*****@*****.**", "MailingList Request", command.ToString(), command.Email);
                    mailSuccess = true;
                }
                catch (Exception ex)
                {
                    logger.ErrorException("SmtpEmail.Send() failed: ", ex);
                    logger.Error("Failed to send email", ex);
                }
            }

            var success = mailingListSuccess || mailSuccess;

            logger.Info("MailingList - eventstore: {0}, mailing: {1}", mailingListSuccess, mailSuccess);
            logger.Info("Request: {0}", command.ToString());
            return success;
        }
コード例 #3
0
        // TODO: Add  Database code here...
        public bool Process(RequestInvitationCommand command)
        {
            bool inviteSuccess = false;
            bool mailSuccess = false;
            bool mailingListSuccess = false;

            var eventGuid = Guid.NewGuid();

            Logger.Debug("Received RequestMailing Commmand: {0}", command);

            try
            {
                var invitation = new Invitation(Guid.NewGuid());

                var e = new RequestInviteReceived(eventGuid)
                        {
                            StreamId = invitation.Id,
                            Email = command.Email,
                            ReceivedAt = DateTime.UtcNow,
                            Categories = command.Categories,
                            FirstName = command.FirstName,
                            LastName = command.LastName,
                            Location = command.Location,
                            Referral = command.Referral,
                            Phone = command.Phone,
                            BestTimeToReach = command.BestTimeToReach,
                            WhyAreYouInterested = command.WhyAreYouInterested
                        };

                //var configurationConnectionFactory = new ConfigurationConnectionFactory(MueVueConfig.MueVueEventsName);
                //var connection = configurationConnectionFactory.OpenMaster(e.StreamId);

                MueVueEvents.Add(e);
                invitation.OnReceiving(e);
                inviteSuccess = true;
            }
            catch (Exception ex)
            {
                Logger.Error("Saving invitationRequest to event store failed: ", ex);
            }

            if (command.JoinEmailList)
            {
                var requestMailingListCommand = new RequestMailingCommand
                                                    {
                                                        FirstName = command.FirstName,
                                                        LastName = command.LastName,
                                                        HtmlEmail = command.HtmlEmail,
                                                        Ip = command.Ip
                                                    };
                mailingListSuccess = CommandHandler.Process(requestMailingListCommand);
            }

            try
            {
                Logger.Debug("Calling SmtpMail.send()");
                //SmtpMail.Send("<xxx>", "Received Invitation Request", command.ToString(), command.Email,
                //    null, null, true, eventGuid, null);
                mailSuccess = true;
            }
            catch (Exception ex)
            {
                Logger.ErrorException("Calling SmtpMail.send() failed", ex);
                Logger.Error("Failed to send email", ex);
            }

            var success = inviteSuccess || mailSuccess;

            Logger.Info("RequestInvitation - eventstore: {0}, mailing: {1}, mailingList: {2}", inviteSuccess, mailSuccess, mailingListSuccess);
            Logger.Info("Request: {0}", command);
            return success;
        }