Example #1
0
        public static ActivityData Create(string activityName, string openingHoursHours, string openingHoursMinutes, string closingHoursHours,
                                          string closingHoursMinutes, string openingDays, string studentPrice, string adultPrice,
                                          string energyNeeded, string transport, string duration, string temperature, string category,
                                          string minParticipants, string maxParticipants, string address, string materialNeeded)
        {
            var openingTime = StringUtils.CreateDateFromTextBoxes(openingHoursHours, openingHoursMinutes);
            var closingTime = StringUtils.CreateDateFromTextBoxes(closingHoursHours, closingHoursMinutes);

            var daysOpenEnum     = EnumUtils.ParseEnum <DaysOpen>(openingDays);
            var studentPriceEnum = EnumUtils.ParseEnum <Price>(studentPrice);
            var adultPriceEnum   = EnumUtils.ParseEnum <Price>(adultPrice);
            var energyNeededEnum = EnumUtils.ParseEnum <EnergyNeeded>(energyNeeded);
            var transportEnum    = EnumUtils.ParseEnum <Transport>(transport);
            var durationEnum     = EnumUtils.ParseEnum <ActivityDuration>(duration);
            var temperatureEnum  = EnumUtils.ParseEnum <Temperature>(temperature);
            var categoryEnum     = EnumUtils.ParseEnum <Category>(category);

            var minimumParticipants = 0;

            StringUtils.GetIntFromString(minParticipants, out minimumParticipants);

            var maximumParticipants = 0;

            StringUtils.GetIntFromString(maxParticipants, out maximumParticipants);

            ActivityData newActivityData = new ActivityData(activityName, openingTime, closingTime, daysOpenEnum,
                                                            minimumParticipants, maximumParticipants, studentPriceEnum, adultPriceEnum,
                                                            address, energyNeededEnum, materialNeeded, transportEnum,
                                                            durationEnum, temperatureEnum, categoryEnum);

            return(newActivityData);
        }
Example #2
0
        public bool PassesFilter(ActivityData dataFilter)
        {
            if (dataFilter.Name != string.Empty &&
                dataFilter.Name != Data.Name)
            {
                return(false);
            }

            if (dataFilter.OpeningHour.Hour != 0 &&
                (dataFilter.OpeningHour.Hour != Data.OpeningHour.Hour || dataFilter.OpeningHour.Minute != Data.OpeningHour.Minute))
            {
                return(false);
            }

            if (dataFilter.ClosingHour.Hour != 0 &&
                (dataFilter.ClosingHour.Hour != Data.ClosingHour.Hour || dataFilter.ClosingHour.Minute != Data.ClosingHour.Minute))
            {
                return(false);
            }

            if (dataFilter.DaysOpen != DaysOpen.None && dataFilter.DaysOpen != Data.DaysOpen)
            {
                return(false);
            }

            if (dataFilter.MinimumParticipants != 0 && dataFilter.MinimumParticipants != Data.MinimumParticipants)
            {
                return(false);
            }

            if (dataFilter.MaximumParticipants != 0 && dataFilter.MaximumParticipants != Data.MaximumParticipants)
            {
                return(false);
            }

            if (dataFilter.StudentPrice != Price.None && dataFilter.StudentPrice != Data.StudentPrice)
            {
                return(false);
            }

            if (dataFilter.AdultPrice != Price.None && dataFilter.AdultPrice != Data.AdultPrice)
            {
                return(false);
            }

            // TODO : maybe support string containing instead of exact address here
            if (dataFilter.Address != string.Empty && dataFilter.Address != Data.Address)
            {
                return(false);
            }

            if (dataFilter.EnergyNeeded != EnergyNeeded.None && dataFilter.EnergyNeeded != Data.EnergyNeeded)
            {
                return(false);
            }

            // TODO : maybe support string containing instead of exact address here
            if (dataFilter.MaterialNeeded != string.Empty && dataFilter.MaterialNeeded != Data.MaterialNeeded)
            {
                return(false);
            }

            if (dataFilter.Transport != Transport.None && dataFilter.Transport != Data.Transport)
            {
                return(false);
            }

            if (dataFilter.Duration != ActivityDuration.None && dataFilter.Duration != Data.Duration)
            {
                return(false);
            }

            if (dataFilter.Temperature != Temperature.None && dataFilter.Temperature != Data.Temperature)
            {
                return(false);
            }

            if (dataFilter.Category != Category.None && dataFilter.Category != Data.Category)
            {
                return(false);
            }

            return(true);
        }
Example #3
0
        static public Activity Create(XElement activityElement)
        {
            var name          = "";
            var nameAttribute = activityElement.Attribute(ActivityStrings.Name);

            if (nameAttribute != null)
            {
                name = nameAttribute.Value;
            }

            var openingHour          = new DateTime();
            var openingHourAttribute = activityElement.Attribute(ActivityStrings.OpeningHourString);

            if (openingHourAttribute != null)
            {
                openingHour = DateTime.Parse(openingHourAttribute.Value);
            }

            var closingHour          = new DateTime();
            var closingHourAttribute = activityElement.Attribute(ActivityStrings.ClosingHourString);

            if (closingHourAttribute != null)
            {
                closingHour = DateTime.Parse(closingHourAttribute.Value);
            }

            var daysOpen          = DaysOpen.Always;
            var daysOpenAttribute = activityElement.Attribute(ActivityStrings.DaysOpenString);

            if (daysOpenAttribute != null)
            {
                daysOpen = EnumUtils.ParseEnum <DaysOpen>(daysOpenAttribute.Value);
            }

            var minParticipants          = 0;
            var minParticipantsAttribute = activityElement.Attribute(ActivityStrings.MinimumParticipantsString);

            if (minParticipantsAttribute != null)
            {
                if (!Int32.TryParse(minParticipantsAttribute.Value, out minParticipants))
                {
                    // ERROR!
                }
            }

            var maxParticipants          = 0;
            var maxParticipantsAttribute = activityElement.Attribute(ActivityStrings.MaximumParticipantsString);

            if (maxParticipantsAttribute != null)
            {
                if (!Int32.TryParse(maxParticipantsAttribute.Value, out maxParticipants))
                {
                    // ERROR!
                }
            }

            var studentPrice          = Price.Cheap;
            var studentPriceAttribute = activityElement.Attribute(ActivityStrings.StudentPriceString);

            if (studentPriceAttribute != null)
            {
                studentPrice = EnumUtils.ParseEnum <Price>(studentPriceAttribute.Value);
            }

            var adultPrice          = Price.Cheap;
            var adultPriceAttribute = activityElement.Attribute(ActivityStrings.AdultPriceString);

            if (adultPriceAttribute != null)
            {
                adultPrice = EnumUtils.ParseEnum <Price>(adultPriceAttribute.Value);
            }

            var address          = "";
            var addressAttribute = activityElement.Attribute(ActivityStrings.AddressString);

            if (addressAttribute != null)
            {
                address = addressAttribute.Value;
            }

            var energyNeeded          = EnergyNeeded.LotOfEnergy;
            var energyNeededAttribute = activityElement.Attribute(ActivityStrings.EnergyNeededString);

            if (energyNeededAttribute != null)
            {
                energyNeeded = EnumUtils.ParseEnum <EnergyNeeded>(energyNeededAttribute.Value);
            }

            var materialNeeded          = "";
            var materialNeededAttribute = activityElement.Attribute(ActivityStrings.MaterialNeededString);

            if (materialNeededAttribute != null)
            {
                materialNeeded = materialNeededAttribute.Value;
            }

            var transport          = Transport.WalkBike;
            var transportAttribute = activityElement.Attribute(ActivityStrings.TransportString);

            if (transportAttribute != null)
            {
                transport = EnumUtils.ParseEnum <Transport>(transportAttribute.Value);
            }

            var duration          = ActivityDuration.Short;
            var durationAttribute = activityElement.Attribute(ActivityStrings.DurationString);

            if (durationAttribute != null)
            {
                duration = EnumUtils.ParseEnum <ActivityDuration>(durationAttribute.Value);
            }

            var temperature          = Temperature.DoesntMatter;
            var temperatureAttribute = activityElement.Attribute(ActivityStrings.TemperatureString);

            if (temperatureAttribute != null)
            {
                temperature = EnumUtils.ParseEnum <Temperature>(temperatureAttribute.Value);
            }

            var category          = Category.Food;
            var categoryAttribute = activityElement.Attribute(ActivityStrings.CategoryString);

            if (categoryAttribute != null)
            {
                category = EnumUtils.ParseEnum <Category>(categoryAttribute.Value);
            }

            ActivityData data = new ActivityData(name, openingHour, closingHour, daysOpen, minParticipants, maxParticipants,
                                                 studentPrice, adultPrice, address, energyNeeded, materialNeeded, transport,
                                                 duration, temperature, category);

            return(new Activity(data));
        }
Example #4
0
 public Activity(ActivityData data)
 {
     Data = data;
     OpeningHourString = Data.OpeningHour.ToString("HH:mm");
     ClosingHourString = Data.ClosingHour.ToString("HH:mm");
 }