示例#1
0
        private bool RewardTraining(Member m, Dictionary <Guid, TrainingCourse> courses, Dictionary <Guid, ComputedTrainingAward> awards, TrainingRule rule, DateTime?completed, DateTime?expiry, string newAwardsString)
        {
            IEnumerable <string> results = newAwardsString.Split('+');
            bool awarded = false;

            if (completed < (rule.OfferedFrom ?? DateTime.MinValue) || completed > (rule.OfferedUntil ?? DateTime.MaxValue))
            {
                return(false);
            }

            foreach (string result in results)
            {
                string[] parts  = result.Split(':');
                Guid     course = new Guid(parts[0]);

                if (!courses.ContainsKey(course))
                {
                    throw new InvalidOperationException("Found bad rule: Adds course with ID" + course.ToString());
                }

                if (parts.Length > 1)
                {
                    if (parts[1] == "default")
                    {
                        if (courses[course].ValidMonths.HasValue)
                        {
                            expiry = completed.Value.AddMonths(courses[course].ValidMonths.Value);
                        }
                        else
                        {
                            expiry = null;
                        }
                    }
                    else
                    {
                        expiry = completed.Value.AddMonths(int.Parse(parts[1]));
                    }
                }


                if (awards.ContainsKey(course) && expiry > awards[course].Expiry)
                {
                    awards[course].Completed = completed;
                    awards[course].Expiry    = expiry;
                    awards[course].Rule      = rule;
                    awarded = true;
                    System.Diagnostics.Debug.WriteLineIf(m.LastName == "Kedan", string.Format("Updating existing record {0}, new expiry: {1}", courses[course].DisplayName, expiry));
                }
                else if (!awards.ContainsKey(course))
                {
                    ComputedTrainingAward newAward = new ComputedTrainingAward {
                        Course = courses[course], Member = m, Completed = completed, Expiry = expiry, Rule = rule
                    };
                    awards.Add(course, newAward);
                    this.ComputedTrainingAwards.Add(newAward);
                    awarded = true;
                    System.Diagnostics.Debug.WriteLineIf(m.LastName == "Kedan", string.Format("Add new record {0}, new expiry: {1}", courses[course].DisplayName, expiry));
                }
            }
            return(awarded);
        }
示例#2
0
        private bool RewardTraining(Member m, Dictionary<Guid, TrainingCourse> courses, Dictionary<Guid, ComputedTrainingAward> awards, TrainingRule rule, DateTime? completed, DateTime? expiry, string newAwardsString)
        {
            IEnumerable<string> results = newAwardsString.Split('+');
              bool awarded = false;

              foreach (string result in results)
              {
            string[] parts = result.Split(':');
            Guid course = new Guid(parts[0]);

            if (!courses.ContainsKey(course))
            {
              throw new InvalidOperationException("Found bad rule: Adds course with ID" + course.ToString());
            }

            if (parts.Length > 1)
            {
              if (parts[1] == "default")
              {
            if (courses[course].ValidMonths.HasValue)
            {
              expiry = completed.Value.AddMonths(courses[course].ValidMonths.Value);
            }
            else
            {
              expiry = null;
            }
              }
              else
              {
            expiry = completed.Value.AddMonths(int.Parse(parts[1]));
              }
            }

            if (awards.ContainsKey(course) && expiry > awards[course].Expiry)
            {
              awards[course].Completed = completed;
              awards[course].Expiry = expiry;
              awards[course].Rule = rule;
              awarded = true;
              System.Diagnostics.Debug.WriteLineIf(m.LastName == "Kedan", string.Format("Updating existing record {0}, new expiry: {1}", courses[course].DisplayName, expiry));
            }
            else if (!awards.ContainsKey(course))
            {
              ComputedTrainingAward newAward = new ComputedTrainingAward { Course = courses[course], Member = m, Completed = completed, Expiry = expiry, Rule = rule };
              awards.Add(course, newAward);
              this.ComputedTrainingAwards.Add(newAward);
              awarded = true;
              System.Diagnostics.Debug.WriteLineIf(m.LastName == "Kedan", string.Format("Add new record {0}, new expiry: {1}", courses[course].DisplayName, expiry));
            }
              }
              return awarded;
        }
        protected bool RewardTraining(Member m, Dictionary <Guid, TrainingCourse> courses, Dictionary <Guid, ComputedTrainingAward> awards, TrainingRule rule, DateTime?completed, DateTime?expiry, string newAwardsString)
        {
            IEnumerable <string> results = newAwardsString.Split('+');
            bool awarded = false;

            foreach (string result in results)
            {
                string[] parts  = result.Split(':');
                Guid     course = new Guid(parts[0]);

                if (!courses.ContainsKey(course))
                {
                    throw new InvalidOperationException("Found bad rule: Adds course with ID" + course.ToString());
                }

                if (parts.Length > 1)
                {
                    if (parts[1] == "default")
                    {
                        if (courses[course].ValidMonths.HasValue)
                        {
                            expiry = completed.Value.AddMonths(courses[course].ValidMonths.Value);
                        }
                        else
                        {
                            expiry = null;
                        }
                    }
                    else
                    {
                        expiry = completed.Value.AddMonths(int.Parse(parts[1]));
                    }
                }


                if (awards.ContainsKey(course) && expiry > awards[course].Expiry)
                {
                    awards[course].Completed = completed;
                    awards[course].Expiry    = expiry;
                    awards[course].Rule      = rule;
                    awarded = true;
                }
                else if (!awards.ContainsKey(course))
                {
                    ComputedTrainingAward newAward = new ComputedTrainingAward {
                        Course = courses[course], Member = m, Completed = completed, Expiry = expiry, Rule = rule
                    };
                    awards.Add(course, newAward);
                    db.ComputedTrainingAwards.Add(newAward);
                    awarded = true;
                }
            }
            return(awarded);
        }