public async Task <ActionResult> Create(StudentViewModel student, HttpPostedFileBase upload) { if (ModelState.IsValid) { Student std = new Student(); Userinfo user = new Userinfo(); if (db.Userinfoes.Find(student.username) != null) { ViewBag.userMsg = "Username already exist."; ViewBag.sessionID = new SelectList(db.Sessions, "sessionID", "name", student.sessionID); return(View(student)); } else if (student.password == null) { ViewBag.pswMsg = "Password can not be null"; ViewBag.sessionID = new SelectList(db.Sessions, "sessionID", "name", student.sessionID); return(View(student)); } else if (student.password != student.confirmPassword) { ViewBag.pswMsg = "Password are not same"; ViewBag.sessionID = new SelectList(db.Sessions, "sessionID", "name", student.sessionID); return(View(student)); } user.username = student.username; user.passwordHash = Cryptography.getMD5(student.password); user.token = Cryptography.getMD5(student.username) + Cryptography.getMD5(student.password); user.role = "student"; user.email = student.email; if (upload != null && upload.ContentLength > 0) { string path = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(student.rollNo + ".jpg")); upload.SaveAs(path); user.imagePath = "~/Images/" + student.rollNo + ".jpg"; } db.Userinfoes.Add(user); std.rollNo = student.rollNo; std.fullName = student.firstName; std.username = student.username; std.gender = student.gender; std.fatherName = student.fatherName; std.guardianID = student.guardianID; std.sessionID = student.sessionID; db.Students.Add(std); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } else { ViewBag.sessionID = new SelectList(db.Sessions, "sessionID", "name", student.sessionID); return(View(student)); } }
public async Task <ActionResult> Create(NewClass obj) { if (ModelState.IsValid) { Class @class = new Class(); try { @class.sectionID = int.Parse(Request.Form["section"].ToString()); } catch (Exception) { //@class.sectionID = -1; } @class.isMorning = obj.isMorning; @class.isSupply = obj.isSupply; @class.isTheory = obj.isTheory; @class.name = obj.name; @class.sessionID = obj.sessionID; //foreach (var item in obj.Students) //{ // if (item.Assigned) // { // @class.Students.Add(db.Students.Find(item.rollno)); // } //} db.Classes.Add(@class); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.sectionID = new SelectList(db.Sections, "sectionID", "name", obj.sectionID); ViewBag.sessionID = new SelectList(db.Sessions, "sessionID", "name", obj.sessionID); return(View(obj)); }
public async Task <ActionResult> Edit([Bind(Include = "guardianID,guardianName,relationship,mobileNumber")] Guardian guardian) { if (ModelState.IsValid) { db.Entry(guardian).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index", "Students")); } return(View(guardian)); }
public async Task <ActionResult> Create([Bind(Include = "courseCode,name,theoryHours,labHours")] Subject subject) { if (ModelState.IsValid) { db.Subjects.Add(subject); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(subject)); }
public async Task <ActionResult> Create([Bind(Include = "deptID,name,location")] Department department) { if (ModelState.IsValid) { db.Departments.Add(department); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(department)); }
public async Task <ActionResult> Create([Bind(Include = "dicipID,name,deptID,totalSemester")] Dicipline dicipline) { if (ModelState.IsValid) { db.Diciplines.Add(dicipline); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.deptID = new SelectList(db.Departments, "deptID", "name", dicipline.deptID); return(View(dicipline)); }
public async Task <ActionResult> Create([Bind(Include = "sessionID,name,dicipID,year")] Session session) { if (ModelState.IsValid) { db.Sessions.Add(session); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.dicipID = new SelectList(db.Diciplines, "dicipID", "name", session.dicipID); return(View(session)); }
public async Task <ActionResult> Create([Bind(Include = "teacherID,classID,courseCode,isCurrent")] Teacher_Course_Allocation teacher_Course_Allocation) { if (ModelState.IsValid) { db.Teacher_Course_Allocation.Add(teacher_Course_Allocation); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.classID = new SelectList(db.Classes, "classID", "name", teacher_Course_Allocation.classID); ViewBag.courseCode = new SelectList(db.Subjects, "courseCode", "name", teacher_Course_Allocation.courseCode); ViewBag.teacherID = new SelectList(db.Teachers, "teacherID", "name", teacher_Course_Allocation.teacherID); return(View(teacher_Course_Allocation)); }
public async Task <ActionResult> Create(TeacherViewModel teacher) { if (ModelState.IsValid) { Userinfo u = db.Userinfoes.Find(teacher.username); if (u != null) { ViewBag.userMsg = "Username Exist"; return(View()); } else if (teacher.password == null) { ViewBag.userMsg = "Password should not be null"; return(View()); } else if (teacher.password != teacher.confirmPassword) { ViewBag.userMsg = "Password not matched"; return(View()); } Userinfo user = new Userinfo(); user.username = teacher.username; user.role = teacher.role; user.email = teacher.email; user.passwordHash = Cryptography.getMD5(teacher.password); user.token = Cryptography.getMD5(teacher.username) + Cryptography.getMD5(teacher.password); db.Userinfoes.Add(user); db.SaveChanges(); Teacher tchr = new Teacher(); tchr.name = teacher.teacherName; tchr.email = teacher.email; tchr.username = teacher.username; db.Teachers.Add(tchr); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(teacher)); }
public async Task <int> SaveAsync() { try { return(await _context.SaveChangesAsync()); } catch (DbUpdateException databaseException) { foreach (var entry in databaseException.Entries) { //log exception } return(0); } }