public IActionResult GetAvilabelStudySemesterByYearAndStudyYear(string specializationId, int yearId, int studyYearId) { var year = _yearRepositroy.GetIQueryable(c => c.Id == yearId) .Include(c => c.ExamSemester) .ThenInclude(c => c.StudentSubject) .ThenInclude(c => c.Subject) .ThenInclude(c => c.StudySemester) .ThenInclude(c => c.Studyplan) .FirstOrDefault(); if (year.Blocked) { var message = Messages.Blocked; message.Message = "السنة مقفولة"; message.ActionName = "Get Avilabel Study Semester By Year And StudyYear"; message.ControllerName = "Exam Semeter"; return(Conflict(message)); } //var examSemesters = year.ExamSemester.Where(ss => ss.StudentSubject.Where(c => c.Subject.StudySemester.Studyplan.SpecializationId == specializationId && c.Subject.StudySemester.StudyYearId == studyYearId).Count() > 0).ToList(); var examSemesters = year.ExamSemester.ToList(); examSemesters.Sort((s1, s2) => s1.SemesterNumber.CompareTo(s2.SemesterNumber)); foreach (var item in examSemesters) { if (item.SemesterNumber > 1) { if (!year.IsThisSemesterFinshed(item.SemesterNumber - 1)) { var message = new BadRequestErrors() { ActionName = "GetAvilabelStudySemesterByYearAndStudyYear", ControllerName = "ExamSemester", Message = "يجب انهاء الفصل السابق", }; return(Conflict(message)); } } if (item.StudentSubject.Any(c => c.PracticalDegree == null || c.TheoreticlaDegree == null)) { item.StudentSubject = item.StudentSubject.Where(c => c.TheoreticlaDegree == null).ToList(); item.StudentSubject = item.StudentSubject.Where(c => c.Subject.StudySemester.StudyYearId == studyYearId && c.Subject.StudySemester.Studyplan.SpecializationId == specializationId).ToList(); var subjects = item.StudentSubject.GroupBy(c => c.Subject).Select(c => c.First().Subject).ToList(); var repsonseExamSemester = _mapper.Map <ResponseExamSemesterDTO>(item); repsonseExamSemester.Subjects = _mapper.Map <ResponseSubjectDTO[]>(subjects).ToList(); return(Ok(repsonseExamSemester)); } } return(Ok(new ResponseExamSemesterDTO[0])); }
public IActionResult AddExamSystem([FromBody] AddExamSystemDTO addExamSystemDTO) { try { addExamSystemDTO.Name = addExamSystemDTO.Name.Trim(); if (string.IsNullOrWhiteSpace(addExamSystemDTO.Name)) { var message = Messages.EmptyName; message.ActionName = "Add Exam System"; message.ControllerName = "Exam System"; return(BadRequest(message)); } if (_examSystemRepositroy.Get(c => c.Name == addExamSystemDTO.Name).FirstOrDefault() != null) { var message = Messages.Exist; message.ActionName = "Add Exam System"; message.ControllerName = "Exam System"; return(Conflict(message)); } if (addExamSystemDTO.HaveTheredSemester == true && addExamSystemDTO.GraduateStudentsSemester > 0) { var message = new BadRequestErrors(); message.ActionName = "Add Exam System"; message.ControllerName = "Exam System"; message.Message = "لا يمكن وضع دورة خريجين و مع فصل ثالث"; return(Conflict(message)); } if (addExamSystemDTO.GraduateStudentsSemester != null && addExamSystemDTO.GraduateStudentsSemester < 0) { var message = new BadRequestErrors(); message.ActionName = "Add Exam System"; message.ControllerName = "Exam System"; message.Message = "لا يمكن لدورة الخريجين ان تكون بالسابة"; return(Conflict()); } var examSystem = _mapper.Map <ExamSystem>(addExamSystemDTO); _examSystemRepositroy.Add(examSystem, UserName()); _examSystemRepositroy.Save(); return(Ok(examSystem)); } catch (Exception ex) { return(BadRequestAnonymousError()); } }
public IActionResult Add(AddYearSystemDTO addYearSystemDTO) { try { addYearSystemDTO.Name = addYearSystemDTO.Name.Trim(); if (string.IsNullOrWhiteSpace(addYearSystemDTO.Name)) { var message = Messages.EmptyName; message.ActionName = "Add"; message.ControllerName = "Year System"; return(BadRequest(message)); } var settingId = addYearSystemDTO.Settings.Select(c => c.Id).ToList(); var mainSettinId = this._settingsRepositroy.Get().Select(c => c.Id).ToList(); // this number of role shoud replace in correct way if (settingId.Count < mainSettinId.Count()) { var message = new BadRequestErrors(); message.ActionName = "Add"; message.ControllerName = "Year System"; message.Message = "لم يتم إرسال كامل الإعدادات"; return(Conflict(message)); } settingId.Sort(); if (settingId.Except(mainSettinId).Any() || mainSettinId.Except(settingId).Any()) { var message = new BadRequestErrors() { ActionName = "Add", ControllerName = "Year System", Message = "لام يتم إرسال جميع الإعدادات او تم إرسال قيمة خاطئة" }; return(Conflict(message)); } if (addYearSystemDTO.IsMain) { var oldMain = _abstractUnitOfWork.Repository <YearSystem>().Get(c => c.IsMain).FirstOrDefault(); if (oldMain != null) { oldMain.IsMain = false; _abstractUnitOfWork.Repository <YearSystem>().Update(oldMain, UserName()); } } YearSystem yearSystem = _mapper.Map <YearSystem>(addYearSystemDTO); _abstractUnitOfWork.Add(yearSystem, UserName()); foreach (var item in addYearSystemDTO.Settings) { var setting = _settingsRepositroy.Find(item.Id); var settingYearSystem = new SettingYearSystem { YearSystem = yearSystem.Id, Setting = setting, Count = item.Count, Note = item.Note }; _abstractUnitOfWork.Add(settingYearSystem, UserName()); } _abstractUnitOfWork.Commit(); return(Ok(_mapper.Map <ResponseYearSystem>(yearSystem))); } catch (Exception ex) { return(BadRequestAnonymousError()); } }
//[Authorize(Roles = "AddStudyPlan")] public IActionResult Add([FromBody] AddStudyPalnDTO addStudyPalnDTO) { try { var year = _yearRepositroy.Find(addStudyPalnDTO.YearId); if (year == null) { var message = Messages.NotFound; message.ActionName = "Add Study Plan"; message.ControllerName = "Study Plan"; message.Message = "السنة غير موجودة"; return(NotFound(message)); } var specialization = _specializationsRepositroy.Find(addStudyPalnDTO.SpecializationId); if (specialization == null) { var message = Messages.NotFound; message.ActionName = "Add Study Plan"; message.ControllerName = "Study Plan"; message.Message = "الاختصاص غير موجود"; return(NotFound(message)); } #region check temporary Id var tempId = addStudyPalnDTO.Subjects.Select(c => c.AddSubjectDTO.TempId).ToArray(); if (tempId.Contains(0)) { var message = new BadRequestErrors(); message.ActionName = "Update"; message.ControllerName = "YearSystem"; message.Message = "الرجاء إعادة تحميل الصفحة"; return(Conflict(message)); } if (tempId.Count() != tempId.Distinct().Count()) { var message = new BadRequestErrors(); message.ActionName = "Update"; message.ControllerName = "YearSystem"; message.Message = "الرجاء إعادة تحميل الصفحة"; return(Conflict(message)); } #endregion #region check subject //but it should replace after asking the Eng //check subject var studyYear = _studyYearRepositroy.Get().ToList(); var subjectsTypesId = _subjectTypeRepositroy.Get().Select(c => c.Id); var subjectsId = _subjectRepositroy.Get().Select(c => c.Id); foreach (var item in addStudyPalnDTO.Subjects) { //there's not thered study semester if (item.StudySemesterNumber > 2) { var message = Messages.NotFound; message.ActionName = "Add Study Plan"; message.ControllerName = "Study Plan"; message.Message = "ليست 3 فصول تدريسية"; return(Conflict(message)); } //chekc if all the year is correct //example //this subject is for thered year and in our collage don't have any thered year yet //so it return an confliect if (studyYear.Select(c => c.Id).ToList().IndexOf(item.StudyYearId) < 0) { var message = new BadRequestErrors(); message.ActionName = "Add Study Plan"; message.ControllerName = "Study Plan"; message.Message = "السنة الدراسية غير موجودة"; return(Conflict(message)); } //check Type if exist if (!subjectsTypesId.Contains(item.AddSubjectDTO.SubjectTypeId)) { var message = Messages.NotFound; message.ActionName = "Add Study Plan"; message.ControllerName = "Study Plan"; message.Message = "نوع المادة غير موجود"; return(NotFound(message)); } var subject = item.AddSubjectDTO; //befor tempId //if (subject.DependencySubjectsId.Except(subjectsId).Any()) //{ // return Conflict(); //} subject.Name = subject.Name.Trim(); if (string.IsNullOrWhiteSpace(subject.Name)) { var message = Messages.EmptyName; message.ActionName = "Add Study Plan"; message.ControllerName = "Study Plan"; return(Conflict(message)); } if (subject.DependencySubjectsId.Except(tempId).Any()) { var message = Messages.ReLoadPage; message.ActionName = "Add Study Plan"; message.ControllerName = "Study Plan"; return(Conflict(message)); } if (subject.EquivalentSubjectsId.Except(subjectsId).Any()) { var message = Messages.ReLoadPage; message.ActionName = "Add Study Plan"; message.ControllerName = "Study Plan"; return(Conflict(message)); } subject.DependencySubjectsId = subject.DependencySubjectsId.Distinct().ToList(); subject.EquivalentSubjectsId = subject.EquivalentSubjectsId.Distinct().ToList(); } #endregion var studyPaln = _mapper.Map <StudyPlan>(addStudyPalnDTO); _abstractUnitOfWork.Add(studyPaln, UserName()); Dictionary <int, Subjects> tempIdAndSubject = new Dictionary <int, Subjects>(); for (int i = 1; i <= studyYear.Count(); i++) { //get the subject for this year mean first year and secound year ..etc var subjectsForYear = addStudyPalnDTO.Subjects.Where(c => c.StudyYearId == studyYear[i - 1].Id); //for adding in semester //semester number because we have 2 semester in the year for (int semesterNumber = 1; semesterNumber <= 2; semesterNumber++) { var semester = new StudySemester() { Number = (short)semesterNumber, StudyYearId = studyYear[i - 1].Id, StudyplanId = studyPaln.Id, }; _abstractUnitOfWork.Add(semester, UserName()); //get subject for the semester var subjectsForSemester = subjectsForYear.Where(c => c.StudySemesterNumber == semesterNumber); #region explain //the output is like subject for first yaer and semester 1 in the first looping . //exmple of output for Specialization Softwere engineering. // programing 1 , electorinec , math1 , operaing system 1 //in the secound loop for the inner loop //out put example //programing 2 , math2 ,e2 , //in the seocund loop for the outer loop and first loop for inner loop // advance programing 1 , oracle 1 ,operaing system 2 // this example depend on input //for git subject without any extande proraty #endregion var finalSubjectAfterFilering = subjectsForSemester.Select(c => c.AddSubjectDTO).ToList(); finalSubjectAfterFilering.ForEach(c => c.StudySemesterId = semester.Id); foreach (var subjectDTO in finalSubjectAfterFilering) { var subject = _mapper.Map <Subjects>(subjectDTO); subject.StudySemester = semester; _abstractUnitOfWork.Add(subject, UserName()); //foreach (var DependencySubjectId in subjectDTO.DependencySubjectsId) //{ // _abstractUnitOfWork.Repository<DependenceSubject>() // .Add(new DependenceSubject() // { // SubjectId = subject.Id, // DependsOnSubjectId = DependencySubjectId // }, UserName()); //} tempIdAndSubject[subjectDTO.TempId] = subject; foreach (var EquivalentSubjectId in subjectDTO.EquivalentSubjectsId) { _abstractUnitOfWork.Add(new EquivalentSubject() { FirstSubject = subject.Id, SecoundSubject = EquivalentSubjectId }, UserName()); } } } } foreach (var subjectDTO in addStudyPalnDTO.Subjects.Select(c => c.AddSubjectDTO)) { var subject = tempIdAndSubject[subjectDTO.TempId]; foreach (var DependancySubjectId in subjectDTO.DependencySubjectsId) { var depenacySubjct = tempIdAndSubject[DependancySubjectId]; // if this subject can't depand on another subject if (!_subjectServices.CheckCanBeDepandacy(subject, depenacySubjct)) { var message = new BadRequestErrors(); message.ActionName = "Add Study Plan"; message.ControllerName = "Study Plan"; message.Message = "خطأ في تحديد اعتمادية المواد"; return(Conflict()); } _abstractUnitOfWork.Add( new DependenceSubject() { SubjectId = subject.Id, DependsOnSubjectId = depenacySubjct.Id }, UserName()); } } _abstractUnitOfWork.Commit(); return(Ok()); } catch (Exception) { return(BadRequestAnonymousError()); } }