/// <summary>
 /// Deprecated Method for adding a new object to the SubjectsDatas EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSubjectsDatas(SubjectsData subjectsData)
 {
     base.AddObject("SubjectsDatas", subjectsData);
 }
 /// <summary>
 /// Create a new SubjectsData object.
 /// </summary>
 /// <param name="subjectID">Initial value of the SubjectID property.</param>
 /// <param name="semesterID">Initial value of the SemesterID property.</param>
 /// <param name="facultyID">Initial value of the FacultyID property.</param>
 /// <param name="ects">Initial value of the Ects property.</param>
 /// <param name="isExam">Initial value of the IsExam property.</param>
 /// <param name="departamentID">Initial value of the DepartamentID property.</param>
 /// <param name="subjectDataID">Initial value of the SubjectDataID property.</param>
 /// <param name="isElective">Initial value of the IsElective property.</param>
 /// <param name="isGeneral">Initial value of the IsGeneral property.</param>
 public static SubjectsData CreateSubjectsData(global::System.Int32 subjectID, global::System.Int32 semesterID, global::System.Int32 facultyID, global::System.Double ects, global::System.Boolean isExam, global::System.Int32 departamentID, global::System.Int32 subjectDataID, global::System.Boolean isElective, global::System.Boolean isGeneral)
 {
     SubjectsData subjectsData = new SubjectsData();
     subjectsData.SubjectID = subjectID;
     subjectsData.SemesterID = semesterID;
     subjectsData.FacultyID = facultyID;
     subjectsData.Ects = ects;
     subjectsData.IsExam = isExam;
     subjectsData.DepartamentID = departamentID;
     subjectsData.SubjectDataID = subjectDataID;
     subjectsData.IsElective = isElective;
     subjectsData.IsGeneral = isGeneral;
     return subjectsData;
 }
 public void DeleteSubject(SubjectsData sd)
 {
     if (sd != null)
     {
         SPDatabase.DB.SubjectsDatas.DeleteObject(sd);
         SPDatabase.DB.SaveChanges();
     }
 }
 public void EditSubject(SubjectsData subjectEdit)
 {
     if (subjectEdit != null)
         SPDatabase.DB.SaveChanges();
 }
        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();
            }
        }