public void AddParentToDatabase()
 {
     //Kijkt of input valide is
     if (InputInformationValidator.ValidateAddParentInput(windowAddStudent, ref errorMessage))
     {
         using (DatabaseContext db = new DatabaseContext())
         {
             //Creeer een ouder object
             Parent parent = new Parent()
             {
                 FirstName  = windowAddStudent.AddParentFirstName.Text,
                 LastName   = windowAddStudent.AddParentLastName.Text,
                 Address    = windowAddStudent.AddParentStreet.Text,
                 Postalcode = windowAddStudent.AddParentPostalcode.Text,
                 Residence  = windowAddStudent.AddParentResidence.Text,
                 Email      = windowAddStudent.AddParentEmail.Text,
                 Gender     = windowAddStudent.AddParentGender.SelectedItem.ToString()
             };
             //Check for next step, if it was false, a student cannot be added.
             ParentWasFilledInCorrectly = true;
             db.Parents.Add(parent);
             db.SaveChanges();
             windowOwner.UpdateDataGridPanelWithStudent();
         }
     }
     else
     {
         //Shows specified errors in a messagebox
         MessageBox.Show(errorMessage);
         ParentWasFilledInCorrectly = false;
         errorMessage = null;
     }
 }
        private bool EditParentDatabase()
        {
            bool   succes = true;
            Parent parentTemp;

            //Get parents from database

            using (DatabaseContext db = new DatabaseContext())
            {
                parentTemp = db.Parents.Select(x => x).Where(x => x.ParentID == SelectedStudent.ParentID).SingleOrDefault();
            }
            //If selected user exists, get information from form
            if (parentTemp != null)
            {
                if (InputInformationValidator.ValidateAddParentInput(windowAddStudent, ref errorMessage))
                {
                    parentTemp.FirstName  = windowAddStudent.AddParentFirstName.Text;
                    parentTemp.LastName   = windowAddStudent.AddParentLastName.Text;
                    parentTemp.Email      = windowAddStudent.AddParentEmail.Text;
                    parentTemp.Gender     = windowAddStudent.AddParentGender.SelectedItem.ToString();
                    parentTemp.Address    = windowAddStudent.AddParentStreet.Text;
                    parentTemp.Postalcode = windowAddStudent.AddParentPostalcode.Text;
                    parentTemp.Residence  = windowAddStudent.AddParentResidence.Text;

                    using (DatabaseContext db = new DatabaseContext())
                    {
                        // Mark entity as modified
                        db.Entry(parentTemp).State = System.Data.Entity.EntityState.Modified;

                        //Sla wijzigen op
                        db.SaveChanges();
                        windowOwner.UpdateDataGridPanelWithStudent();
                    }
                }
                else
                {
                    MessageBox.Show(errorMessage);
                    errorMessage = null;
                    succes       = false;
                }
            }
            else
            {
                if (!InputInformationValidator.ValidateAddParentInputReturnTrueWhenFieldsAreEmpty(windowAddStudent))
                {
                    if (InputInformationValidator.ValidateAddParentInput(windowAddStudent, ref errorMessage))
                    {
                        Parent parent = new Parent()
                        {
                            FirstName  = windowAddStudent.AddParentFirstName.Text,
                            LastName   = windowAddStudent.AddParentLastName.Text,
                            Email      = windowAddStudent.AddParentEmail.Text,
                            Gender     = windowAddStudent.AddParentGender.SelectedItem.ToString(),
                            Address    = windowAddStudent.AddParentStreet.Text,
                            Postalcode = windowAddStudent.AddParentPostalcode.Text,
                            Residence  = windowAddStudent.AddParentResidence.Text
                        };
                        using (DatabaseContext db = new DatabaseContext())
                        {
                            db.Parents.Add(parent);
                            db.SaveChanges();
                            int tempParentIDforUser = db.Parents.Max(x => x.ParentID);
                            var queryUser           = db.Users.Select(x => x).Where(x => x.UserID == SelectedStudent.UserID).FirstOrDefault();
                            queryUser.ParentID = tempParentIDforUser;

                            // Mark entity as modified
                            db.Entry(queryUser).State = System.Data.Entity.EntityState.Modified;

                            //Sla wijzigen op
                            db.SaveChanges();
                            windowOwner.UpdateDataGridPanelWithStudent();
                            MessageBox.Show("Ouder informatie is opgeslagen.");
                        }
                    }
                    else
                    {
                        succes = false;
                        MessageBox.Show(errorMessage);
                        errorMessage = null;
                    }
                }
            }
            return(succes);
        }