// GET: Helpline public ActionResult Index() { HelplineModel ob = new HelplineModel(); ob.Faqs = GetFaqs(); return(View(ob)); }
public ActionResult Index(HelplineModel ob, HttpPostedFileBase file) { ViewBag.Message = "Message Sent Successfully ..."; SqlConnection con = new SqlConnection(constring); String q = "INSERT into Helpline(Name, Email,Phone,Subject,Message,imgid,Prescription,UserId ) " + "values(@Name,@Email,@Phone,@Subject,@Message,@imgid,@Prescription,@UserId)"; SqlCommand cmd = new SqlCommand(q, con); con.Open(); cmd.Parameters.AddWithValue("@Name", ob.Name); if (ob.Email != null) { cmd.Parameters.AddWithValue("@Email", ob.Email); } else { cmd.Parameters.AddWithValue("@Email", DBNull.Value); } cmd.Parameters.AddWithValue("@Phone", ob.Phone); cmd.Parameters.AddWithValue("@Subject", ob.Subject); cmd.Parameters.AddWithValue("@Message", ob.Message); cmd.Parameters.AddWithValue("@Prescription", ob.Prescription); if (file != null && file.ContentLength > 0) { string filename = Path.GetFileName(file.FileName); string imgpath = Path.Combine(Server.MapPath("/Prescriptions/"), filename); file.SaveAs(imgpath); } if (file != null) { cmd.Parameters.AddWithValue("@imgid", "/Prescriptions/" + file.FileName); } else { cmd.Parameters.AddWithValue("@imgid", DBNull.Value); } if (!string.IsNullOrEmpty(Session["userId"] as string)) { cmd.Parameters.AddWithValue("@UserId", Session["userId"].ToString()); } else { cmd.Parameters.AddWithValue("@UserId", DBNull.Value); } cmd.ExecuteNonQuery(); return(RedirectToAction("Index")); }