public void DeleteRule(Rule rule)
 {
     if (rule != null)
     {
         SPDatabase.DB.Rules.DeleteObject(rule);
         SPDatabase.DB.SaveChanges();
     }
 }
        public bool DeleteRule(Rule rule)
        {
            if (rule != null)
            {
                _repository.DeleteRule(rule);
                return true;
            }

            else
            {
                RadMessageBox.Show(
                        "Nastąpił błąd - nie można usunąć reguły", "Usuwanie reguły", MessageBoxButtons.OK, RadMessageIcon.Error);
                return false;
            }
        }
        public void AddRule(Rule rule)
        {
            if (rule != null)
            {
                Rule ruleToAdd = new Rule()
                {
                    PlanId = rule.PlanId,
                    Description = rule.Description,
                    Value = rule.Value,
                    Semester = rule.Semester,
                    Subject = rule.Subject,
                    SubjectType = rule.SubjectType
                };

                SPDatabase.DB.Rules.AddObject(ruleToAdd);
                SPDatabase.DB.SaveChanges();
            }
        }
 private bool ValidateTotalEctsCount(Rule rule)
 {
     if (_selectedPlan.SubjectsDatas.Count != 0)
     {
         double ectsCount = 0;
         foreach (SubjectsData sd in _selectedPlan.SubjectsDatas)
         {
             if(rule.Semester == 0)
                 ectsCount += sd.Ects;
             else
             {
                 if (sd.Semester.Semester1.Equals(rule.Semester))
                     ectsCount += sd.Ects;
             }
         }
         if (rule.Value.Equals(ectsCount))
             return true;
         else
             return false;
     }
     return false;
 }
        private bool ValidateTotalHoursSubjectTypeCount(Rule rule)
        {
            double hoursCount = 0;

            if (_selectedPlan.SubjectsDatas.Count != 0)
            {
                foreach (SubjectsData sd in _selectedPlan.SubjectsDatas)
                {
                    foreach (SubjectTypesData st in sd.SubjectTypesDatas)
                    {
                        if (st.SubjectType.Name.Equals(rule.Subject))
                        {
                            if (rule.Semester == 0)
                                hoursCount += st.Hours;
                            else
                            {
                                if (sd.Semester.Semester1.Equals(rule.Semester))
                                    hoursCount += st.Hours;
                            }
                        }
                    }
                }
                if (rule.Value.Equals(hoursCount))
                    return true;
                else
                    return false;
            }
            return false;
        }
 private void AddTotalHoursSubjectTypeRule()
 {
     double parseValue;
     double.TryParse(tbHoursSubjectTypeCount.Text, out parseValue);
     if (parseValue != 0)
     {
         Rule newRule = new Rule()
         {
             PlanId = _selectedPlan.PlanID,
             Description = "Total Hours Subject Type Count",
             Semester = (short)ddlSemester.SelectedIndex,
             SubjectType = ddlHoursSubjectType.SelectedText,
             Value = parseValue
         };
         _rulesRepository.AddRule(newRule);
     }
     else
     {
         if (ddlHoursSubjectType.SelectedIndex == -1)
             RadMessageBox.Show(
                 "Nastąpił błąd - nie wybrano typu przedmiotu. \nReguła nie zostanie " +
                 "dodana", "Sumaryczna liczba godzin dla przedmiotu typu:" + ddlHoursSubjectType.SelectedText, MessageBoxButtons.OK, RadMessageIcon.Error);
         else
             RadMessageBox.Show(
                 "Nastąpił błąd - podana liczba godzin jest nieprawidłowa. \nReguła nie zostanie " +
                 "dodana", "Sumaryczna liczba godzin dla przedmiotu typu:" + ddlHoursSubjectType.SelectedText, MessageBoxButtons.OK, RadMessageIcon.Error);
     }
 }
 private void AddTotalHoursRule()
 {
     double parseValue;
     double.TryParse(tbHoursCount.Text, out parseValue);
     if (parseValue != 0)
     {
         Rule newRule = new Rule()
         {
             PlanId = _selectedPlan.PlanID,
             Description = "Total Hours Count",
             Semester = (short)ddlSemester.SelectedIndex,
             Value = parseValue
         };
         _rulesRepository.AddRule(newRule);
     }
     else
     {
             RadMessageBox.Show(
                 "Nastąpił błąd - podana liczba godzin jest nieprawidłowa. \nReguła nie zostanie " +
                 "dodana", "Sumaryczna liczba godzin", MessageBoxButtons.OK, RadMessageIcon.Error);
     }
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Rules EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRules(Rule rule)
 {
     base.AddObject("Rules", rule);
 }
 /// <summary>
 /// Create a new Rule object.
 /// </summary>
 /// <param name="ruleId">Initial value of the RuleId property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 /// <param name="value">Initial value of the Value property.</param>
 /// <param name="semester">Initial value of the Semester property.</param>
 /// <param name="planId">Initial value of the PlanId property.</param>
 public static Rule CreateRule(global::System.Int32 ruleId, global::System.String description, global::System.Double value, global::System.Int16 semester, global::System.Int32 planId)
 {
     Rule rule = new Rule();
     rule.RuleId = ruleId;
     rule.Description = description;
     rule.Value = value;
     rule.Semester = semester;
     rule.PlanId = planId;
     return rule;
 }