public bool EditSubject(SubjectEdit subject) { if (subject != null) { SubjectsData st = GetSubject(subject); if (st != null && st.SubjectDataID != subject.SubjectId && st.Subject.Name.ToLower().Equals(subject.Name.ToLower()) && subject.SemesterId == st.SemesterID) subject.AddError("Przedmiot o podanych danych już\nistnieje w planie"); if (subject.IsElective && subject.IsGeneral) subject.AddError("Przedmiot nie może być\njednocześnie obowiązkowy i obieralny"); if (!subject.IsElective && !subject.IsGeneral && (subject.Specializations == null || subject.Specializations.Count() == 0)) subject.AddError("Przedmiot musi być obowiązkowy\nlub obieralny dla wszystkich lub\nprzynajmniej na jednej specjalności"); if (subject.SubjectTypes == null || subject.SubjectTypes.Count() == 0) subject.AddError("Przedmiot musi być przypisany\nprzynajmniej do jednego typu"); if(st != null && st.Ects != subject.Ects && st.SubjectDataID != subject.SubjectId && st.Subject.Name.ToLower().Equals(subject.Name.ToLower())) subject.AddError("Istnieje przedmiot nadrzędny\n o innej liczbie ECTS"); if (subject.IsValid) { st = this.repository.GetSubjectData(subject.SubjectId); Subject s = this.repository.GetSubject(subject.Name); if (s == null) { Subject newSubject = new Subject() { Name = subject.Name }; this.repository.AddSubjectName(newSubject); } s = this.repository.GetSubject(subject.Name); st.Subject = s; Departament dep = DepartamentController.Instance.GetDepartament(subject.Departament); int departamentId = dep == null ? 0 : dep.DepartamentID; Institute inst = InstituteController.Instance.GetInstitute(subject.Institute, departamentId); if (inst != null) st.InstituteID = inst.InstituteID; else st.InstituteID = null; st.Ects = subject.Ects; st.IsExam = subject.IsExam; st.SemesterID = subject.SemesterId; st.IsElective = subject.IsElective; st.IsGeneral = subject.IsGeneral; st.SubjectTypesDatas.Clear(); foreach (NewSubjectTypeData d in subject.SubjectTypes) { SubjectTypesData std = new SubjectTypesData() { Hours = d.Hours, SubjectTypeID = d.SubjectTypeId }; st.SubjectTypesDatas.Add(std); } if (subject.Specializations == null || subject.Specializations.Count() <= 0) { st.SpecializationsData = null; } else { st.SpecializationsData = new SpecializationsData() { SpecializationID = subject.Specializations.ElementAt(0).SpecializationId, IsElective = subject.Specializations.ElementAt(0).IsElective, IsGeneral = subject.Specializations.ElementAt(0).IsGenereal }; } this.repository.EditSubject(st); return true; } } return false; }
/// <summary> /// Create a new SubjectTypesData object. /// </summary> /// <param name="subjectDataID">Initial value of the SubjectDataID property.</param> /// <param name="subjectTypeID">Initial value of the SubjectTypeID property.</param> /// <param name="hours">Initial value of the Hours property.</param> public static SubjectTypesData CreateSubjectTypesData(global::System.Int32 subjectDataID, global::System.Int32 subjectTypeID, global::System.Double hours) { SubjectTypesData subjectTypesData = new SubjectTypesData(); subjectTypesData.SubjectDataID = subjectDataID; subjectTypesData.SubjectTypeID = subjectTypeID; subjectTypesData.Hours = hours; return subjectTypesData; }
/// <summary> /// Deprecated Method for adding a new object to the SubjectTypesDatas EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToSubjectTypesDatas(SubjectTypesData subjectTypesData) { base.AddObject("SubjectTypesDatas", subjectTypesData); }
public void AddSubject(NewSubject subject) { Subject s = this.GetSubject(subject.Name); if (s == null) { Subject newSubject = new Subject() { Name = subject.Name }; this.AddSubjectName(newSubject); } if (subject.Specializations != null && subject.Specializations.Count() > 0 && subject.IsGeneral == false) { s = this.GetSubject(subject.Name); for (int i = 0; i < subject.Specializations.Count(); i++) { SpecializationsData specDat = new SpecializationsData() { IsElective = subject.Specializations.ElementAt(i).IsElective, IsGeneral = subject.Specializations.ElementAt(i).IsGenereal, SpecializationID = subject.Specializations.ElementAt(i).SpecializationId }; SPDatabase.DB.SpecializationsDatas.AddObject(specDat); SubjectsData sd = new SubjectsData() { DepartamentID = subject.DepartamentId, Ects = subject.Ects, FacultyID = subject.FacultyId, InstituteID = subject.InstituteId, IsExam = subject.IsExam, SemesterID = subject.SemesterId, SpecializationDataID = specDat.SpecializationDataID, SubjectID = s.SubjectID, IsElective = false, IsGeneral = false }; if (subject.InstituteId > 0) sd.InstituteID = subject.InstituteId; else sd.InstituteID = null; Plan p = GetPlan(subject.PlanId); if (p != null) sd.Plans.Add(p); foreach (NewSubjectTypeData d in subject.SubjectTypes) { SubjectTypesData std = new SubjectTypesData() { Hours = d.Hours, SubjectTypeID = d.SubjectTypeId }; sd.SubjectTypesDatas.Add(std); } SPDatabase.DB.SubjectsDatas.AddObject(sd); SPDatabase.DB.SaveChanges(); } } if(subject.IsGeneral || subject.IsElective) { s = this.GetSubject(subject.Name); SubjectsData sdd = new SubjectsData() { DepartamentID = subject.DepartamentId, Ects = subject.Ects, FacultyID = subject.FacultyId, IsExam = subject.IsExam, SemesterID = subject.SemesterId, SpecializationDataID = null, SubjectID = s.SubjectID, IsElective = subject.IsElective, IsGeneral = subject.IsGeneral }; if (subject.InstituteId > 0) sdd.InstituteID = subject.InstituteId; else sdd.InstituteID = null; Plan pp = GetPlan(subject.PlanId); if (pp != null) sdd.Plans.Add(pp); foreach (NewSubjectTypeData d in subject.SubjectTypes) { SubjectTypesData std = new SubjectTypesData() { Hours = d.Hours, SubjectTypeID = d.SubjectTypeId }; sdd.SubjectTypesDatas.Add(std); } SPDatabase.DB.SubjectsDatas.AddObject(sdd); SPDatabase.DB.SaveChanges(); } }