public ActionResult Create( [Bind( Include = "Id,UniId,Name,Nickname,Password,SscRegistration,SscPassingYear,SscBoard,SscResult,HscRegistration,HscPassingYear,HscBoard,HscResult,FathersVoterId,FathersName,FathersDegignation,FathersContactNumber,FathersEmail,MothersVoterId,MothersName,MothersDegignation,MothersContactNumber,MothersEmail,File" )] Student student) { if (ModelState.IsValid) { if (student.File.ContentLength > 0) { var path = Path.Combine(Server.MapPath("~/Image/Student"), student.UniId+".jpg"); student.File.SaveAs(path); } LogIn aLogIn=new LogIn(); aLogIn.UserName = student.UniId; aLogIn.Password = student.Password; aLogIn.Category = "student"; student.File = null; db.Students.Add(student); db.Logins.AddOrUpdate(aLogIn); db.SaveChanges(); return RedirectToAction("Index"); } return View(student); }
public ActionResult LogIn(LogIn aLogIn) { //this action is for handle post method if (ModelState.IsValid)//this will check validity { using (Gateway db=new Gateway()) { var v = db.Logins.FirstOrDefault(a => a.UserName == aLogIn.UserName&&a.Password==aLogIn.Password); if (v!=null&&v.Category=="student") { Session["UserName"] = v.UserName.ToString(); return RedirectToAction("StudentAfterLogIn"); } else if (v != null && v.Category == "admin") { Session["UserName"] = v.UserName.ToString(); return RedirectToAction("AdminAfterLogIn"); } } } return View(aLogIn); }