public bool EnrollCourseAndTeacher(EnrollCourseTeacher enrollCourseTeacher) { string query = "INSERT INTO EnrollCourseTeacher Values('" + enrollCourseTeacher.CourseId + "','" + enrollCourseTeacher.TeacherId + "','assigned')"; Command.CommandText = query; Connection.Open(); bool result = Command.ExecuteNonQuery() > 0; Connection.Close(); string query2 = "UPDATE Course set Status='assigned',CourseAssignTo='" + enrollCourseTeacher.TeacherName + "' where Id='" + enrollCourseTeacher.CourseId + "'"; Command.CommandText = query2; Connection.Open(); bool result2 = Command.ExecuteNonQuery() > 0; Connection.Close(); return(result && result2); }
public ActionResult AssignCourse(EnrollCourseTeacher enrollCourseTeacher) { CourseTeacherViewModel ctvm = _courseManager.IsCourseAssigned(enrollCourseTeacher); if (ctvm == null) { bool rowAffected = _teacherManager.EnrollCourseAndTeacher(enrollCourseTeacher); if (rowAffected) { ViewBag.SuccessMessage = "Course and Teacher Enroll Successfullly"; } else { ViewBag.ErrorMessage = "Course and Teacher Enroll Failed"; } } else { ViewBag.ErrorMessage = "Assign Failed! " + ctvm.CourseName + " already enrolled to " + ctvm.TeacherName; } ViewBag.Department = _departmentManager.GetAllDepartments(); return(View()); }
public CourseTeacherViewModel IsCourseAssigned(EnrollCourseTeacher enrollCourseTeacher) { Command.CommandText = @"select c.Id as CourseId,c.Name as CourseName, c.CourseAssignTo as TeacherName from Course c where c.Id='" + enrollCourseTeacher.CourseId + "' and c.Status='assigned'"; Connection.Open(); SqlDataReader reader = Command.ExecuteReader(); CourseTeacherViewModel ect = null; if (reader.HasRows) { while (reader.Read()) { ect = new CourseTeacherViewModel(); ect.CourseId = (int)reader["CourseId"]; ect.CourseName = reader["CourseName"].ToString(); ect.TeacherName = reader["TeacherName"].ToString(); } } reader.Close(); Connection.Close(); return(ect); }
public CourseTeacherViewModel IsCourseAssigned(EnrollCourseTeacher enrollCourseTeacher) { return(_courseGateway.IsCourseAssigned(enrollCourseTeacher)); }
public bool EnrollCourseAndTeacher(EnrollCourseTeacher enrollCourseTeacher) { return(_teacherGateway.EnrollCourseAndTeacher(enrollCourseTeacher)); }