public JsonResult AddEnquiry(tblEnquiry objEnquiry) { try { if (objEnquiry != null) { db = new CourseDataContext(); tblEnquiry addenquiry = new tblEnquiry(); addenquiry.CandidateType = objEnquiry.CandidateType; addenquiry.Name = objEnquiry.Name; addenquiry.Mobile = objEnquiry.Mobile; addenquiry.Email = objEnquiry.Email; addenquiry.EnquiryType = objEnquiry.EnquiryType; addenquiry.Message = objEnquiry.Message; if (objEnquiry.EnquiryType == "Intern") { addenquiry.InternshipId = objEnquiry.InternshipId; } else if (objEnquiry.EnquiryType == "Course") { addenquiry.StudentCategoryId = objEnquiry.StudentCategoryId; addenquiry.CourseId = objEnquiry.CourseId; } addenquiry.DateCreated = DateTime.Now; addenquiry.CreatedBy = objEnquiry.Name; addenquiry.IsPublished = true; db.tblEnquiries.InsertOnSubmit(addenquiry); db.SubmitChanges(); SendOTPForEnqueryContactFAQ(objEnquiry.Name, objEnquiry.Email, "Enquiry", "EnquiryRes"); return(Json(addenquiry.EnquiryId, JsonRequestBehavior.AllowGet)); } return(Json("Failed", JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } }
public ActionResult Enquiry([Bind(Include = "Name,Phone,Email,RefferBy,Query,EnquiryId,CourseId ")] string name, string phone, string email, string RefferBy, tblEnquiry tblEnquiry) { if (tblEnquiry.Name != null) { MailMessage mail = new MailMessage(); mail.To.Add("*****@*****.**"); mail.From = new MailAddress("*****@*****.**"); mail.Subject = "Notification about Enquiry" + "*****@*****.**"; string userMessage = "<b>Some one wants to join<b><hr/>"; mail.Body = userMessage + "<b> Name:</b>" + name + "<br/>" + "<b>Phone no:</b>" + phone + "<br/>" + "<b>Email:</b>" + email + "<br/>" + "<b>Reffer by:</b>" + RefferBy + "<br/>"; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "betademo123"); smtp.EnableSsl = true; smtp.Send(mail); } if (ModelState.IsValid) { db.tblEnquiries.Add(tblEnquiry); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CourseId = new SelectList(db.tblCourses, "CourseId", "CourseName", tblEnquiry.CourseId); return(View(tblEnquiry)); }