示例#1
0
        public async Task <IActionResult> AddRecipe(AddRecipeToPlanViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var recipePlan = new RecipePlans
            {
                DisplayOrder = model.DisplayOrder,
                MealName     = model.MealName,
                PlanId       = int.Parse(model.ChoosePlan),
                DayNameId    = int.Parse(model.DayName),
                RecipeId     = int.Parse(model.Recipe)
            };

            var result = await _planService.AddRecipeToPlanAsync(recipePlan);

            if (result == false)
            {
                ModelState.AddModelError("", "Błąd dodawania planu");
                return(View(model));
            }

            return(RedirectToAction("AddRecipe", "Plan"));
        }
示例#2
0
        public async Task <IActionResult> AddRecipe(AddPlanToRecipeViewModel result)
        {
            var user = await _userManager.GetUserAsync(User);

            ViewBag.userName = user.Name;

            ViewBag.Plans    = _planService.GetUserPlans(user.UserName);
            ViewBag.Recipes  = _recipeService.getUserRecipes(user.UserName);
            ViewBag.DayNames = _dayNameService.GetAll();

            if (ModelState.IsValid)
            {
                try
                {
                    var addRecipe = new RecipePlans
                    {
                        DisplayOrder = result.FoodOrder,
                        MealName     = result.FoodName,

                        Plan    = _planService.Get(result.PlanId),
                        Recipe  = _recipeService.Get(result.RecipeId),
                        DayName = _dayNameService.Get(result.DayNameId)
                    };
                    _recipePlansService.Create(addRecipe);
                    return(RedirectToAction("Index", "Dashboard"));
                }
                catch
                {
                    return(View(result));
                }
            }
            else
            {
                return(View(result));
            }
        }
示例#3
0
 public bool Update(RecipePlans recipePlans)
 {
     _context.RecipePlans.Update(recipePlans);
     return(_context.SaveChanges() > 0);
 }
示例#4
0
 public bool Create(RecipePlans recipePlans)
 {
     _context.RecipePlans.Add(recipePlans);
     return(_context.SaveChanges() > 0);
 }
示例#5
0
        public async Task <bool> AddRecipeToPlanAsync(RecipePlans recipePlans)
        {
            await _context.RecipePlans.AddAsync(recipePlans);

            return(await _context.SaveChangesAsync() > 0);
        }