Beispiel #1
0
        private static object InitItem(string key)
        {
            string[] s = key.Split(new[] { "," }, StringSplitOptions.None);

            switch (s[0].ToLower())
            {
            case "event_types":
                return(TargetData.GetEventTypesRaw());

            case "locations":
                return(TargetData.GetLocationsRaw());

            case "target_audience":
                return(TargetData.GetTargetAudienceRaw());

            case "time_list":
                return(TargetData.GetCachedTimeList());

            case "useraccess":
                return(UserAccess.GetAllUserAccess());

            default:
                return(null);
            }
        }
        public static List <string> Validate(List <Event> events, string username)
        {
            var errors = new List <string>();

            if (events.Count < 1)
            {
                errors.Add("There are no events to save. If you have attempted to save a valid event, please try again");
                return(errors);
            }
            var eventTypes = (from e in TargetData.GetCachedEventTypes()
                              select e.Value).ToList();
            var targetAudiences = (from ta in TargetData.GetCachedTargetAudience()
                                   select ta.Value).ToList();
            var earlyDate = DateTime.Now.AddYears(-1).Date;
            var farDate   = DateTime.Now.AddYears(1).Date;
            var timeList  = (from t in TargetData.GetCachedTimeList()
                             select t.Label).ToList();
            List <TargetData> locationList = TargetData.GetCachedLocations();



            var count = 1;

            foreach (Event e in events)
            {
                e.event_date_raw      = DateTime.Parse(e.event_date);
                e.event_time_from_raw = e.event_date_raw.Date + DateTime.Parse(e.event_time_from).TimeOfDay;
                e.event_time_to_raw   = e.event_date_raw.Date + DateTime.Parse(e.event_time_to).TimeOfDay;
                e.added_by            = username;

                var locationName = (from l in locationList where l.Value == e.location_id.ToString() select l.Label).First();

                if (e.event_name.Length == 0)
                {
                    errors.Add($"Invalid name for event #{count}.");
                }

                if (!eventTypes.Contains(e.event_type_id.ToString()))
                {
                    errors.Add("An invalid Event Type was selected, please check your selection and try again.");
                }
                foreach (int ta in e.target_audiences)
                {
                    if (!targetAudiences.Contains(ta.ToString()))
                    {
                        errors.Add("An invalid Target Audience was selected, please check your selection and try again.");
                    }
                }

                if (e.event_date_raw.Date < earlyDate || e.event_date_raw.Date > farDate)
                {
                    errors.Add($@"For event #{count},  Please select a date within 1 year.");
                }

                if (locationList.FirstOrDefault(l => l.Value == e.location_id.ToString()) == null)
                {
                    errors.Add($"The location for event #{count} at {locationName} could not be found.");
                }

                if (!timeList.Contains(e.event_time_from) || e.event_time_from_raw.TimeOfDay > e.event_time_to_raw.TimeOfDay)
                {
                    errors.Add($@"On event {e.event_name} at {locationName} on {e.event_date}, {e.event_time_from}
                        is not an acceptable time.");
                }

                if (!timeList.Contains(e.event_time_to))
                {
                    errors.Add($@"On event {e.event_name} at {locationName} on {e.event_date}, {e.event_time_to}
                        is not an acceptable time.");
                }

                count++;
            }

            return(errors);
        }