Пример #1
0
        private LocationFood CreateLocationFood(int days)
        {
            LocationFood loc = new LocationFood();

            if (days > 0)
            {
                loc.FirstDay = new DayFood(false, false, false);
                loc.LastDay  = new DayFood(true, false, false);
                List <DayFood> l = new List <DayFood>();
                for (var i = 0; i < days - 1; i++)
                {
                    l.Add(new DayFood(true, false, false));
                }
                loc.MiddleDays = l;
            }
            else
            {
                loc.OnlyDay = new DayFood(false, false, false);
            }

            return(loc);
        }
Пример #2
0
        private LocationFood CreateLocationFood(int days, LocationFood template)
        {
            LocationFood loc = new LocationFood();

            if (template.OnlyDay != null && days == 0)
            {
                //No change
                loc.OnlyDay = template.OnlyDay;
            }
            else if (template.OnlyDay != null && days > 0)
            {
                loc.FirstDay = template.OnlyDay;
                loc.LastDay  = new DayFood(true, false, false);
                List <DayFood> l = new List <DayFood>();
                for (var i = 0; i < days - 2; i++)
                {
                    l.Add(new DayFood(true, false, false));
                }
                loc.MiddleDays = l;
            }
            else if (template.OnlyDay == null && days == 0)
            {
                //Take the first day ... or possibly change this?
                loc.OnlyDay = template.FirstDay;
            }
            else if (template.OnlyDay == null && days > 0)
            {
                //Take the first days if the new stuff is shorter ... or possibly change in accordance with the previous case?
                //If the new stuff is longer --> just add breakfasts
                loc.FirstDay = template.FirstDay;
                List <DayFood> l = new List <DayFood>();
                if (template.MiddleDays.Count() > days - 1)
                {
                    var i = 0;
                    for (; i < days - 2; i++)
                    {
                        l.Add(template.MiddleDays.ElementAt(i));
                    }
                    loc.LastDay = template.MiddleDays.ElementAt(i + 1);
                }
                else if (template.MiddleDays.Count() == days - 1)
                {
                    var i = 0;
                    for (; i < days - 1; i++)
                    {
                        l.Add(template.MiddleDays.ElementAt(i));
                    }
                    loc.LastDay = template.LastDay;
                }
                else
                {
                    var i = 0;
                    for (; i < template.MiddleDays.Count(); i++)
                    {
                        l.Add(template.MiddleDays.ElementAt(i));
                    }
                    for (var j = 0; j < days - 1 - i; j++)
                    {
                        l.Add(new DayFood(true, false, false));
                    }
                    loc.LastDay = template.LastDay;
                }
                loc.MiddleDays = l;
            }

            return(loc);
        }
Пример #3
0
        public void SaveFood([FromBody] SaveFoodObject saveFoodObject)
        {
            ILocationManager l = ObjectContainer.GetLocationManager();

            LocationFood loc = l.Get(saveFoodObject.LocationId).Food;

            int foodIndex = saveFoodObject.FoodIndex;
            int dayIndex  = saveFoodObject.DayIndex;

            if (dayIndex == 0 && loc.OnlyDay != null)
            {
                if (foodIndex == 0)
                {
                    loc.OnlyDay.Breakfast = !loc.OnlyDay.Breakfast;
                }
                else if (foodIndex == 1)
                {
                    loc.OnlyDay.Lunch = !loc.OnlyDay.Lunch;
                }
                else
                {
                    loc.OnlyDay.Dinner = !loc.OnlyDay.Dinner;
                }
            }
            else if (dayIndex == 0 && loc.FirstDay != null)
            {
                if (foodIndex == 0)
                {
                    loc.FirstDay.Breakfast = !loc.FirstDay.Breakfast;
                }
                else if (foodIndex == 1)
                {
                    loc.FirstDay.Lunch = !loc.FirstDay.Lunch;
                }
                else
                {
                    loc.FirstDay.Dinner = !loc.FirstDay.Dinner;
                }
            }
            else if (dayIndex == loc.MiddleDays.Count + 1)
            {
                if (foodIndex == 0)
                {
                    loc.LastDay.Breakfast = !loc.LastDay.Breakfast;
                }
                else if (foodIndex == 1)
                {
                    loc.LastDay.Lunch = !loc.LastDay.Lunch;
                }
                else
                {
                    loc.LastDay.Dinner = !loc.LastDay.Dinner;
                }
            }
            else
            {
                if (foodIndex == 0)
                {
                    loc.MiddleDays[dayIndex - 1].Breakfast = !loc.MiddleDays[dayIndex - 1].Breakfast;
                }
                else if (foodIndex == 1)
                {
                    loc.MiddleDays[dayIndex - 1].Lunch = !loc.MiddleDays[dayIndex - 1].Lunch;
                }
                else
                {
                    loc.MiddleDays[dayIndex - 1].Dinner = !loc.MiddleDays[dayIndex - 1].Dinner;
                }
            }

            Location location = l.Get(saveFoodObject.LocationId);

            location.Food = loc;
            l.Save(location);
        }