public bool AddInstitute(NewInstitute toAdd) { Institute i = this.repository.GetInstitute(toAdd.InstituteName); if (i != null) toAdd.AddError("Instytut o takiej nazwie już istnieje"); if (toAdd.IsValid) { this.repository.AddInstitute(toAdd); return true; } return false; }
public void AddInstitute(NewInstitute toAdd) { if (toAdd != null) { Institute i = new Institute() { Name = toAdd.InstituteName, }; foreach (Departament d in toAdd.Departaments) { i.Departaments.Add(d); } SPDatabase.DB.Institutes.AddObject(i); SPDatabase.DB.SaveChanges(); } }
private void btnAdd_Click(object sender, EventArgs e) { lblValidation.Text = string.Empty; NewInstitute toAdd = new NewInstitute() { InstituteName = tbNewInstituteName.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 (!InstituteController.Instance.AddInstitute(toAdd)) { string errors = string.Empty; foreach (string error in toAdd.Errors) errors = errors + error + "\n"; lblValidation.Text = errors; } else { FillWithInstitutes(null); cbDepartamentFilter.SelectedIndex = 0; Clear(); changes = true; } }