public ActionResult Create(int id)
        {
            var currentEnrollee = _enrolleeService.Find(customer => customer.AppCustomer.UserName == User.Identity.Name).First();

            var faculty = _facultyService.Get(id);

            var addedFaculty = _facultyService.GetAll().Where(f => f.FacultyNumber == faculty.FacultyNumber && faculty.Enrollees.Any()).ToList();

            if (currentEnrollee.Faculties.Any(f => f.FacultyNumber == faculty.FacultyNumber))
            {
                ModelState.AddModelError("AddFaculty", "This faculty already added.");
                return(View());
            }
            else if (addedFaculty.Any() && addedFaculty.First().Enrollees.Any() &&
                     addedFaculty.First().Enrollees.Count(e => e.StudentStatuses.Any(s => s.FacultyStatus == true && s.Faculty.FacultyNumber == faculty.FacultyNumber))
                     == faculty.AllPlaces)
            {
                ModelState.AddModelError("AddFaculty", "No places are there :(");

                return(View());
            }
            else
            {
                currentEnrollee.ExaminationSubjects.Clear();
                currentEnrollee.SchoolSubjects.Clear();
                foreach (var item in _schoolSubjectsService.GetAll().ToList())
                {
                    if (!currentEnrollee.SchoolSubjects.Contains(item))
                    {
                        currentEnrollee.SchoolSubjects.Add(item);
                    }
                }

                var exSubjects = _examinationSubjectService.Find(e => e.Faculties.Any(f => f.FacultyNumber == faculty.FacultyNumber)).ToList();

                foreach (var item in exSubjects)
                {
                    if (!currentEnrollee.ExaminationSubjects.Any(s => s.Name == item.Name))
                    {
                        currentEnrollee.ExaminationSubjects.Add(item);
                    }
                }

                currentEnrollee.Faculties.Add(faculty);

                var status = new StudentStatus()
                {
                    Faculty = faculty, FacultyStatus = false, Enrollee = currentEnrollee, Status = "Enrollee"
                };

                _studentStatusService.Create(status);

                _enrolleeService.Update(currentEnrollee);

                return(View("Create", currentEnrollee));
            }
        }
Exemplo n.º 2
0
        public void GetAll_CorrectQuantiity()
        {
            var schoolSubjects = new List <SchoolSubject>
            {
                new SchoolSubject(),
                new SchoolSubject()
            };

            _unitOfWorkMock.Setup(uof => uof.SchoolSubjectGenericRepository.GetAll()).Returns(schoolSubjects);

            var result = _sut.GetAll();

            Assert.Equal(schoolSubjects.Count, result.Count());
        }
        public ActionResult GetSchoolSubjects()
        {
            var subjects = _schoolSubjectsService.GetAll();

            return(View(subjects));
        }