private static void Initalize(SPItemEventDataCollection afterProperties, ITrainingCourseRepository repository, SPWeb web, out string title, out string code, out DateTime enrollmentDate, out DateTime startDate, out DateTime endDate, out float cost)
        {
            title          = ((string)afterProperties[repository.GetFieldName(new Guid(Fields.Title), web)]).Trim();
            code           = ((string)afterProperties[repository.GetFieldName(new Guid(Fields.TrainingCourseCode), web)]).Trim();
            enrollmentDate = Convert.ToDateTime(afterProperties[repository.GetFieldName(new Guid(Fields.TrainingCourseEnrollmentDate), web)]).ToUniversalTime();;
            startDate      = Convert.ToDateTime(afterProperties[repository.GetFieldName(new Guid(Fields.TrainingCourseStartDate), web)]).ToUniversalTime();;
            endDate        = Convert.ToDateTime(afterProperties[repository.GetFieldName(new Guid(Fields.TrainingCourseEndDate), web)]).ToUniversalTime();
            cost           = Convert.ToSingle(afterProperties[repository.GetFieldName(new Guid(Fields.TrainingCourseCost), web)]);

            afterProperties[repository.GetFieldName(new Guid(Fields.Title), web)] = title;
            afterProperties[repository.GetFieldName(new Guid(Fields.TrainingCourseCode), web)] = code;
        }
        public override void ItemUpdating(SPItemEventProperties properties)
        {
            bool          isValid      = true;
            StringBuilder errorMessage = new StringBuilder();

            string   title          = string.Empty;
            string   code           = string.Empty;
            DateTime enrollmentDate = DateTime.MinValue;
            DateTime startDate      = DateTime.MinValue;
            DateTime endDate        = DateTime.MinValue;
            float    cost           = 0;

            using (SPWeb web = properties.OpenWeb())
            {
                ITrainingCourseRepository repository = ServiceLocator.GetInstance().Get <ITrainingCourseRepository>();
                Initalize(properties.AfterProperties, repository, web, out title, out code, out enrollmentDate, out startDate, out endDate, out cost);

                if (properties.ListItem[repository.GetFieldName(new Guid(Fields.TrainingCourseCode), web)].ToString() != code)
                {
                    if (ValidateCourseCodeExists(repository, code, errorMessage, web))
                    {
                        isValid = false;
                    }
                }
            }

            isValid = isValid & ValidateCourseCode(code, errorMessage);
            isValid = isValid & ValidateStartDate(enrollmentDate, startDate, errorMessage);
            isValid = isValid & ValidateEndDate(startDate, endDate, errorMessage);
            isValid = isValid & ValidateCourseCost(cost, errorMessage);

            //if any of the rules fail, set an error message and set the
            //Cancel property to true to instruct SharePoint to redirect to
            //standard error page.
            if (!isValid)
            {
                properties.ErrorMessage = errorMessage.ToString();
                properties.Cancel       = true;
            }
        }