Ejemplo n.º 1
0
        public async Task <IActionResult> SelectCourse(long facId, long crsId)
        {
            if (await _offRepository.EntityExistAsync(facId, crsId))
            {
                return(RedirectToAction(nameof(Details), routeValues: new { id = facId }));
            }
            var offer = new Offer
            {
                Faculty = await _repository.GetEntityByIdAsync(facId),
                Course  = await _crsRepository.GetEntityByIdAsync(crsId)
            };

            _offRepository.Add(offer);
            await _unitOfWork.SaveAsync();

            return(RedirectToAction(nameof(CourseController.GetFacultiesByCrsId),
                                    nameof(Course),
                                    routeValues: new { crsId }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> SelectCourse(long stuId, long crsId)
        {
            bool hasEnrollment = await _enrRepository.EntityExistAsync(stuId, crsId);

            if (!hasEnrollment)
            {
                bool hasOffer = await _offRepository.EntityExistAsync(crsId, 0);

                if (hasOffer)
                {
                    var enrollment = new Enrollment
                    {
                        Student = await _repository.GetEntityByIdAsync(stuId),
                        Offer   = await _offRepository.GetEntityByCrsId(crsId),
                        EnGrade = EnGrade.大一
                    };
                    _enrRepository.Add(enrollment);
                    await _unitOfWork.SaveAsync();
                }
            }
            return(RedirectToAction(nameof(CourseController.GetStudentsByCrsId), nameof(Course), new { crsId }));
        }