public void DeleteSpecialization(SpecializationEdit toEdit)
 {
     Specialization s = this.repository.GetSpecialization(toEdit.SpecializationName);
     if (s != null && s.SpecializationsDatas.Count > 0)
         throw new UpdateException("Nie można usunąć specjalizacji,\nponieważ posiada powiązania");
     else
     {
         this.repository.DeleteSpecialization(s);
     }
 }
        public SpecializationEdit GetSpecializationEdit(string specializationName, string departamentName, string facultyName)
        {
            Specialization s = this.repository.GetSpecialization(specializationName, departamentName, facultyName);
            if (s != null)
            {
                SpecializationEdit se = new SpecializationEdit()
                {
                    DepartamentId = s.DepartamentID,
                    FacultyId = s.FacultyID,
                    SpecializationID = s.SpecializationID,
                    SpecializationName = s.Name
                };
                return se;
            }

            return null;
        }
        public SpecializationEdit GetSpecializationEdit(string specializationame)
        {
            Specialization s = this.GetSpecialization(specializationame);
            if (s != null)
            {
                SpecializationEdit ss = new SpecializationEdit()
                {
                    SpecializationID = s.SpecializationID,
                    SpecializationName = s.Name,
                    DepartamentId = s.DepartamentID,
                    FacultyId = s.FacultyID
                };
                return ss;
            }

            return null;
        }
        private void gridSpecializations_CellDoubleClick(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                SpecializationEdit specialization = SpecializationController.Instance.GetSpecializationEdit(gridSpecializations.Rows[e.RowIndex].Cells["name"].Value.ToString(),
                                                    gridSpecializations.Rows[e.RowIndex].Cells["departament"].Value.ToString(), gridSpecializations.Rows[e.RowIndex].Cells["faculty"].Value.ToString());
                if (specialization != null)
                {
                    toEdit = specialization;
                    Enable();
                    tbNewSpecializationName.Text = specialization.SpecializationName;

                    Departament dep = DepartamentController.Instance.GetDepartament(specialization.DepartamentId);
                    Faculty fac = FacultyController.Instance.GetFaculty(specialization.FacultyId);

                    if (dep != null)
                        for (int i = 0; i < lstDepartaments.Items.Count; i++)
                            if (lstDepartaments.Items[i].Text.Equals(dep.Name))
                                lstDepartaments.SelectedIndex = i;
                    //lstDepartaments.SelectedItem.Value = dep.Name;

                    if (fac != null && dep != null)
                        for (int i = 0; i < lstFaculties.Items.Count; i++)
                            if (lstFaculties.Items[i].Text.Equals(fac.Name))
                                lstFaculties.SelectedIndex = i;
                    //lstFaculties.SelectedItem.Value = fac.Name;
                }
                else
                {
                    lblValidation.Text = "Specjalizacja nie istnieje";
                    toEdit = null;
                }
            }
        }
 private void btnCancel_Click(object sender, EventArgs e)
 {
     if (toEdit != null)
     {
         toEdit = null;
         Disable();
         Clear();
     }
 }
 private void btnDelete_Click(object sender, EventArgs e)
 {
     lblValidation.Text = string.Empty;
     if (toEdit != null)
     {
         try
         {
             SpecializationController.Instance.DeleteSpecialization(toEdit);
             FillWithSpecializations();
             toEdit = null;
             Disable();
             Clear();
             changes = true;
         }
         catch (UpdateException ex)
         {
             lblValidation.Text = ex.Message;
         }
     }
 }
        public bool EditSpecialization(SpecializationEdit toEdit)
        {
            if (toEdit != null)
            {
                Specialization s = this.repository.GetSpecialization(toEdit.SpecializationName, toEdit.DepartamentId, toEdit.FacultyId);
                if (s != null && s.SpecializationID != toEdit.SpecializationID && s.Name.ToLower().Equals(toEdit.SpecializationName.ToLower())
                    && s.FacultyID == toEdit.FacultyId && s.DepartamentID == toEdit.DepartamentId)
                    toEdit.AddError("Specjalizacja o takich danych\njuż istnieje");

                if (toEdit.DepartamentId == 0 || toEdit.FacultyId == 0)
                    toEdit.AddError("Wydział lub kierunek nie istnieje");

                if (toEdit.IsValid)
                {
                    s = this.repository.GetSpecialization(toEdit.SpecializationID);
                    s.Name = toEdit.SpecializationName;
                    s.FacultyID = toEdit.FacultyId;
                    s.DepartamentID = toEdit.DepartamentId;
                   
                    this.repository.EditSpecialization(s);
                    return true;
                }
            }
            return false;
        }