public ActionResult SupplyDeliveryQuote(int productId)
        {
            Product product = _productService.GetProductById(productId);
            SupplyDeliveryQuoteModel model = new SupplyDeliveryQuoteModel();

            if (product != null)
                model.ProductName = product.Name;

            return View(SUPPLY_DELIVERY_QUOTE_VIEW, model);
        }
        public ActionResult SupplyDeliveryQuote(SupplyDeliveryQuoteModel Model)
        {
            if (ModelState.IsValid)
            {
                bool successfullySent = SendFreeSampleMessage(Model);

                if (successfullySent)
                    return RedirectToAction("SupplyDeliveryQuoteSuccessful");
                else
                {
                    ModelState.AddModelError("", _localizationService
                        .GetResource("Plugin.Misc.FreeSample.ErrorOccured"));
                }
            }

            return View(SUPPLY_DELIVERY_QUOTE_VIEW, Model);
        }
        private IList<Token> GenerateTokens(SupplyDeliveryQuoteModel Model)
        {
            IList<Token> tokens = new List<Token>();

            string additionalMessage = string.IsNullOrWhiteSpace(Model.AdditionalInfo) ?
                "N/A" : Model.AdditionalInfo;
            string phone = string.IsNullOrWhiteSpace(Model.Phone) ?
                "N/A" : Model.Phone;
            
            string projectStage = GetProjectStageToken(Model);
            projectStage = string.IsNullOrWhiteSpace(projectStage) ? "N/A" : projectStage;

            _messageTokenProvider.AddStoreTokens(tokens);
            tokens.Add(new Token("SupplyDeliveryQuote.ProductName", Model.ProductName));
            tokens.Add(new Token("SupplyDeliveryQuote.Name", Model.Name));
            tokens.Add(new Token("SupplyDeliveryQuote.Email", Model.Email));
            tokens.Add(new Token("SupplyDeliveryQuote.Phone", phone));
            tokens.Add(new Token("SupplyDeliveryQuote.PostCode", Model.PostCode));
            tokens.Add(new Token("SupplyDeliveryQuote.Rooms", Model.Rooms.ToString()));
            tokens.Add(new Token("SupplyDeliveryQuote.Flooring", Model.Flooring.ToString()));
            tokens.Add(new Token("SupplyDeliveryQuote.ProjectStage", projectStage));
            tokens.Add(new Token("SupplyDeliveryQuote.AdditionalInfo", additionalMessage));

            if (Model.FreeCredit)
                tokens.Add(new Token("SupplyDeliveryQuote.FreeCredit", "Yes"));
            else
                tokens.Add(new Token("SupplyDeliveryQuote.FreeCredit", "No"));

            return tokens;
        }
 private string GetProjectStageToken(SupplyDeliveryQuoteModel Model)
 {
     if (Model.ProjectStageId == 1)
         return ("Just looking for price");
     if (Model.ProjectStageId == 2)
         return ("Within next 4 weeks");
     if (Model.ProjectStageId == 3)
         return ("Within next 3 months");
     if (Model.ProjectStageId == 4)
         return ("Within next 6 months");
     else
         return null;
 }
        private bool SendFreeSampleMessage(SupplyDeliveryQuoteModel Model)
        {
            MessageTemplate messageTemplate =
                GetLocalizedActiveMessageTemplate("SupplyDeliveryQuote.Form");

            if (messageTemplate == null)
                return false;

            EmailAccount sendTo = GetEmailAccountOfMessageTemplate(messageTemplate,
                _workContext.WorkingLanguage.Id);
            IList<Token> tokens = GenerateTokens(Model);

            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);
            return 0 != SendMessage(messageTemplate, Model.Name, Model.Email, sendTo,
                _workContext.WorkingLanguage.Id, tokens);
        }