public void DeleteSubjectType(SubjectTypeEdit toEdit)
 {
     SubjectType st = this.repository.GetSubjectType(toEdit.SubjectTypeName);
     if (st != null && st.SubjectTypesDatas.Count > 0)
         throw new UpdateException("Nie można usunąć typu przedmiotu,\nponieważ posiada powiązania");
     else
         this.repository.DeleteSubjectType(st);
 }
        public SubjectTypeEdit GetSubjectTypeEdit(string subjectTypeName)
        {
            SubjectType st = this.GetSubjectType(subjectTypeName);
            if (st != null)
            {
                SubjectTypeEdit ste = new SubjectTypeEdit()
                {
                    SubjectTypeID = st.SubjectTypeID,
                    SubjectTypeName = st.Name
                };
                return ste;
            }

            return null;
        }
        public bool EditSubjectType(SubjectTypeEdit toEdit)
        {
            if (toEdit != null)
            {
                SubjectType st = this.repository.GetSubjectType(toEdit.SubjectTypeName);
                if (st != null && st.SubjectTypeID != toEdit.SubjectTypeID && st.Name.ToLower().Equals(toEdit.SubjectTypeName.ToLower()))
                    toEdit.AddError("Typ przedmiotu o takiej nazwie\njuż istnieje");

                if (toEdit.IsValid)
                {
                    st = this.repository.GetSubjectType(toEdit.SubjectTypeID);
                    st.Name = toEdit.SubjectTypeName;

                    this.repository.EditSubjectType(st);
                    return true;
                }
            }
            return false;
        }
 private void listSubjectTypes_DoubleClick(object sender, EventArgs e)
 {
     lblValidation.Text = string.Empty;
     if (listSubjectTypes.SelectedIndex >= 0)
     {
         SubjectTypeEdit subjectType = SubjectTypeController.Instance.GetSubjectTypeEdit(listSubjectTypes.SelectedItem.ToString());
         if (subjectType != null)
         {
             toEdit = subjectType;
             Enable();
             tbNewSubjectTypeName.Text = subjectType.SubjectTypeName;
         }
         else
         {
             lblValidation.Text = "Typ przedmiotu 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
         {
             SubjectTypeController.Instance.DeleteSubjectType(toEdit);
             FillWithSubjectTypes();
             toEdit = null;
             Disable();
             Clear();
             changes = true;
         }
         catch (UpdateException ex)
         {
             lblValidation.Text = ex.Message;
         }
     }
 }