コード例 #1
0
        public Object Save(OptInViewModel viewModel)
        {
            var contactRepository = new ContactRepository();
            var sourceRepository  = new SourceRepository();

            if (string.IsNullOrEmpty(botCheck))
            {
                try
                {
                    var source  = sourceRepository.FindByName(viewModel.oiSource);
                    var contact = new Contact
                    {
                        FirstName    = FirstName,
                        LastName     = LastName,
                        EmailAddress = EmailAddress,
                        SourceID     = source.ID,
                        Comments     = source.Notes,
                        SubmitDate   = DateTime.Now,
                        optIn        = true
                    };

                    contactRepository.InsertOrUpdate(contact);
                    contactRepository.Save();

                    new Email().SendRequestedDocument(contact, viewModel.oiDocument);
                }
                catch (Exception ex)
                {
                    throw ex;
                    return(false);
                }
                return(true);
            }
            return(false);
        }
コード例 #2
0
        //
        // Register for Webinar - Ajax partial postback
        public ActionResult Register(OptInViewModel viewModel)
        {
            var sourceRepository = new SourceRepository();

            if (ModelState.IsValid && string.IsNullOrEmpty(viewModel.botCheck))
            {
                try
                {
                    var contact = new Contact
                    {
                        FirstName    = viewModel.FirstName,
                        LastName     = viewModel.LastName,
                        EmailAddress = viewModel.EmailAddress,
                        SubmitDate   = DateTime.Now,
                        optIn        = true
                    };

                    var source = sourceRepository.FindByName("PCOS Webinar Opt-In");
                    contact.SourceID = source.ID;
                    contact.Comments = source.Notes;

                    contactRepository.InsertOrUpdate(contact);
                    contactRepository.Save();

                    var email          = new Email();
                    var emailViewModel = FormatEmail(contact);
                    email.InboundMessage(emailViewModel);

                    string docPath      = Server.MapPath("/Content/Documents/PCOSWebinarInstructions.htm");
                    var    instructions = MvcHtmlString.Create(System.IO.File.ReadAllText(docPath, System.Text.Encoding.UTF8));
                    email.SendWebinarInstructions(emailViewModel, instructions);
                }
                catch (Exception ex)
                {
                    base.ViewData["Exception"] = "Exception: " + ex.Message + " Stack Trace: " + ex.StackTrace;
                }
                return(RedirectToAction("Thanks"));
            }
            else
            {
                return(PartialView("_WebinarOptInPartial"));
            }
        }
コード例 #3
0
        public bool Save(PromoFormViewModel viewModel)
        {
            var promoRepository  = new PromoCodeRepository();
            var sourceRepository = new SourceRepository();

            var promoCode = new PromoCode
            {
                ID          = viewModel.ID,
                Code        = viewModel.Code,
                Name        = viewModel.Name,
                Description = viewModel.Description,
                Message     = viewModel.Message,
                Document    = viewModel.Document,
                StartDate   = DateTime.Parse(viewModel.StartDate),
                EndDate     = DateTime.Parse(viewModel.EndDate),
                Active      = viewModel.Active,
                Markup      = viewModel.Markup
            };

            var source = sourceRepository.FindByName(promoCode.Code + " Opt-In") ?? new Source
            {
                Name      = promoCode.Code + " Opt-In",
                Notes     = "Opt-In for " + promoCode.Code + " Promo Code",
                StartDate = promoCode.StartDate,
                EndDate   = promoCode.EndDate
            };

            try
            {
                sourceRepository.InsertOrUpdate(source);
                sourceRepository.Save();

                promoRepository.InsertOrUpdate(promoCode);
                promoRepository.Save();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }