public bool AddFaculty(NewFaculty toAdd)
 {
     Faculty f = this._repository.GetFaculty(toAdd.FacultyName);
     if (f != null)
         toAdd.AddError("Kierunek o takiej nazwie już istnieje");
     if (toAdd.IsValid)
     {
         this._repository.AddFaculty(toAdd);
         return true;
     }
     return false;
 }
        public void AddFaculty(NewFaculty toAdd)
        {
            if (toAdd != null)
            {
                Faculty f = new Faculty()
                {
                    Name = toAdd.FacultyName,
                };
                foreach (Departament d in toAdd.Departaments)
                {
                    f.Departaments.Add(d);
                }

                SPDatabase.DB.Faculties.AddObject(f);
                SPDatabase.DB.SaveChanges();
            }
        }
        private void btnAddFaculty_Click(object sender, EventArgs e)
        {
            lblValidation.Text = string.Empty;
            NewFaculty toAdd = new NewFaculty()
            {
                FacultyName = tbNewFacultyName.Text
            };
            List<string> list = clbDepartaments.CheckedItems.Cast<string>().ToList<string>();
            if (list != null && list.Count > 0)
            {
                List<Departament> departaments = new List<Departament>();
                foreach (string name in list)
                {
                    Departament d = DepartamentController.Instance.GetDepartament(name);
                    if (d != null)
                        departaments.Add(d);
                }
                toAdd.Departaments = departaments.AsEnumerable();
            }
            else
                toAdd.Departaments = null;

            if (!FacultyController.Instance.AddFaculty(toAdd))
            {
                string errors = string.Empty;
                foreach (string error in toAdd.Errors)
                    errors = errors + error + "\n";
                lblValidation.Text = errors;
            }
            else
            {
                FillWithFaculties(null);
                cbDepartamentFilter.SelectedIndex = 0;
                Clear();
                changes = true;
            }
        }
 public void Init()
 {
     _newFaculty = new NewFaculty();
 }