/// <summary> /// Deletes a contactus item /// </summary> /// <param name="contactus">ContactUs item</param> public virtual void DeleteContactUs(ContactUs contactus) { if (contactus == null) throw new ArgumentNullException("contactus"); _contactusRepository.Delete(contactus); //event notification _eventPublisher.EntityDeleted(contactus); }
public ActionResult ContactVendorSend(ContactVendorModel model, bool captchaValid) { if (!_vendorSettings.AllowCustomersToContactVendors) return RedirectToRoute("HomePage"); var vendor = _vendorService.GetVendorById(model.VendorId); if (vendor == null || !vendor.Active || vendor.Deleted) return RedirectToRoute("HomePage"); //validate CAPTCHA if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid) { ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService)); } model.VendorName = vendor.GetLocalized(x => x.Name); if (ModelState.IsValid) { string email = model.Email.Trim(); string fullName = model.FullName; string subject = _commonSettings.SubjectFieldOnContactUsForm ? model.Subject : string.Format(_localizationService.GetResource("ContactVendor.EmailSubject"), _storeContext.CurrentStore.GetLocalized(x => x.Name)); var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId); if (emailAccount == null) emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault(); if (emailAccount == null) throw new Exception("No email account could be loaded"); string from; string fromName; string body = Core.Html.HtmlHelper.FormatText(model.Enquiry, 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}", Server.HtmlEncode(fullName), Server.HtmlEncode(email), body); } else { from = email; fromName = fullName; } _queuedEmailService.InsertQueuedEmail(new QueuedEmail { From = from, FromName = fromName, To = vendor.Email, ToName = vendor.Name, ReplyTo = email, ReplyToName = fullName, Priority = QueuedEmailPriority.High, Subject = subject, Body = body, CreatedOnUtc = DateTime.UtcNow, EmailAccountId = emailAccount.Id }); model.SuccessfullySent = true; model.Result = _localizationService.GetResource("ContactVendor.YourEnquiryHasBeenSent"); //store in database if (_commonSettings.StoreInDatabaseContactUsForm) { var contactus = new ContactUs() { CreatedOnUtc = DateTime.UtcNow, CustomerId = _workContext.CurrentCustomer.Id, StoreId = _storeContext.CurrentStore.Id, VendorId = model.VendorId, Email = email, FullName = fullName, Subject = subject, Enquiry = body, EmailAccountId = emailAccount.Id, IpAddress = _webHelper.GetCurrentIpAddress() }; _contactUsService.InsertContactUs(contactus); } return View(model); } model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage; return View(model); }