public ActionResult Enroll(EnrollStudentInCourse enrollStudent) { string message; try { message = studentManager.Save(enrollStudent); ViewBag.Message = message; IEnumerable<Student> students = studentManager.GetAll; IEnumerable<Course> courses = courseManager.GetAll; ViewBag.Students = students; ViewBag.Courses = courses; return View(); } catch (Exception exception) { message= exception.InnerException.Message; ViewBag.Message = message; return View(); } }
public int Update(EnrollStudentInCourse enrollStudentInCourse) { ConnectionObj.Open(); SqlTransaction sqlTransaction = ConnectionObj.BeginTransaction(); try { CommandObj.Transaction = sqlTransaction; CommandObj.CommandText = "UPDATE t_StudentEnrollInCourse SET IsStudentActive=1 WHERE StudentId='" + enrollStudentInCourse.StudentId + "' AND CourseId='" + enrollStudentInCourse.CourseId + "'"; int updateResult=CommandObj.ExecuteNonQuery(); // int updateResult = UpdateStudentEnrolledCourses(enrollStudentInCourse); sqlTransaction.Commit(); return updateResult; } catch (Exception exception) { sqlTransaction.Rollback(); throw new Exception("Could not save", exception); } finally { CommandObj.Dispose(); ConnectionObj.Close(); } }
public int Insert(EnrollStudentInCourse enrollStudent) { try { CommandObj.CommandText = "INSERT INTO t_StudentEnrollInCourse VALUES(@stId,@courseId,@enrollDate,@status)"; CommandObj.Parameters.Clear(); CommandObj.Parameters.AddWithValue("@stId", enrollStudent.StudentId); CommandObj.Parameters.AddWithValue("@courseId", enrollStudent.CourseId); CommandObj.Parameters.AddWithValue("@enrollDate", enrollStudent.EnrollDate.ToShortDateString()); CommandObj.Parameters.AddWithValue("@status", 1); ConnectionObj.Open(); int rowAffected = CommandObj.ExecuteNonQuery(); return rowAffected; } catch (Exception exception) { throw new Exception("Could not save",exception); } finally { CommandObj.Dispose(); ConnectionObj.Close(); } }
public string Save(EnrollStudentInCourse enrollStudentInCourse) { EnrollStudentInCourse enrollStudent = GetEnrollCourses.ToList() .Find( st => (st.StudentId == enrollStudentInCourse.StudentId && st.CourseId == enrollStudentInCourse.CourseId) && (st.Status)); if (enrollStudent == null) { if (studentGateway.Insert(enrollStudentInCourse) > 0) { return "Saved Sucessfully!"; } return "Failed to save"; } return "This course already taken by the student"; }