Teacher Register Home Controller

[HttpPost]
public ActionResult tchregister(Teacher t, HttpPostedFileBase pic)
{
            int result = db.Teachers.Where(x => x.teacher_email == t.teacher_email).Count();
                if (result == 1)
                {
                    ViewBag.message = "This Email is already Registered. Please enter new Email.";
                    return View();
                }
                else
                {
                    if (pic == null)
                    {
                        t.teacher_pic = "~/content/pics/blank-profile-picture-973460_640.png";
                    }
                    else
                    {
                        string fullpath = Server.MapPath("~/content/pics/" + pic.FileName);
                        pic.SaveAs(fullpath);
                        t.teacher_pic = "~/content/pics/" + pic.FileName;
                    }

                db.Teachers.Add(t);
                db.SaveChanges();

                string from = "your email here";
                string to = t.teacher_email;
                MailMessage mail = new MailMessage(from, to);
                mail.Subject = "Registered Successfully";
                mail.Body = "<h5> Tutoronic </h5><br/>Hi Mr/Mrs  " + t.teacher_name + " <br/> you have successfully registered on tutoronic and will ready to teach students. In this way you can also earn revenue from your courses. ";
                mail.IsBodyHtml = true;
                SmtpClient server = new SmtpClient("smtp.gmail.com", 587);
                server.Credentials = new System.Net.NetworkCredential("your email here", "password");
                server.EnableSsl = true;
                server.Send(mail);


                Session["tch"] = t;
                return RedirectToAction("index", "teacher");
                
            }
            







           
}

Leave a Comment