using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using WebApplication1.DAL; using WebApplication1.Models; namespace WebApplication1.Controllers { public class StudentController : Controller { private _Student _Studdb; private _Student _Standarddb; public StudentController() { _Studdb = new Student(); _Standarddb = new Student(); } // GET: Student public ActionResult Index() { foreach (var item in _Studdb.GetModel()) { if (item.StandardId == "1") { item.strstandard = "Class A"; } else if (item.StandardId == "2") { item.strstandard = "Class B"; } } return View(_Studdb.GetModel()); } // GET: Student/Details/5 public ActionResult Details(int id) { Student dt = _Studdb.GetModelByID(id); return View(dt); } // GET: Student/Create public ActionResult Create() { List list = _Standarddb.GetModel().ToList(); ViewBag.List = new SelectList(list, "StandardId", "StandardName"); return View(); } // POST: Student/Create [HttpPost] public ActionResult Create(Student std) { try { // TODO: Add insert logic here _Studdb.InsertModel(std); _Studdb.save(); return RedirectToAction("Index"); } catch { return View(); } } // GET: Student/Edit/5 public ActionResult Edit(int id) { //foreach (var item in _Studdb.GetModel()) //{ // if (item.Mobile == item.Mobile) // { // item.editMobile = item.Mobile; // } //} List list = _Standarddb.GetModel().ToList(); ViewBag.List = new SelectList(list, "StandardId", "StandardName"); Student edit = _Studdb.GetModelByID(id); return View(edit); } // POST: Student/Edit/5 [HttpPost] public ActionResult Edit(Student edit) { try { // TODO: Add update logic here Student ed = _Studdb.GetModelByID(edit.StudentId); ed.FirstName = edit.FirstName; ed.LastName = edit.LastName; ed.Mobile = edit.Mobile; ed.StandardId = edit.StandardId; ed.RollNumber = edit.RollNumber; ed.Email = edit.Email; _Studdb.UpdateModel(ed); _Studdb.save(); return RedirectToAction("Index"); } catch { return View(); } } // GET: Student/Delete/5 public ActionResult Delete(int id) { Student delete = _Studdb.GetModelByID(id); return View(delete); } // POST: Student/Delete/5 [HttpPost] public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here _Studdb.DeleteModel(id); _Studdb.save(); return RedirectToAction("Index"); } catch { return View(); } } [HttpGet] public JsonResult IsMobileExist(string Mobile) { bool isExist = false; var data = _Studdb.GetModel().FirstOrDefault(x => x.Mobile == Mobile); isExist = (data != null) ? true : false; return Json(!isExist, JsonRequestBehavior.AllowGet); } //[HttpGet] //public JsonResult IsMobileExistonedit(string editMobile) //{ // bool isExist = false; // var data = _Studdb.GetModel().FirstOrDefault(x => x.Mobile == editMobile); // isExist = (data != null) ? true : false; // return Json(!isExist, JsonRequestBehavior.AllowGet); //} [HttpGet] public JsonResult IsEmailExist(string Email,string id) { bool isExist = false; var data = _Studdb.GetModel().FirstOrDefault(x => x.Email == Email); var em = _Studdb.GetModel().FirstOrDefault(x => x.StandardId == id); data = em; isExist = (data != null) ? true : false; return Json(!isExist, JsonRequestBehavior.AllowGet); } [HttpGet] public JsonResult IsClassandRollNoExist(string RollNumber, string StandardId) { bool isExist = false; var data = _Studdb.GetModel().FirstOrDefault(x => x.StandardId == StandardId && x.RollNumber == RollNumber); isExist = (data != null) ? true : false; return Json(!isExist, JsonRequestBehavior.AllowGet); } [HttpGet] public JsonResult IsRollNoandClassExist(string StandardId, string RollNumber) { bool isExist = false; var data = _Studdb.GetModel().FirstOrDefault(x => x.StandardId == StandardId && x.RollNumber == RollNumber); isExist = (data != null) ? true : false; return Json(!isExist, JsonRequestBehavior.AllowGet); } } }