예제 #1
0
        public ActionResult Contact()
        {
            var infoContact = new ContentModel();
            infoContact = HgtCache.Get<ContentModel>(CONTENT_CONTACT_INFO_KEY);
            if (infoContact == null)
            {
                var contact = _contactService.Find((int)ContentType.Contact);
                infoContact = contact.ToModel();
                HgtCache.Insert(CONTENT_CONTACT_INFO_KEY, infoContact);
            }

            var model = new ContactModel() { Departments = GetAllDepartments() };
            ViewData["ContactInfo"] = infoContact.Value;
            model.CaptchaShow = _captchaShow;
            if (!_captchaShow)
            {
                model.Captcha = "captcha";
            }

            return View(model);
        }
예제 #2
0
        public ActionResult Contact(ContactModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            else
            {
                if (_captchaShow)
                {

                    if (!model.Captcha.ToLower().Equals(Session[ConstantKeys.CaptchaSession].ToString().ToLower()))
                    {
                        return Json(new { Status = ResultStatus.CaptchaInCorrect, Message = StringTable.CaptchaInCorrect });
                    }
                }

                string emailFrom = AppSettings.Settings.SMTPAccount;
                string emailCc = AppSettings.Settings.EmailOrder; // +"," + model.ContactEmail;
                string emailTo = AppSettings.Settings.CompanyEmail;

                var emailTemplateId = (int)EmailTemplateType.ContactForm;
                var emaiTemplate = _emailTemplateService.GetEmailByID(emailTemplateId);

                // get subject of email template
                var subject = emaiTemplate.Subject;

                // format body email
                string mailbody = emaiTemplate.Content;
                mailbody = mailbody.Replace(ConstantKeys.UserName, model.ContactName);
                mailbody = mailbody.Replace(ConstantKeys.FromEmail, model.ContactEmail);
                mailbody = mailbody.Replace(ConstantKeys.ContactPhone, model.ContactPhone);
                mailbody = mailbody.Replace(ConstantKeys.CompanyName, "<strong>Công ty:</strong> " + model.CompanyName);

                var department = GetAllDepartments().Where(x => x.Value == model.DepartmentId.ToString()).Select(x => x.Text).FirstOrDefault();
                mailbody = mailbody.Replace(ConstantKeys.Department, department);
                mailbody = mailbody.Replace(ConstantKeys.Content, model.ContactContent);
                mailbody = mailbody.Replace(ConstantKeys.CreatedDate, DateTime.Now.ToLongTimeString() + " - " + DateTime.Now.ToShortDateString());

                // send mail to email admin
                var status = SendMailUtility.SendMailWithOutCC(model.ContactName, "Liên hệ mới", mailbody, emailTo, emailCc);

                if (status)
                {
                    // save info sendmail
                    //string ip = System.Web.HttpContext.Current.Request.UserHostAddress;
                    //var emailqueues = new EmailQueue();
                    //emailqueues.EmailFrom = emailFrom;
                    //emailqueues.Department = department;
                    //emailqueues.Active = false;
                    //emailqueues.EmailTo = model.ContactEmail;
                    //emailqueues.EmailCc = emailFrom;
                    //emailqueues.EmailSubject = subject;
                    //emailqueues.SenderIP = ip;
                    //emailqueues.DisplayNameFrom = model.ContactName;
                    //emailqueues.PhoneContact = model.ContactPhone;
                    //emailqueues.EmailContact = model.ContactEmail;
                    //emailqueues.CompanyName = model.CompanyName;
                    //emailqueues.CreatedDate = DateTime.Now;
                    //emailqueues.UpdatedDate = DateTime.Now;

                    //_emailQueueService.Insert(emailqueues);
                    //_unitOfWork.SaveChanges();

                    return Json(new { Status = ResultStatus.Success, Message = "Gửi liên hệ thành công!" });
                }
                return Json(new { Status = ResultStatus.Fail, Message = "Gửi liên hệ không thành công!" });
            }
        }