コード例 #1
0
        public StudyPlanDetail UpdateDetail(Guid studyPlanId, Guid studyPlanDetailId, string name, Guid subjectId)
        {
            var existentStudyPlan = _studyPlanRepository.Get(studyPlanId, "details,details.subject");

            if (existentStudyPlan == null)
            {
                throw new Exception("There is no Study Plan with that ID");
            }

            var subject = _subjectRepository.Get(subjectId);

            if (subject == null)
            {
                throw new Exception("There is no Subject with that ID");
            }

            if (existentStudyPlan.Details.Any(x => x.Subject.Id == subjectId && x.Id != studyPlanDetailId))
            {
                throw new Exception("The StudyPlan already have this Subject in the Detail");
            }

            var updateStudyPlanDetail = new StudyPlanDetail()
            {
                Id        = studyPlanDetailId,
                Name      = name,
                Subject   = subject,
                StudyPlan = existentStudyPlan
            };

            return(_studyPlanDetailRepository.Update(updateStudyPlanDetail));
        }
コード例 #2
0
        public StudyPlanDetail AddNewDetail(Guid studyPlanId, string name, Guid subjectId)
        {
            var studyPlan = _studyPlanRepository.Get(studyPlanId, "details,details.subject");

            if (studyPlan == null)
            {
                throw new Exception("There is no StudyPlan with that ID");
            }

            var subject = _subjectRepository.Get(subjectId);

            if (subject == null)
            {
                throw new Exception("There is no Subject with that ID");
            }

            if (studyPlan.Details.Any(x => x.Subject.Id == subjectId))
            {
                throw new Exception("The StudyPlan already have this Subject in the Detail");
            }

            var newDetail = new StudyPlanDetail {
                Id = new Guid(), Subject = subject, Name = name, StudyPlan = studyPlan
            };

            return(_studyPlanDetailRepository.Add(newDetail));
        }