Ejemplo n.º 1
0
        public static List <WeekItem> ListWeekByYear(int year)
        {
            var startDate      = new DateTime(year, 1, 1);
            var endDate        = startDate.AddYears(1);
            var currentCulture = CultureInfo.CurrentCulture;
            var dfi            = DateTimeFormatInfo.CurrentInfo;
            var result         = new List <WeekItem>();
            var start          = startDate.AddDays(-startDate.FdiDayOfWeek());

            for (var tm = startDate; tm <= endDate; tm = tm.AddDays(7))
            {
                if (dfi != null)
                {
                    var id  = currentCulture.Calendar.GetWeekOfYear(tm, dfi.CalendarWeekRule, dfi.FirstDayOfWeek);
                    var w   = start.AddDays(7 * (id - 1));
                    var mon = Enumerable.Range(1, 7).Select(num => w.AddDays(num)).ToArray();
                    var obj = new WeekItem
                    {
                        ID           = id,
                        MonToSun     = mon,
                        MonToSunView = mon[0].ToString("dd/MM") + "-" + mon[6].ToString("dd/MM/yyyy")
                    };
                    result.Add(obj);
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public ActionResult AddRecipe(int weekPlanId, int recipeId)
        {
            WeekItem item = new WeekItem
            {
                RecipeId = recipeId,
                WeekId   = weekPlanId,
                WeekDay  = String.Empty
            };

            RecipeRepository repo = new RecipeRepository(ConnectionString);

            repo.InsertWeekItem(item);
            return(Content("200"));
        }
Ejemplo n.º 3
0
        private Dictionary <int, WeekItem> ExtractWeeksFromContent()
        {
            var weekselections = document.DocumentNode.Descendants()
                                 .Where(x => (x.IsSelect() && x.IdEquals("week_selectie")))
                                 .ToList();

            if (weekselections.Count != 1)
            {
                var s = String.Format("Nr of weekselections is {0} but should be equal to 1.", weekselections.Count());
                Logger.Error(s);
                throw new ApplicationException(s);
            }
            var weekselection = weekselections.First();

            // select options
            var options = weekselection.ChildNodes.Where(x => x.IsOption()).ToList();

            var weeks = new Dictionary <int, WeekItem>();

            if (options.Any())
            {
                foreach (var option in options)
                {
                    if (option.Attributes == null || option.Attributes["value"] == null)
                    {
                        throw new Exception();
                    }

                    int nr;
                    if (!Int32.TryParse(option.Attributes["value"].Value, out nr))
                    {
                        throw new Exception();
                    }

                    if (option.NextSibling == null)
                    {
                        throw new Exception();
                    }

                    //Week 09 - 2015
                    var weekText = option.NextSibling.InnerText.Trim();
                    weekText = weekText.Replace("Week", "").Trim();
                    var split = weekText.Split('-');
                    if (split.Count() == 2)
                    {
                        string sWeek = split[0].Trim(); // 09
                        string sYear = split[1].Trim(); // 2015
                        int    weekNr, year;

                        if (Int32.TryParse(sWeek, out weekNr) && Int32.TryParse(sYear, out year))
                        {
                            var w = new WeekItem(weekNr, year);
                            weeks.Add(nr, w);
                        }
                        else
                        {
                            throw new Exception();
                        }
                    }
                }
            }
            return(weeks);
        }