Example #1
0
        public JsonResult SendMessage(string message, string name, string email)
        {
            var isValid = ((!string.IsNullOrWhiteSpace(message) || message.Length < 50)&&
                           (!string.IsNullOrWhiteSpace(name))&&
                           !string.IsNullOrWhiteSpace(email));
            isValid = isValid ? AccountHelper.ValidateEmail(email) : false;

            if (isValid)
            {
                try
                {
                    MailHelper mail = new MailHelper();
                    mail.SelfSendMailNoAttachment(string.Format("[GKNM] Message from: {0}", name), message, null);
                }
                catch
                {
                    return Json(new
                    {
                        sent = false,
                        error = "Không thể gửi tin nhắn cho hệ thống. Vui lòng refresh trang và thử lại hoặc liên hệ hotline với chúng tôi."
                    });
                }
            }

            return Json(new
            {
                sent = isValid,
                error = isValid ? "" : "Dữ liệu nhập không hợp lý. Vui lòng kiểm tra và thử lại."
            });
        }