Esempio n. 1
0
        public void Update_SchoolSubject_Updated()
        {
            var schoolSubject = new SchoolSubject();

            _unitOfWorkMock.Setup(uof => uof.SchoolSubjectGenericRepository.Update(schoolSubject));

            _sut.Update(schoolSubject);

            _unitOfWorkMock.Verify(uof => uof.SchoolSubjectGenericRepository.Update(It.IsAny <SchoolSubject>()), Times.AtLeastOnce);
        }
        public ActionResult SchoolSubjectEdit(SchoolSubject schoolSubject)
        {
            if (!ModelState.IsValid)
            {
                return(View(schoolSubject));
            }

            _schoolSubjectsService.Update(schoolSubject);

            return(RedirectToAction("GetSchoolSubjects", "SchoolSubject", new { area = "Operator" }));
        }
        public ActionResult AddFaculty(int[] examMark, int[] schoolMark)
        {
            var currentEnrollee = _enrolleeService.Find(customer => customer.AppCustomer.UserName == User.Identity.Name).First();

            var exSubjects = _examinationSubjectService.Find(ex => ex.Enrollees.Any(e => e.Email == currentEnrollee.Email)).ToList();

            if (examMark != null)
            {
                for (var i = 0; i < examMark.Length; i++)
                {
                    var mark = new Mark {
                        StudentMark = examMark[i], Enrollee = currentEnrollee, ExaminationSubject = exSubjects[i]
                    };

                    _markService.Create(mark);

                    if (exSubjects[i].Marks.Any(m => m.ExaminationSubject.Name == exSubjects[i].Name &&
                                                m.Enrollee.Email == currentEnrollee.Email))
                    {
                        exSubjects[i].Marks.First(m => m.ExaminationSubject.Name == exSubjects[i].Name &&
                                                  m.Enrollee.Email == currentEnrollee.Email).StudentMark = examMark[i];
                    }
                    else
                    {
                        exSubjects[i].Marks.Add(_markService.Find(m => m.Enrollee.Email == currentEnrollee.Email &&
                                                                  m.ExaminationSubject.Name == exSubjects[i].Name).Last());
                    }
                }
            }

            exSubjects.ForEach(s => _examinationSubjectService.Update(s));

            var schoolSubjects = _schoolSubjectsService.Find(ex => ex.Enrollees.Any(e => e.Email == currentEnrollee.Email)).ToList();

            if (schoolMark != null)
            {
                for (var i = 0; i < schoolMark.Length; i++)
                {
                    var mark = new Mark {
                        StudentMark   = schoolMark[i], Enrollee = currentEnrollee,
                        SchoolSubject = schoolSubjects[i]
                    };

                    _markService.Create(mark);

                    if (schoolSubjects[i].Marks.Any(m => m.SchoolSubject.Name == schoolSubjects[i].Name &&
                                                    m.Enrollee.Email == currentEnrollee.Email))
                    {
                        schoolSubjects[i].Marks.First(m => m.SchoolSubject.Name == schoolSubjects[i].Name &&
                                                      m.Enrollee.Email == currentEnrollee.Email).StudentMark = schoolMark[i];
                    }
                    else
                    {
                        schoolSubjects[i].Marks.Add(_markService.Find(m => m.Enrollee.Email == currentEnrollee.Email &&
                                                                      m.SchoolSubject.Name == schoolSubjects[i].Name).Last());
                    }
                }
            }

            schoolSubjects.ForEach(s => _schoolSubjectsService.Update(s));

            _enrolleeService.Update(currentEnrollee);

            return(RedirectToAction("GetFaculty", new { area = string.Empty, controller = "Faculty" }));
        }