예제 #1
0
        public ActionResult AddProductToPlan(int id, int dayNumber, ProductInPlanViewModel productInPlanModel, int productId)
        {
            var user          = UserId;
            var username      = Username;
            var dailyDietPlan = _dietPlanService.GetDailyDietPlan(id, dayNumber);

            if (dailyDietPlan != null)
            {
                productInPlanModel.DietPlanNo            = _dietPlanService.GetDietPlan(id).PlanNo;
                productInPlanModel.DietPlanId            = dailyDietPlan.DietPlanId;
                productInPlanModel.DayNumber             = dailyDietPlan.DayNumber;
                productInPlanModel.Date                  = dailyDietPlan.Date.ToShortDateString();
                productInPlanModel.ProductInPlan.Product = _productInPlanService.GetProductFromList(productId);
            }
            if (!ModelState.IsValid)
            {
                return(View(productInPlanModel));
            }
            try
            {
                var product      = _productInPlanService.GetProductFromList(productId);
                var productToAdd = productInPlanModel.ProductInPlan;
                _productInPlanService.AddProductToDailyDietPlan(id, dayNumber, productToAdd, product, user, username);
                return(RedirectToAction("DailyProductList", "DietPlan",
                                        new { id = id, dayNumber = dayNumber }));
            }
            catch
            {
                return(View(productInPlanModel));
            }
        }
예제 #2
0
        // GET: DietPlanController/Edit/5
        public ActionResult EditProductInPlan(int id, int dayNumber, int ordinalNumber)
        {
            var model = new ProductInPlanViewModel()
            {
                ProductInPlan = _productInPlanService.GetProductFromDietPlan(id, dayNumber, ordinalNumber)
            };

            var dailyDietPlan = _dietPlanService.GetDailyDietPlan(id, dayNumber);

            if (dailyDietPlan != null)
            {
                model.DietPlanNo = _dietPlanService.GetDietPlan(id).PlanNo;
                model.DietPlanId = dailyDietPlan.DietPlanId;
                model.DayNumber  = dailyDietPlan.DayNumber;
                model.Date       = dailyDietPlan.Date.ToShortDateString();
            }

            return(View(model));
        }