public int AddEnrollment(int StuId, int CourId) { using (TransactionScope tran = new TransactionScope()) { Course c = Courses.Get(CourId); Student s = Students.Get(StuId); if (c == null || s == null) { return(-1); // if the course or student doesn't exist, invalid } Enrollment enroll = Enrollments.SingleOrDefault(e => (e.StudentId == StuId && e.CourseId == CourId)); if (enroll != null) { return(enroll.Id); // already exist, return } enroll = new Enrollment() { StudentId = StuId, CourseId = CourId }; int EId = Enrollments.Add(enroll); // Complete(); tran.Complete(); return(EId); } }
public EnrollmentModel Add(int userId, int classId) { var userclass = enrollmentRepository.Add(userId, classId); return(new EnrollmentModel { UserId = userclass.UserId, ClassId = userclass.ClassID }); }
public IActionResult AddCourseToStudent(StudentViewModel model) { if (ModelState.IsValid) { if (model.Enrollment.StudentId == 0 || model.Enrollment.CourseId == 0) { return(RedirectToAction("Index")); } _enrollmentRepository.Add(model.Enrollment); } return(RedirectToAction("Details", new { id = model.Enrollment.StudentId })); }
public async Task <EnrollmentNotification> Handle(EnrollmentAddCommand request, CancellationToken cancellationToken) { try { var course = await _mediator.Send(new CourseQueryById() { id = request.enrollment.CourseId }); if (course.MaxEnrollments - course.Enrollmenteds > 0) { await _repository.Add(request.enrollment); await _mediator.Send(new CourseUpateAvailableCommand() { id = request.enrollment.CourseId }); var result = new EnrollmentNotification() { enrollment = request.enrollment, message = "You assigned to course." }; await _mediator.Publish(result); return(await Task.FromResult(result)); } else { var result = new EnrollmentNotification() { enrollment = request.enrollment, message = "There no more subscriptions available for this course." }; await _mediator.Publish(result); return(await Task.FromResult(result)); } } catch (Exception ex) { await _mediator.Publish(new ErrorNotification { ErrorDescription = ex.Message, ErrorTrace = ex.StackTrace }); return(await Task.FromResult(new EnrollmentNotification() { enrollment = request.enrollment, message = "Sorry some wrong happend, please try later." })); } }
public async Task <IActionResult> Create([Bind("EnrollmentID,CourseID,StudentID,Grade")] Enrollment enrollment) { if (ModelState.IsValid) { await _enrollmentRepository.Add(enrollment); return(RedirectToAction(nameof(Index))); } var students = _studentRepository.GetAll().Result; var courses = _courseRepository.GetAll().Result; ViewData["CourseID"] = new SelectList(courses, "Id", "Id"); ViewData["StudentID"] = new SelectList(students, "Id", "Id"); return(View(enrollment)); }
public async Task <ActionResult <Enrollment> > PostEnrollment(Enrollment enrollment) { Enrollment enrollresult = _enrollmentRepository.Add(enrollment); if (enrollresult != null) { await _enrollmentRepository.SaveChangesAsync(); return(StatusCode((int)System.Net.HttpStatusCode.OK, "Enrollment Success")); } else { return(StatusCode((int)System.Net.HttpStatusCode.Forbidden, "Course Is Full")); } }
public void Add(Enrollment enrollment) { SetEnrollmentProperties(enrollment); ValidateEnrollment(enrollment); SetCurrentEnrollment(enrollment); enrollment.EnrollmentDate = DateTime.Today; _enrollmentRepository.Add(enrollment); var evaluations = GetEvaluationForNewEnrollment(enrollment); _evaluationRepository.AddRange(evaluations); }
public async Task <string> Handle(EnrollmentAddCommand request, CancellationToken cancellationToken) { try { bool result = await _repository.Add(request.enrollment); request.enrollment.Accepted = result; await _mediator.Publish(new EnrollmentAddNotification() { enrollment = request.enrollment }); return(await Task.FromResult(result? "Your signup was created successfull." : "Your already enrollmented in this course.")); } catch (Exception ex) { await _mediator.Publish(new ErrorNotification { Error = ex.Message, SourceError = ex.StackTrace }); return(await Task.FromResult("Some wrong happened to create your signup.")); }; }
public async Task <int> EnrollStudent(EnrollmentDto enrollmentDto) { var course = await _courseRepository.GetById(enrollmentDto.CourseId); if (course == null) { throw new ArgumentException($"There's no course with courseId = {enrollmentDto.CourseId}"); } var student = await _studentRepository.GetById(enrollmentDto.StudentId); if (student == null) { throw new ArgumentException($"There's no student with studentId = {enrollmentDto.StudentId}"); } return(await _enrollmentRepository.Add(new Enrollment { CourseId = enrollmentDto.CourseId, StudentId = enrollmentDto.StudentId })); }
public Enrollment DoEnrollmentAndRegistration(Student student, StudyPlan studyPlan) { var existentEnrollment = _enrollmentRepository.GetByStudent(student.Id); if (existentEnrollment != null) { throw new Exception("The Student is already Enrolled in another StudyPlan"); } var existentEnrollments = _enrollmentRepository.GetByStudyPlan(studyPlan.Id); if (existentEnrollments.Any(x => x.Student.Id == student.Id)) { throw new Exception("The Student is already Enrolled in this StudyPlan"); } var newEnrollment = new Enrollment() { Id = new Guid(), Student = student, StudyPlan = studyPlan }; return(_enrollmentRepository.Add(newEnrollment)); }
public void CreateEnrollment(Enrollment enrollment) { enrollmentRepository.Add(enrollment); enrollmentRepository.SaveChanges(); }
public void Add(int userId, int classId) { enrollmentRepository.Add(userId, classId); }
public void Add(Enrollment enrollment) { repository.Add(enrollment); }
private Task <int> Persist(Enrollment enrollment) => _enrollmentRepository.Add(enrollment);