Example #1
0
        public ActionResult EventCodeRecovery()
        {
            var model = new EventCodeRecoveryModel();

            model.Email = _workContext.CurrentCustomer.Username;
            return(View("~/Plugins/Cameleo.CameleoEvents/Views/CameleoEvents/EventCodeRecovery/EventCodeRecovery.cshtml", model));
        }
Example #2
0
        public ActionResult EventRecoverySend(EventCodeRecoveryModel model)
        {
            if (ModelState.IsValid)
            {
                //Get customer email address
                string email = model.Email.Trim();

                string fullName = model.FirstName + " " + model.LastName;

                //Message subject
                string subject = string.Format(_localizationService.GetResource("Plugins.Cameleo.CameleoEvents.EventCodeRecovery.EmailSubject"), _storeContext.CurrentStore.Name);

                //Email account to send message
                var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
                if (emailAccount == null)
                {
                    emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
                }
                if (emailAccount == null)
                {
                    // Can't get account
                    model.SuccessfullySent = false;
                    model.Result           = _localizationService.GetResource("Plugins.Cameleo.CameleoEvents.EventCodeRecovery.YourEnquiryHasNotBeenSent");

                    //activity log
                    _customerActivityService.InsertActivity("Plugins.Cameleo.CameleoEvents.EventCodeRecovery.Activity.Used", _localizationService.GetResource("Plugins.Cameleo.CameleoEvents.EventCodeRecovery.Activity.Used"));

                    return(View("~/Plugins/Cameleo.CameleoEvents/Views/CameleoEvents/EventCodeRecovery/EventCodeRecovery.cshtml", model));
                }

                //Else create message
                string from     = null;
                string fromName = null;
                string body     = Core.Html.HtmlHelper.FormatText(model.Notes, false, true, false, false, false, false);
                //required for some SMTP servers
                if (_commonSettings.UseSystemEmailForContactUsForm)
                {
                    from     = emailAccount.Email;
                    fromName = emailAccount.DisplayName;
                    body     = string.Format("<strong>From</strong>: {0} - {1}<br /><br />{2}<br /><br />{3}<br /><br />{4}",
                                             Server.HtmlEncode(fullName), Server.HtmlEncode(email), model.Event, model.Group, body);
                }
                else
                {
                    from     = email;
                    fromName = fullName;
                }

                //Send
                _queuedEmailService.InsertQueuedEmail(new QueuedEmail()
                {
                    From           = from,
                    FromName       = fromName,
                    To             = emailAccount.Email,
                    ToName         = emailAccount.DisplayName,
                    Priority       = 5,
                    Subject        = subject,
                    Body           = body,
                    CreatedOnUtc   = DateTime.UtcNow,
                    EmailAccountId = emailAccount.Id
                });

                model.SuccessfullySent = true;
                model.Result           = _localizationService.GetResource("Plugins.Cameleo.CameleoEvents.EventCodeRecovery.YourEnquiryHasBeenSent");

                //activity log
                _customerActivityService.InsertActivity("Plugins.Cameleo.CameleoEvents.EventCodeRecovery.Activity.Used", _localizationService.GetResource("Plugins.Cameleo.CameleoEvents.EventCodeRecovery.Activity.Used"));

                return(View("~/Plugins/Cameleo.CameleoEvents/Views/CameleoEvents/EventCodeRecovery/EventCodeRecovery.cshtml", model));
            }

            //If we got this far, something failed, redisplay form
            return(View("~/Plugins/Cameleo.CameleoEvents/Views/CameleoEvents/EventCodeRecovery/EventCodeRecovery.cshtml", model));
        }