public ActionResult AddNews(News data)
 {
     if (ModelState.IsValid)
     {
         db.TheNews.Add(new News()
         {
             Title       = data.Title,
             AddedDate   = data.AddedDate,
             NewsContent = data.NewsContent
         });
         db.SaveChanges();
     }
     return(RedirectToAction("DisplayNews"));
 }
        public HttpResponseMessage PostSaveAd(AdModel adModel)
        {
            if (ModelState.IsValid)
            {
                db.AdModels.Add(adModel);
                db.SaveChanges();

                try
                {
                    WebMail.SmtpServer = "smtp.gmail.com";
                    WebMail.SmtpPort   = 587;
                    WebMail.SmtpUseDefaultCredentials = true;
                    WebMail.EnableSsl = true;
                    //EmailId used to send emails from application
                    WebMail.UserName = "******";
                    WebMail.Password = "";

                    //Sender email address.
                    WebMail.From = "*****@*****.**";

                    //Send email
                    WebMail.Send(to: "*****@*****.**", subject: adModel.ContactName + " " + "has posted a new Ad.", body: adModel.Title + " " + adModel.ContactName + " " + adModel.Address + " " + adModel.MobileNo + " at " + DateTime.Now + ".", isBodyHtml: true);
                }
                catch (Exception)
                {
                    HttpResponseMessage msg = Request.CreateResponse("Problem while sending email, Please check details.");
                    return(msg);
                }

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, adModel);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = adModel.Id }));
                return(response);
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }