public async Task <ActionResult> Register([Bind(Include = "StudentId,StudentName,StudentEmail,StudentContact,RegDate,StudentAddress,StudentDeptId")] StudentModel studentModel) { string regPart = string.Format("{0}-{1}-", db.Departments.Single(x => x.DeptId == studentModel.StudentDeptId).DeptCode, studentModel.RegDate.Year.ToString()); studentModel.StudentRegNo = new BusinessLogics().RegistrationNo(regPart); if (ModelState.IsValid) { db.Students.Add(studentModel); await db.SaveChangesAsync(); TempData["student"] = studentModel; return(RedirectToAction("Register")); } ViewBag.StudentDeptId = new SelectList(db.Departments, "DeptId", "DeptCode", studentModel.StudentDeptId); return(View(studentModel)); }
public async Task <ActionResult> Add([Bind(Include = "TeacherId,TeacherName,TeacherAddress,TeacherEmail,TeacherContact,TeacherDesignationId,TeacherDeptId,TotalCredit")] TeacherModel teacherModel) { if (ModelState.IsValid) { db.Teachers.Add(teacherModel); if (await db.SaveChangesAsync() > 0) { TempData["Message"] = string.Format("Teacher added successfully!"); TempData["MessageType"] = "success"; } return(RedirectToAction("Index")); } ViewBag.TeacherDeptId = new SelectList(db.Departments.OrderBy(x => x.DeptCode), "DeptId", "Department", teacherModel.TeacherDeptId); ViewBag.TeacherDesignationId = new SelectList(db.Designations, "DesignationId", "Designation", teacherModel.TeacherDesignationId); return(View(teacherModel)); }
public async Task <ActionResult> Create([Bind(Include = "CourseId,CourseCode,CourseName,CourseCredit,CourseDesc,CourseDeptId,CourseSemesterId")] CourseModel courseModel) { if (ModelState.IsValid) { db.Courses.Add(courseModel); if (await db.SaveChangesAsync() > 0) { TempData["Message"] = string.Format("<b>{0} ({1})</b> has been saved.", courseModel.CourseName, courseModel.CourseCode); TempData["MessageType"] = "success"; } return(RedirectToAction("create")); } ViewBag.CourseDeptId = new SelectList(db.Departments.OrderBy(x => x.DeptCode), "DeptId", "Department", courseModel.CourseDeptId); ViewBag.CourseSemesterId = new SelectList(db.Semesters, "SemesterId", "Semester", courseModel.CourseSemesterId); return(View(courseModel)); }
public async Task <ActionResult> Create([Bind(Include = "DeptId,DeptCode,DeptName")] DepartmentModel departmentModel) { if (ModelState.IsValid) { db.Departments.Add(departmentModel); if (await db.SaveChangesAsync() > 0) { TempData["Message"] = string.Format("Department <b>{0} ({1})</b> is created successfully!", departmentModel.DeptName, departmentModel.DeptCode); TempData["MessageType"] = "success"; } return(RedirectToAction("create")); } return(View(departmentModel)); }