public ActionResult addStudent(Student student) { var responce = Request["g-recaptcha-response"]; string secretKey = "6LdeyhUTAAAAAPm5v2eh-CafSM56oc8dsTHLtWkE"; var client = new WebClient(); var result = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secretKey, responce)); var obj = JObject.Parse(result); var status = (bool)obj.SelectToken("success"); ViewBag.Message = status ? "" : "Failed"; status = true; if (status) { bool ex_student = db.Students.Any(x => x.Email == student.Email||x.Phone==student.Phone); if (ex_student == false) { db.Students.AddOrUpdate(student); db.SaveChanges(); return RedirectToAction("AdminDashboard", "Dashboard"); } else { ViewBag.existMsg = "Student is already Exist!;"; return View(); } } else { ViewBag.Message = "Check This Box If u r not robot!:P"; return View(); } }
public ActionResult EditStudent(Student student) { db.Students.AddOrUpdate(student); db.SaveChanges(); return View("EditStudent"); }