예제 #1
0
        public List<WeeklyMenuListViewModel> GenerateWeeklyMenus(int startWeek, int year, int numberOfWeeks)
        {
            if (_unitOfWork.Recipies.Count() < 5)
            {
                return null;
            }

            var weeklyMenus = new List<WeeklyMenuListViewModel>();
            for (int i = 0; i < numberOfWeeks; i++)
            {
                var publishDate = FirstDateOfWeek(year, startWeek + i);
                var weeklyMenu = new WeeklyMenu
                {
                    Created = DateTime.Now,
                    Id = Guid.NewGuid(),
                    Current = false,
                    Approved = false,
                    PublishDate = publishDate,
                    WeekNumber = GetWeekOfYear(publishDate),
                    Recipes = new List<Recipe>()
                };

                weeklyMenus.Add(new WeeklyMenuListViewModel
                {
                    WeekNumber = weeklyMenu.WeekNumber,
                    Id = weeklyMenu.Id,
                    PublishDate = weeklyMenu.PublishDate.ToString("dd-MMMM-yyyy"),
                });

                while (weeklyMenu.Recipes.Count < 5)
                {
                    var recipe = GetRandomRecipe();
                    if (weeklyMenu.Recipes.FirstOrDefault(_ => _.Id == recipe.Id) == null)
                    {
                        weeklyMenu.Recipes.Add(recipe);
                    }
                }

                _unitOfWork.WeeklyMenus.Add(weeklyMenu);
            }

            _unitOfWork.Commit();

            return weeklyMenus;
        }
예제 #2
0
 public void CreateShoppingList(WeeklyMenu weeklyMenu)
 {
     CreateShoppingList(weeklyMenu, null);
 }
예제 #3
0
        private ShoppingList GetShoppingList(Guid? userId, WeeklyMenu weeklyMenu)
        {
            if (weeklyMenu == null)
            {
                return null;
            }

               return weeklyMenu.ShoppingLists.FirstOrDefault(_ => _.UserId == userId) ??
                           weeklyMenu.ShoppingLists.First(_ => _.UserId == null);
        }
예제 #4
0
        private ShoppingList CreateShoppingList(WeeklyMenu weeklyMenu, Guid? userId)
        {
            var listOfamounts = new List<Amount>();

            var shoppingList = new ShoppingList
            {
                Id = Guid.NewGuid(),
                UserId = userId,
                WeeklyMenuId = weeklyMenu.Id,
                ShoppingListItems = new List<ShoppingListItem>(),
                Recipes = weeklyMenu.Recipes,
                WeekNumber = weeklyMenu.WeekNumber
            };

            weeklyMenu.Recipes.ForEach(_=> listOfamounts.AddRange(_.Amounts));
            var viewModel = AddToShoppingList(shoppingList, listOfamounts);

            _unitOfWork.ShoppingLists.Add(shoppingList);
            _unitOfWork.Commit();

            return viewModel;
        }
예제 #5
0
        private static WeeklyMenuViewModel GetWeeklyMenuAsViewModel(WeeklyMenu weeklyMenu, User user)
        {
            var viewModel = new WeeklyMenuViewModel
            {
                Id = weeklyMenu.Id,
                WeekNumber = weeklyMenu.WeekNumber,
                Description = weeklyMenu.Description,
                Approved = weeklyMenu.Approved,
                Recipes = new List<WeeklyMenuRecipeViewModel>()
            };

            for (var index = 0; index < weeklyMenu.Recipes.Count; index++)
            {
                var recipe = weeklyMenu.Recipes[index];
                var date = weeklyMenu.PublishDate.AddDays(index);
                var isFavorite = user.Favorites.FirstOrDefault(_ => _.Id == recipe.Id);

                viewModel.Recipes.Add(new WeeklyMenuRecipeViewModel
                {
                    Date = DateTime.Now.AddDays(index).ToString("d/MM", CultureInfo.InvariantCulture),
                    Id = recipe.Id,
                    DayName = DayName(index),
                    Name = recipe.Name,
                    ImageUrl = recipe.ImageUrl,
                    Rate = recipe.Rate,
                    Time = recipe.Time,
                    IsCurrent = date.Date == DateTime.Now.Date,
                    IsFavorite = isFavorite != null,
                    Severity = recipe.Severity,
                    Description = recipe.Description
                });
            }

            return viewModel;
        }