public ActionResult Create2(int idee, bookyourdoctor.Models.gmailsent model) { hospital_view p = new hospital_view(); Hospital_request hospital_Request = db.Hospital_request.Find(idee); p.Hospital_day = hospital_Request.Hospital_day; p.patient_name = hospital_Request.patient_name; p.hospital_start_time = hospital_Request.Hospital_start_time; p.hospital_end_time = hospital_Request.hospital_end_time; db.hospital_view.Add(p); db.SaveChanges(); MailMessage mm = new MailMessage("*****@*****.**", ideee);//model.To ki jagah patient i mm.Subject = "APPOINTMENT STATUS"; model.Subject = mm.Subject; mm.Body = p.patient_name + "" + "Your request has been rejected" + ". " + "You need to come to the hospital at time" + "" + model.startTime + " " + "to" + model.endTime + "" + "on" + "" + p.Hospital_day; model.Body = mm.Body; mm.IsBodyHtml = false; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; smtp.Port = 587; NetworkCredential nc = new NetworkCredential("*****@*****.**", "maham180598"); smtp.UseDefaultCredentials = true; smtp.Credentials = nc; smtp.Send(mm); ViewBag.Message = "Mail has been sent successfully"; return(RedirectToAction("Index2", "Clinic_request")); //return RedirectToAction("Index1"); }
public ActionResult Create1(int idee, bookyourdoctor.Models.gmailsent model) { try { hospital_view p = new hospital_view(); Hospital_request hospital_Request = db.Hospital_request.Find(idee); p.Hospital_day = hospital_Request.Hospital_day; p.patient_name = hospital_Request.patient_name; p.hospital_start_time = hospital_Request.Hospital_start_time; p.hospital_end_time = hospital_Request.hospital_end_time; db.hospital_view.Add(p); db.SaveChanges(); MailMessage mm = new MailMessage("*****@*****.**", ideee);//model.To ki jagah patient i mm.Subject = "APPOINTMENT STATUS"; model.Subject = mm.Subject; mm.Body = p.patient_name + "" + "Your request has been rejected" + ". " + "You need to come to the hospital at time" + "" + model.startTime + " " + "to" + model.endTime + "" + "on" + "" + p.Hospital_day; model.Body = mm.Body; mm.IsBodyHtml = false; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; smtp.Port = 587; NetworkCredential nc = new NetworkCredential("*****@*****.**", "maham180598"); smtp.UseDefaultCredentials = true; smtp.Credentials = nc; smtp.Send(mm); ViewBag.Message = "Mail has been sent successfully"; } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } return(RedirectToAction("Index2", "Clinic_request")); }