Example #1
0
        public Boolean UpdateTeacher(ref TeacherBDO teacher, ref string message)
        {
            message = "Teacher updated successfully.";
            Boolean ret = true;
            Teacher t = new Teacher();
            try {
               ConvertTeacherBDOToTeacher(teacher, t);
            Teacher teacherInDB = new Teacher();
            using (var DCEnt = new DCFIEntities())
            {
                var teacherID = teacher.TeacherId;
                teacherInDB = (from tea in DCEnt.Teachers
                               where tea.TeacherId.Equals(teacherID)
                               select tea).FirstOrDefault();

                if (teacherInDB == null)
                {
                    throw new Exception("No teacher with ID " + teacher.TeacherId);
                }

                //1st Part
                if (teacherInDB.TeacherChildrens.Count == 0)
                {
                    foreach (TeacherChildren tc in t.TeacherChildrens)
                    {
                        teacherInDB.TeacherChildrens.Add(tc);
                    }
                }
                else if (teacherInDB.TeacherChildrens.Count < t.TeacherChildrens.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<TeacherChildren> tcToAdd = t.TeacherChildrens.Except(teacherInDB.TeacherChildrens);
                    if (tcToAdd != null)
                    {
                        foreach (TeacherChildren child in tcToAdd)
                        {
                            teacherInDB.TeacherChildrens.Add(child);
                        }
                    }

                    IEnumerable<TeacherChildren> tcToRemove = teacherInDB.TeacherChildrens.Except(t.TeacherChildrens);
                    if (tcToRemove != null)
                    {
                        foreach (TeacherChildren child in tcToRemove)
                        {
                            teacherInDB.TeacherChildrens.Add(child);
                        }
                    }

                }
                else if (teacherInDB.TeacherChildrens.Count > t.TeacherChildrens.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<TeacherChildren> tcToAdd = t.TeacherChildrens.Except(teacherInDB.TeacherChildrens);
                    if (tcToAdd != null)
                    {
                        foreach (TeacherChildren child in tcToAdd)
                        {
                            teacherInDB.TeacherChildrens.Add(child);
                        }
                    }

                    IEnumerable<TeacherChildren> tcToRemove = teacherInDB.TeacherChildrens.Except(t.TeacherChildrens);
                    if (tcToRemove != null)
                    {
                        foreach (TeacherChildren child in tcToRemove)
                        {
                            teacherInDB.TeacherChildrens.Add(child);
                        }
                    }
                }
                else if (teacherInDB.TeacherChildrens.Count == t.TeacherChildrens.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<TeacherChildren> tcToAdd = t.TeacherChildrens.Except(teacherInDB.TeacherChildrens);
                    if (tcToAdd != null)
                    {
                        foreach (TeacherChildren child in tcToAdd)
                        {
                            teacherInDB.TeacherChildrens.Add(child);
                        }
                    }

                    IEnumerable<TeacherChildren> tcToRemove = teacherInDB.TeacherChildrens.Except(t.TeacherChildrens);
                    if (tcToRemove != null)
                    {
                        foreach (TeacherChildren child in tcToRemove)
                        {
                            teacherInDB.TeacherChildrens.Add(child);
                        }
                    }

                }

                //2nd Part
                if (teacherInDB.TeacherEligibilities.Count == 0)
                {
                    foreach (TeacherEligibility te in t.TeacherEligibilities)
                    {
                        teacherInDB.TeacherEligibilities.Add(te);
                    }
                }
                else if (teacherInDB.TeacherEligibilities.Count < t.TeacherEligibilities.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<TeacherEligibility> tcToAdd = t.TeacherEligibilities.Except(teacherInDB.TeacherEligibilities);
                    if (tcToAdd != null)
                    {
                        foreach (TeacherEligibility child in tcToAdd)
                        {
                            teacherInDB.TeacherEligibilities.Add(child);
                        }
                    }

                    IEnumerable<TeacherEligibility> tcToRemove = teacherInDB.TeacherEligibilities.Except(t.TeacherEligibilities);
                    if (tcToRemove != null)
                    {
                        foreach (TeacherEligibility child in tcToRemove)
                        {
                            teacherInDB.TeacherEligibilities.Add(child);
                        }
                    }

                }
                else if (teacherInDB.TeacherEligibilities.Count > t.TeacherEligibilities.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<TeacherEligibility> tcToAdd = t.TeacherEligibilities.Except(teacherInDB.TeacherEligibilities);
                    if (tcToAdd != null)
                    {
                        foreach (TeacherEligibility child in tcToAdd)
                        {
                            teacherInDB.TeacherEligibilities.Add(child);
                        }
                    }

                    IEnumerable<TeacherEligibility> tcToRemove = teacherInDB.TeacherEligibilities.Except(t.TeacherEligibilities);
                    if (tcToRemove != null)
                    {
                        foreach (TeacherEligibility child in tcToRemove)
                        {
                            teacherInDB.TeacherEligibilities.Add(child);
                        }
                    }
                }
                else if (teacherInDB.TeacherEligibilities.Count == t.TeacherEligibilities.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<TeacherEligibility> tcToAdd = t.TeacherEligibilities.Except(teacherInDB.TeacherEligibilities);
                    if (tcToAdd != null)
                    {
                        foreach (TeacherEligibility child in tcToAdd)
                        {
                            teacherInDB.TeacherEligibilities.Add(child);
                        }
                    }

                    IEnumerable<TeacherEligibility> tcToRemove = teacherInDB.TeacherEligibilities.Except(t.TeacherEligibilities);
                    if (tcToRemove != null)
                    {
                        foreach (TeacherEligibility child in tcToRemove)
                        {
                            teacherInDB.TeacherEligibilities.Add(child);
                        }
                    }

                }

                //3rd Part
                if (teacherInDB.TeacherEducationalBackgrounds.Count == 0)
                {
                    foreach (TeacherEducationalBackground eb in t.TeacherEducationalBackgrounds)
                    {
                        teacherInDB.TeacherEducationalBackgrounds.Add(eb);
                    }
                }

                else if (teacherInDB.TeacherEducationalBackgrounds.Count < t.TeacherEducationalBackgrounds.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<TeacherEducationalBackground> tcToAdd = t.TeacherEducationalBackgrounds.Except(teacherInDB.TeacherEducationalBackgrounds);
                    if (tcToAdd != null)
                    {
                        foreach (TeacherEducationalBackground child in tcToAdd)
                        {
                            teacherInDB.TeacherEducationalBackgrounds.Add(child);
                        }
                    }

                    IEnumerable<TeacherEducationalBackground> tcToRemove = teacherInDB.TeacherEducationalBackgrounds.Except(t.TeacherEducationalBackgrounds);
                    if (tcToRemove != null)
                    {
                        foreach (TeacherEducationalBackground child in tcToRemove)
                        {
                            teacherInDB.TeacherEducationalBackgrounds.Add(child);
                        }
                    }

                }
                else if (teacherInDB.TeacherEducationalBackgrounds.Count > t.TeacherEducationalBackgrounds.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<TeacherEducationalBackground> tcToAdd = t.TeacherEducationalBackgrounds.Except(teacherInDB.TeacherEducationalBackgrounds);
                    if (tcToAdd != null)
                    {
                        foreach (TeacherEducationalBackground child in tcToAdd)
                        {
                            teacherInDB.TeacherEducationalBackgrounds.Add(child);
                        }
                    }

                    IEnumerable<TeacherEducationalBackground> tcToRemove = teacherInDB.TeacherEducationalBackgrounds.Except(t.TeacherEducationalBackgrounds);
                    if (tcToRemove != null)
                    {
                        foreach (TeacherEducationalBackground child in tcToRemove)
                        {
                            teacherInDB.TeacherEducationalBackgrounds.Add(child);
                        }
                    }
                }
                else if (teacherInDB.TeacherEducationalBackgrounds.Count == t.TeacherEducationalBackgrounds.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<TeacherEducationalBackground> tcToAdd = t.TeacherEducationalBackgrounds.Except(teacherInDB.TeacherEducationalBackgrounds);
                    if (tcToAdd != null)
                    {
                        foreach (TeacherEducationalBackground child in tcToAdd)
                        {
                            teacherInDB.TeacherEducationalBackgrounds.Add(child);
                        }
                    }

                    IEnumerable<TeacherEducationalBackground> tcToRemove = teacherInDB.TeacherEducationalBackgrounds.Except(t.TeacherEducationalBackgrounds);
                    if (tcToRemove != null)
                    {
                        foreach (TeacherEducationalBackground child in tcToRemove)
                        {
                            teacherInDB.TeacherEducationalBackgrounds.Add(child);
                        }
                    }

                }

                //4th Part
                if (teacherInDB.TrainingSeminars.Count == 0)
                {
                    foreach (TrainingSeminar ts in t.TrainingSeminars)
                    {
                        teacherInDB.TrainingSeminars.Add(ts);
                    }
                }
                else if (teacherInDB.TrainingSeminars.Count < t.TrainingSeminars.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<TrainingSeminar> tcToAdd = t.TrainingSeminars.Except(teacherInDB.TrainingSeminars);
                    if (tcToAdd != null)
                    {
                        foreach (TrainingSeminar child in tcToAdd)
                        {
                            teacherInDB.TrainingSeminars.Add(child);
                        }
                    }

                    IEnumerable<TrainingSeminar> tcToRemove = teacherInDB.TrainingSeminars.Except(t.TrainingSeminars);
                    if (tcToRemove != null)
                    {
                        foreach (TrainingSeminar child in tcToRemove)
                        {
                            teacherInDB.TrainingSeminars.Add(child);
                        }
                    }

                }
                else if (teacherInDB.TrainingSeminars.Count > t.TrainingSeminars.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<TrainingSeminar> tcToAdd = t.TrainingSeminars.Except(teacherInDB.TrainingSeminars);
                    if (tcToAdd != null)
                    {
                        foreach (TrainingSeminar child in tcToAdd)
                        {
                            teacherInDB.TrainingSeminars.Add(child);
                        }
                    }

                    IEnumerable<TrainingSeminar> tcToRemove = teacherInDB.TrainingSeminars.Except(t.TrainingSeminars);
                    if (tcToRemove != null)
                    {
                        foreach (TrainingSeminar child in tcToRemove)
                        {
                            teacherInDB.TrainingSeminars.Add(child);
                        }
                    }
                }
                else if (teacherInDB.TrainingSeminars.Count == t.TrainingSeminars.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<TrainingSeminar> tcToAdd = t.TrainingSeminars.Except(teacherInDB.TrainingSeminars);
                    if (tcToAdd != null)
                    {
                        foreach (TrainingSeminar child in tcToAdd)
                        {
                            teacherInDB.TrainingSeminars.Add(child);
                        }
                    }

                    IEnumerable<TrainingSeminar> tcToRemove = teacherInDB.TrainingSeminars.Except(t.TrainingSeminars);
                    if (tcToRemove != null)
                    {
                        foreach (TrainingSeminar child in tcToRemove)
                        {
                            teacherInDB.TrainingSeminars.Add(child);
                        }
                    }

                }

                //5th Part
                if (teacherInDB.WorkExperiences.Count == 0)
                {
                    foreach (WorkExperience we in t.WorkExperiences)
                    {
                        teacherInDB.WorkExperiences.Add(we);
                    }
                }
                else if (teacherInDB.WorkExperiences.Count < t.WorkExperiences.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<WorkExperience> tcToAdd = t.WorkExperiences.Except(teacherInDB.WorkExperiences);
                    if (tcToAdd != null)
                    {
                        foreach (WorkExperience child in tcToAdd)
                        {
                            teacherInDB.WorkExperiences.Add(child);
                        }
                    }

                    IEnumerable<WorkExperience> tcToRemove = teacherInDB.WorkExperiences.Except(t.WorkExperiences);
                    if (tcToRemove != null)
                    {
                        foreach (WorkExperience child in tcToRemove)
                        {
                            teacherInDB.WorkExperiences.Add(child);
                        }
                    }

                }
                else if (teacherInDB.WorkExperiences.Count > t.WorkExperiences.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<WorkExperience> tcToAdd = t.WorkExperiences.Except(teacherInDB.WorkExperiences);
                    if (tcToAdd != null)
                    {
                        foreach (WorkExperience child in tcToAdd)
                        {
                            teacherInDB.WorkExperiences.Add(child);
                        }
                    }

                    IEnumerable<WorkExperience> tcToRemove = teacherInDB.WorkExperiences.Except(t.WorkExperiences);
                    if (tcToRemove != null)
                    {
                        foreach (WorkExperience child in tcToRemove)
                        {
                            teacherInDB.WorkExperiences.Add(child);
                        }
                    }
                }
                else if (teacherInDB.WorkExperiences.Count == t.WorkExperiences.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<WorkExperience> tcToAdd = t.WorkExperiences.Except(teacherInDB.WorkExperiences);
                    if (tcToAdd != null)
                    {
                        foreach (WorkExperience child in tcToAdd)
                        {
                            teacherInDB.WorkExperiences.Add(child);
                        }
                    }

                    IEnumerable<WorkExperience> tcToRemove = teacherInDB.WorkExperiences.Except(t.WorkExperiences);
                    if (tcToRemove != null)
                    {
                        foreach (WorkExperience child in tcToRemove)
                        {
                            teacherInDB.WorkExperiences.Add(child);
                        }
                    }
                }
                using (var DC = new DCFIEntities())
                {
                    //   DC.Teachers.Remove(teacherInDB);
                    teacherInDB = t;

                    foreach (TeacherChildren tc in teacherInDB.TeacherChildrens)
                        DC.Entry(tc).State = tc.ChildId == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;

                    foreach (TeacherEducationalBackground tc in teacherInDB.TeacherEducationalBackgrounds)
                        DC.Entry(tc).State = tc.TEBId == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;

                    foreach (TeacherEligibility tc in teacherInDB.TeacherEligibilities)
                        DC.Entry(tc).State = tc.EligibilityId == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;

                    foreach (TrainingSeminar tc in teacherInDB.TrainingSeminars)
                        DC.Entry(tc).State = tc.TSID == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;

                    foreach (WorkExperience tc in teacherInDB.WorkExperiences)
                        DC.Entry(tc).State = tc.WEId == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;

                    DC.Entry(teacherInDB).State = System.Data.Entity.EntityState.Modified;

                    int num = DC.SaveChanges();

                    if (num > 0)
                    {
                        //  ret = false;
                        message = "No teacher is updated.";
                    }
                }
            }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                                validationError.PropertyName,
                                                validationError.ErrorMessage);
                    }
                }
            }
            return ret;
        }
Example #2
0
        public Boolean CreateTeacher(ref TeacherBDO teacher, ref string message)
        {
            message = "Teacher Added Successfully";
            bool ret = true;
            Teacher t = new Teacher();
            try {
            ConvertTeacherBDOToTeacher(teacher, t);
            using (var DCEnt = new DCFIEntities())
            {
                DCEnt.Teachers.Add(t);

                DCEnt.SaveChanges();
              }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                                validationError.PropertyName,
                                                validationError.ErrorMessage);
                    }
                }
            }
            return ret;
        }
Example #3
0
 public void ConvertTeacherToTeacherBDO(Teacher teacher, TeacherBDO tb)
 {
     tb.TeacherId = teacher.TeacherId;
     tb.LastName = teacher.LastName;
     tb.FirstName = teacher.FirstName;
     tb.MiddleName = teacher.MiddleName;
     tb.Deactivated = teacher.Deactivated;
     tb.Gender = teacher.Gender;
     tb.DOB = teacher.DOB;
     tb.TIN = teacher.TIN;
     tb.DateOfAppointment = teacher.DateOfAppointment;
     tb.EmploymentStatus = teacher.EmploymentStatus;
     tb.POBProvince = teacher.POBProvince;
     tb.POBMunicipality = teacher.POBMunicipality;
     tb.CivilStatus = teacher.CivilStatus;
     tb.HeightCm = teacher.HeightCm;
     tb.WeightKg = teacher.WeightKg;
     tb.BloodType = teacher.BloodType;
     tb.SSSNum = teacher.SSSNum;
     tb.PagIBIGNo = teacher.PagIBIGNo;
     tb.PhilHealthNo = teacher.PhilHealthNo;
     tb.RAStreetName = teacher.RAStreetName;
     tb.RARegion = teacher.RARegion;
     tb.RAProvince = teacher.RAProvince;
     tb.RAMunicipality = teacher.RAMunicipality;
     tb.ResTelephoneNo = teacher.ResTelephoneNo;
     tb.PAStreetName = teacher.PAStreetName;
     tb.PARegion = teacher.PARegion;
     tb.PAProvince = teacher.PAProvince;
     tb.PAMunicipality = teacher.PAMunicipality;
     tb.EmailAddress = teacher.EmailAddress;
     tb.MobileNo = teacher.MobileNo;
     tb.PreviousSchool = teacher.PreviousSchool;
     tb.DialectSpoken = teacher.DialectSpoken;
     tb.SpouseLastName = teacher.SpouseLastName;
     tb.SpouseFirstName = teacher.SpouseFirstName;
     tb.SpouseMiddleName = teacher.SpouseMiddleName;
     tb.SpouseOccupation = teacher.SpouseOccupation;
     tb.SpouseBusinessAdd = teacher.SpouseBusinessAdd;
     tb.SpouseEmployerName = teacher.SpouseEmployerName;
     tb.SpouseTelephoneNo = teacher.SpouseTelephoneNo;
     tb.PERAA = teacher.PERAA;
     tb.Image = teacher.Image;
     if (teacher.Academic == null)
         tb.Academic = true;
     else
         tb.Academic = (bool)teacher.Academic;
 }
Example #4
0
        public void ConvertTeacherBDOToTeacher(TeacherBDO teacher, Teacher tb)
        {
            ICollection<TeacherChildren> tc = new List<TeacherChildren>();
            tc = ToChildrenList(teacher.TeacherChildrens);

            ICollection<TeacherEligibility> te = new List<TeacherEligibility>();
            te = ToEligibilityList(teacher.TeacherEligibilities);

            ICollection<TeacherEducationalBackground> eb = new List<TeacherEducationalBackground>();
            eb = ToEducationalBackList(teacher.TeacherEducationalBackgrounds);

            ICollection<TrainingSeminar> ts = new List<TrainingSeminar>();
            ts = ToTrainingSeminarList(teacher.TrainingSeminars);

            ICollection<WorkExperience> we = new List<WorkExperience>();
            we = ToWorkExperienceList(teacher.WorkExperiences);

            tb.TeacherId = teacher.TeacherId;
            tb.LastName = teacher.LastName;
            tb.FirstName = teacher.FirstName;
            tb.MiddleName = teacher.MiddleName;
            tb.Deactivated = teacher.Deactivated;
            tb.Gender = teacher.Gender;
            tb.DOB = teacher.DOB;
            tb.TIN = teacher.TIN;
            tb.DateOfAppointment = teacher.DateOfAppointment;
            tb.EmploymentStatus = teacher.EmploymentStatus;
            tb.POBProvince = teacher.POBProvince;
            tb.POBMunicipality = teacher.POBMunicipality;
            tb.CivilStatus = teacher.CivilStatus;
            tb.HeightCm = teacher.HeightCm;
            tb.WeightKg = teacher.WeightKg;
            tb.BloodType = teacher.BloodType;
            tb.SSSNum = teacher.SSSNum;
            tb.PagIBIGNo = teacher.PagIBIGNo;
            tb.PhilHealthNo = teacher.PhilHealthNo;
            tb.RAStreetName = teacher.RAStreetName;
            tb.RARegion = teacher.RARegion;
            tb.RAProvince = teacher.RAProvince;
            tb.RAMunicipality = teacher.RAMunicipality;
            tb.ResTelephoneNo = teacher.ResTelephoneNo;
            tb.PAStreetName = teacher.PAStreetName;
            tb.PARegion = teacher.PARegion;
            tb.PAProvince = teacher.PAProvince;
            tb.PAMunicipality = teacher.PAMunicipality;
            tb.EmailAddress = teacher.EmailAddress;
            tb.MobileNo = teacher.MobileNo;
            tb.PreviousSchool = teacher.PreviousSchool;
            tb.DialectSpoken = teacher.DialectSpoken;
            tb.SpouseLastName = teacher.SpouseLastName;
            tb.SpouseFirstName = teacher.SpouseFirstName;
            tb.SpouseMiddleName = teacher.SpouseMiddleName;
            tb.SpouseOccupation = teacher.SpouseOccupation;
            tb.SpouseBusinessAdd = teacher.SpouseBusinessAdd;
            tb.SpouseEmployerName = teacher.SpouseEmployerName;
            tb.SpouseTelephoneNo = teacher.SpouseTelephoneNo;
            tb.PERAA = teacher.PERAA;
            tb.Image = teacher.Image;
            tb.TeacherChildrens = tc;
            tb.TeacherEligibilities = te;
            tb.TeacherEducationalBackgrounds = eb;
            tb.TrainingSeminars = ts;
            tb.WorkExperiences = we;
            tb.Academic = teacher.Academic;
        }
Example #5
0
        public Boolean CreateTeacher(ref TeacherBDO teacher, ref string message)
        {
            message = "Teacher Added Successfully";
            bool ret = true;
            Teacher t = new Teacher();
            ConvertTeacherBDOToTeacher(teacher, t);
            using (var DCEnt = new DCFIEntities())
            {
                DCEnt.Teachers.Add(t);

                DCEnt.SaveChanges();


            }
            return ret;
        }