public ActionResult OrderFreeSample(int productId) { Product product = _productService.GetProductById(productId); OrderFreeSampleModel model = new OrderFreeSampleModel(); if (product != null) model.ProductName = product.Name; return View(ORDER_FREE_SAMPLE_VIEW, model); }
public ActionResult OrderFreeSample(OrderFreeSampleModel Model) { if (ModelState.IsValid) { bool successfullySent = SendFreeSampleMessage(Model); if (successfullySent) return RedirectToAction("OrderFreeSampleSuccessful"); else { ModelState.AddModelError("", _localizationService .GetResource("Plugin.Misc.FreeSample.ErrorOccured")); } } return View(ORDER_FREE_SAMPLE_VIEW, Model); }
private IList<Token> GenerateTokens(OrderFreeSampleModel Model) { IList<Token> tokens = new List<Token>(); string additionalMessage = string.IsNullOrWhiteSpace(Model.CommentEnquiry) ? "N/A" : Model.CommentEnquiry; string company = string.IsNullOrWhiteSpace(Model.Company) ? "N/A" : Model.Company; _messageTokenProvider.AddStoreTokens(tokens); tokens.Add(new Token("FreeSample.ProductName", Model.ProductName)); tokens.Add(new Token("FreeSample.Name", Model.Name)); tokens.Add(new Token("FreeSample.Company", company)); tokens.Add(new Token("FreeSample.Address", Model.Address)); tokens.Add(new Token("FreeSample.PostCode", Model.PostCode)); tokens.Add(new Token("FreeSample.Phone", Model.Phone)); tokens.Add(new Token("FreeSample.Email", Model.Email)); tokens.Add(new Token("FreeSample.CommentEnquiry", additionalMessage)); /*if (Model.CHECKED) tokens.Add(new Token("FreeSample.CommentEnquiry", "CHEKBOX CHECKED")); else tokens.Add(new Token("FreeSample.CommentEnquiry", "CHEKBOX NOT CHECKED"));*/ return tokens; }
private bool SendFreeSampleMessage(OrderFreeSampleModel Model) { MessageTemplate messageTemplate = GetLocalizedActiveMessageTemplate("OrderFreeSample.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); }