Example #1
0
 public MealPlanPage(RootPage root)
 {
     try
     {
         InitializeComponent();
         App.Configuration.InitialAsync(this);
         NavigationPage.SetHasNavigationBar(this, false);
         this._model = new MealPlanViewModel(App.CurrentApp.MainPage.Navigation)
         {
             Root = root,
             BindDataSourceAction = () =>
             {
                 AccordionMain.DataSource = this._model.AccordionSources;
                 AccordionMain.DataBind();
             },
         };
         BindingContext             = this._model;
         AccordionMain.FirstExpaned = true;
         this.Page_Load();
     }
     catch (Exception ex)
     {
         var exceptionHandler = new ExceptionHandler(TAG, ex);
     }
 }
Example #2
0
        public void TestCreateMealPlan_Success_OKResponse()
        {
            //Arrange
            BaseResult <HotelMealType> baseResult = new BaseResult <HotelMealType>();

            baseResult.Result = new HotelMealType()
            {
                Id = 1
            };
            List <MealPlanViewModel> mealPlanViewModelList = new List <MealPlanViewModel>();

            List <CuisineTypeViewModel> cuisineTypeViewModelList = new List <CuisineTypeViewModel>();
            CuisineTypeViewModel        cuisine1 = new CuisineTypeViewModel()
            {
                Id          = 1,
                Cusine      = "Indian",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };
            CuisineTypeViewModel cuisine2 = new CuisineTypeViewModel()
            {
                Id          = 2,
                Cusine      = "Asian",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };

            cuisineTypeViewModelList.Add(cuisine1);
            cuisineTypeViewModelList.Add(cuisine2);

            MealPlanViewModel mealPlanViewModel = new MealPlanViewModel()
            {
                HotelId         = 1103,
                MealId          = 1,
                IsSelected      = true,
                ObjectState     = ObjectState.Added,
                MealPlanOptions = new MealOptionViewModel()
                {
                    CurrencyId  = 1,
                    Price       = 1000,
                    ObjectState = ObjectState.Added,
                }
            };

            mealPlanViewModel.MealPlanOptions.CuisineOptions.AddRange(cuisineTypeViewModelList);
            mealPlanViewModelList.Add(mealPlanViewModel);

            mockMealPlanRepository.Setup(x => x.SaveAndUpdateHotelMealAndMealType(It.IsAny <List <MealPlanViewModel> >(), It.IsAny <string>())).Returns(Task.FromResult(new BaseResult <HotelMealType>()
            {
                Result = baseResult.Result
            })).Verifiable();

            //Act
            var result = mockMealPlanController.CreateMealPlan(mealPlanViewModelList);

            //Assert
            mockMealPlanRepository.Verify();
            Assert.IsTrue(result.Result is OkObjectResult);
            Assert.AreEqual(((OkObjectResult)result.Result).StatusCode, 200);
        }
Example #3
0
        /// <summary>
        ///  Method to map selected meals to MealPlan viewmodel
        /// </summary>
        /// <param name="mealPlanListDetail"></param>
        /// <returns></returns>
        public static BaseResult <List <MealPlanViewModel> > MapMealPlan(BaseResult <List <HotelMeal> > hotelMealList, BaseResult <List <HotelMealType> > hotelMealTypeList)
        {
            BaseResult <List <MealPlanViewModel> > mealPlanViewModelList = new BaseResult <List <MealPlanViewModel> >();
            List <MealPlanViewModel> modelList = new List <MealPlanViewModel>();

            foreach (var hotelMealItem in hotelMealList.Result)
            {
                MealPlanViewModel model = new MealPlanViewModel
                {
                    HotelId    = hotelMealItem.HotelId,
                    MealId     = hotelMealItem.MealId,
                    IsSelected = true
                };
                model.MealPlanOptions            = new MealOptionViewModel();
                model.MealPlanOptions.CurrencyId = hotelMealItem.CurrencyId;
                model.MealPlanOptions.Price      = hotelMealItem.Price;

                foreach (var hotelMealTypeItem in hotelMealTypeList.Result)
                {
                    if (hotelMealTypeItem.MealId == hotelMealItem.MealId)    //Take Cusine list of related Meal only
                    {
                        CuisineTypeViewModel cuisineTypeViewModel = new CuisineTypeViewModel
                        {
                            Id         = hotelMealTypeItem.CuisineTypeId,
                            IsSelected = true
                        };
                        model.MealPlanOptions.CuisineOptions.Add(cuisineTypeViewModel);
                    }
                }
                modelList.Add(model);
            }
            mealPlanViewModelList.Result = modelList;
            return(mealPlanViewModelList);
        }
Example #4
0
        public MealPlanViewModel GetDisplay(int mealPlanId)
        {
            MealPlanViewModel mealPlanDisplay = new MealPlanViewModel();

            MealPlan mealPlan = Get(mealPlanId);

            mealPlanDisplay.MealPlanId     = mealPlan.MealPlanId;
            mealPlanDisplay.Description    = mealPlan.Description;
            mealPlanDisplay.PhotoFilePath  = mealPlan.PhotoFilePath;
            mealPlanDisplay.PrepTime       = mealPlan.PrepTime;
            mealPlanDisplay.PrepTimeUnit   = mealPlan.PrepTimeUnit;
            mealPlanDisplay.CostPerServing = mealPlan.CostPerServing;
            mealPlanDisplay.Active         = mealPlan.Active;
            mealPlanDisplay.Created        = (System.DateTime)mealPlan.Created;

            PreparationRepository preparationRepository = new PreparationRepository();

            mealPlanDisplay.Preparations = preparationRepository.GetDisplayList(mealPlanId);

            MealPlanAssignedCategoryRepository mealPlanAssignedCategoryRepository = new MealPlanAssignedCategoryRepository();

            mealPlanDisplay.MealPlanAssignedCategories = mealPlanAssignedCategoryRepository.GetDisplayList(mealPlanId);

            MealPlanAssignedDietPlanRepository mealPlanAssignedDietPlanRepository = new MealPlanAssignedDietPlanRepository();

            mealPlanDisplay.MealPlanAssignedDietPlans = mealPlanAssignedDietPlanRepository.GetDisplayList(mealPlanId);

            NutrientViewModel nutrientViewModel = new NutrientViewModel();

            mealPlanDisplay.NutrientDropDownList = nutrientViewModel.GetDropDownList();

            MealPlanAssignedNutrientRepository mealPlanAssignedNutrientRepository = new MealPlanAssignedNutrientRepository();

            mealPlanDisplay.MealPlanAssignedNutrients = mealPlanAssignedNutrientRepository.GetDisplayList(mealPlanId);

            MealPlanAssignedIngredientRepository mealPlanAssignedIngredientRepository = new MealPlanAssignedIngredientRepository();

            mealPlanDisplay.MealPlanAssignedIngredients = mealPlanAssignedIngredientRepository.GetDisplayList(mealPlanId);

            MealPlanAssignedDishRepository mealPlanAssignedDishRepository = new MealPlanAssignedDishRepository();

            mealPlanDisplay.MealPlanAssignedDishes = mealPlanAssignedDishRepository.GetDisplayList(mealPlanId);

            UomViewModel uomViewModel = new UomViewModel();

            mealPlanDisplay.UomDropDownList = uomViewModel.GetDropDownList();

            DishViewModel dishViewModel = new DishViewModel();

            mealPlanDisplay.DishDropDownList = dishViewModel.GetDropDownList();

            IngredientViewModel ingredientViewModel = new IngredientViewModel();

            mealPlanDisplay.IngredientDropDownList = ingredientViewModel.GetDropDownList();

            return(mealPlanDisplay);
        }
Example #5
0
        public void TestCreateMealPlan_Exception_Failed_NoContentResponse()
        {
            //Arrange
            List <MealPlanViewModel> mealPlanViewModelList = new List <MealPlanViewModel>();

            List <CuisineTypeViewModel> cuisineTypeViewModelList = new List <CuisineTypeViewModel>();
            CuisineTypeViewModel        cuisine1 = new CuisineTypeViewModel()
            {
                Id          = 1,
                Cusine      = "Indian",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };
            CuisineTypeViewModel cuisine2 = new CuisineTypeViewModel()
            {
                Id          = 2,
                Cusine      = "Asian",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };

            cuisineTypeViewModelList.Add(cuisine1);
            cuisineTypeViewModelList.Add(cuisine2);

            MealPlanViewModel mealPlanViewModel = new MealPlanViewModel()
            {
                HotelId         = 1103,
                MealId          = 1,
                IsSelected      = true,
                ObjectState     = ObjectState.Added,
                MealPlanOptions = new MealOptionViewModel()
                {
                    CurrencyId  = 1,
                    Price       = 1000,
                    ObjectState = ObjectState.Added,
                }
            };

            mealPlanViewModel.MealPlanOptions.CuisineOptions.AddRange(cuisineTypeViewModelList);
            mealPlanViewModelList.Add(mealPlanViewModel);

            mockMealPlanRepository.Setup(a => a.SaveAndUpdateHotelMealAndMealType(It.IsAny <List <MealPlanViewModel> >(), It.IsAny <string>())).Returns(Task.FromResult(new BaseResult <HotelMealType> {
                Result = new HotelMealType()
            }));
            mockMealPlanRepository.Setup(a => a.SaveAndUpdateHotelMealAndMealType(It.IsAny <List <MealPlanViewModel> >(), It.IsAny <string>())).Returns(Task.FromResult(new BaseResult <HotelMealType> {
                Result = null
            })).Verifiable();

            //Act
            Task <IActionResult> actionResult = mockMealPlanController.CreateMealPlan(mealPlanViewModelList);

            //Assert
            mockMealPlanRepository.Verify();
            Assert.IsTrue(actionResult != null);
            Assert.AreEqual(((Microsoft.AspNetCore.Mvc.StatusCodeResult)actionResult.Result).StatusCode, 204);
        }
Example #6
0
        public ActionResult Create([Bind(Include = "MealPlanId,Description,PhotoFilePath,PrepTime,PrepTimeUnit,CostPerServing,Active,Created,Preparations,MealPlanAssignedCategories,MealPlanAssignedDietPlans,MealPlanAssignedNutrients,MealPlanAssignedDishes,MealPlanAssignedIngredients")] MealPlanViewModel mealPlanDisplay)
        {
            if (ModelState.IsValid)
            {
                MealPlanRepository mealPlanRepository = new MealPlanRepository();
                mealPlanRepository.Add(mealPlanDisplay);
                return(RedirectToAction("Index"));
            }

            return(View(mealPlanDisplay));
        }
Example #7
0
        public async Task TestSaveAndUpdateHotelMeal_Save_Failed_Error()
        {
            //Arrange
            List <MealPlanViewModel> mealPlanViewModelList = new List <MealPlanViewModel>();

            List <CuisineTypeViewModel> cuisineTypeViewModelList = new List <CuisineTypeViewModel>();
            CuisineTypeViewModel        cuisine1 = new CuisineTypeViewModel()
            {
                Id          = 1,
                Cusine      = "Indian",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };
            CuisineTypeViewModel cuisine2 = new CuisineTypeViewModel()
            {
                Id          = 2,
                Cusine      = "Asian",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };

            cuisineTypeViewModelList.Add(cuisine1);
            cuisineTypeViewModelList.Add(cuisine2);

            MealPlanViewModel mealPlanViewModel = new MealPlanViewModel()
            {
                HotelId         = 1103,
                MealId          = 1,
                IsSelected      = true,
                ObjectState     = ObjectState.Added,
                MealPlanOptions = new MealOptionViewModel()
                {
                    CurrencyId  = 1,
                    Price       = 1000,
                    ObjectState = ObjectState.Added,
                }
            };

            mealPlanViewModel.MealPlanOptions.CuisineOptions.AddRange(cuisineTypeViewModelList);
            mealPlanViewModelList.Add(mealPlanViewModel);
            iHotelMealConnectionLibrary.Setup(x => x.InsertEntity(It.IsAny <HotelMeal>())).Returns(Task.FromResult(new BaseResult <long>()
            {
                IsError          = true,
                ExceptionMessage = Helper.Common.GetMockException()
            })).Verifiable();

            //Act
            Task <BaseResult <HotelMealType> > actionResult = mealPlanRepository.SaveAndUpdateHotelMealAndMealType(mealPlanViewModelList, It.IsAny <string>());

            //Assert
            Assert.IsTrue(actionResult.Result.IsError);
            Assert.IsTrue(actionResult.Result.ExceptionMessage != null);
        }
Example #8
0
        public async Task <EatingPlanViewModel> GetEatingPlan(string userId)
        {
            var user = await this.db.Users.FirstOrDefaultAsync(u => u.Id == userId);

            if (user == null)
            {
                throw new ArgumentException("Моля влезте си в акаунта!");
            }

            var eatingPlan = await this.db.EatingPlan
                             .Include(e => e.MealPlans)
                             .ThenInclude(m => m.Meals)
                             .FirstOrDefaultAsync(e => e.UserId == user.Id);

            if (eatingPlan == null)
            {
                return(null);
            }

            eatingPlan.MealPlans = eatingPlan.MealPlans.OrderBy(mp => mp.Name).ToList();

            var mealPlanModel = new List <MealPlanViewModel>();

            foreach (var mealPlan in eatingPlan.MealPlans)
            {
                var mealsModel = new List <MealViewModel>();
                var plan       = new MealPlanViewModel()
                {
                    Name = mealPlan.Name,
                    Time = mealPlan.Time,
                };
                foreach (var meal in mealPlan.Meals)
                {
                    var model = new MealViewModel()
                    {
                        Name       = meal.Name,
                        GramsOrMil = meal.GramsOrMil,
                    };
                    mealsModel.Add(model);
                }

                plan.Meals = mealsModel;
                mealPlanModel.Add(plan);
            }

            return(new EatingPlanViewModel()
            {
                MealPlans = mealPlanModel,
            });
        }
Example #9
0
        // GET: MealPlan/Create
        public ActionResult Create()
        {
            MealPlanViewModel mealPlanDisplay = new MealPlanViewModel();

            mealPlanDisplay.Preparations = new List <PreparationViewModel>();
            mealPlanDisplay.Preparations.Add(new PreparationViewModel());

            MealPlanAssignedCategoryRepository mealPlanAssignedCategoryRepository = new MealPlanAssignedCategoryRepository();

            mealPlanDisplay.MealPlanAssignedCategories = mealPlanAssignedCategoryRepository.GetDisplayList(0);

            MealPlanAssignedDietPlanRepository mealPlanAssignedDietPlanRepository = new MealPlanAssignedDietPlanRepository();

            mealPlanDisplay.MealPlanAssignedDietPlans = mealPlanAssignedDietPlanRepository.GetDisplayList(0);

            NutrientViewModel nutrientViewModel = new NutrientViewModel();

            mealPlanDisplay.NutrientDropDownList = nutrientViewModel.GetDropDownList();

            MealPlanAssignedNutrientRepository mealPlanAssignedNutrientRepository = new MealPlanAssignedNutrientRepository();

            mealPlanDisplay.MealPlanAssignedNutrients = mealPlanAssignedNutrientRepository.GetDisplayList(0);
            mealPlanDisplay.MealPlanAssignedNutrients.Add(new MealPlanAssignedNutrientViewModel());

            MealPlanAssignedDishRepository mealPlanAssignedDishRepository = new MealPlanAssignedDishRepository();

            mealPlanDisplay.MealPlanAssignedDishes = mealPlanAssignedDishRepository.GetDisplayList(0);
            mealPlanDisplay.MealPlanAssignedDishes.Add(new MealPlanAssignedDishViewModel());

            MealPlanAssignedIngredientRepository mealPlanAssignedIngredientRepository = new MealPlanAssignedIngredientRepository();

            mealPlanDisplay.MealPlanAssignedIngredients = mealPlanAssignedIngredientRepository.GetDisplayList(0);
            mealPlanDisplay.MealPlanAssignedIngredients.Add(new MealPlanAssignedIngredientViewModel());

            UomViewModel uomViewModel = new UomViewModel();

            mealPlanDisplay.UomDropDownList = uomViewModel.GetDropDownList();

            DishViewModel dishViewModel = new DishViewModel();

            mealPlanDisplay.DishDropDownList = dishViewModel.GetDropDownList();

            IngredientViewModel ingredientViewModel = new IngredientViewModel();

            mealPlanDisplay.IngredientDropDownList = ingredientViewModel.GetDropDownList();

            return(View(mealPlanDisplay));
        }
Example #10
0
        // GET: MealPlan/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            MealPlanRepository mealPlanRepository = new MealPlanRepository();
            MealPlanViewModel  mealPlanDisplay    = mealPlanRepository.GetDisplay(id.Value);

            if (mealPlanDisplay == null)
            {
                return(HttpNotFound());
            }

            return(View(mealPlanDisplay));
        }
        public ViewResult Index()
        {
            var id            = userManager.GetUserId(User); // Get user id:
            var user          = personRepository.getUser(id);
            var totalCalories = personRepository.getUserDailyCalories(id);

            if (!personalised)
            {
                mealRepository.AddPersonalMeals(mealPlan, totalCalories);
                personalised = true;
            }

            var items = mealPlan.GetMealPlanItems();



            mealPlan.MealPlanItems = items;
            ClaimsPrincipal currentUser = this.User;

            var        TDEE           = personRepository.calculateUserTDEE(id);
            List <int> macros         = personRepository.calculateMacros(id);
            int        proteinPercent = (int)Math.Round((double)macros.ElementAt(0) * 4 / totalCalories * 100);
            int        fatPercent     = (int)Math.Round((double)macros.ElementAt(1) * 9 / totalCalories * 100);
            int        carbsPercent   = (int)Math.Round((double)macros.ElementAt(2) * 4 / totalCalories * 100);


            var mealPlanViewModel = new MealPlanViewModel()
            {
                MealPlan           = mealPlan,
                TDEE               = personRepository.calculateUserTDEE(id),
                TotalCalories      = mealPlan.GetMealPlanTotalCalories(),
                DailyCalorieAmount = totalCalories,
                ProteinAmount      = macros.ElementAt(0),
                FatAmount          = macros.ElementAt(1),
                CarbsAmount        = macros.ElementAt(2),
                ProteinPercent     = proteinPercent,
                CarbsPercent       = carbsPercent,
                FatPercent         = fatPercent
            };

            mealPlanViewModel.MealPlan.MealPlanItems.OrderBy(x => x.DayOfWeek);
            return(View(mealPlanViewModel));
        }
        public IActionResult CreatePlan(MealPlanViewModel mealPlanViewModel)
        {
            List <Day>    days         = new List <Day>();
            List <string> mealPlanList = mealPlanViewModel.ModelList;

            MealPlan mealPlan = new MealPlan
            {
                Name = mealPlanList[0]
            };

            for (int i = 1; i < mealPlanList.Count; i += 3)
            {
                Meal meal1 = new Meal();
                Meal meal2 = new Meal();
                Meal meal3 = new Meal();
                Day  day   = new Day
                {
                    Breakfast = new Meal(),
                    Lunch     = new Meal(),
                    Dinner    = new Meal()
                };

                //meal1.MealId = Convert.ToInt32(mealPlanList[i]);
                day.Breakfast.MealId = Convert.ToInt32(mealPlanList[i]); //meal1.MealId;

                //meal2.MealId = Convert.ToInt32(mealPlanList[i + 1]);
                day.Lunch.MealId = Convert.ToInt32(mealPlanList[i + 1]);  //meal2.MealId;

                //meal3.MealId = Convert.ToInt32(mealPlanList[i + 2]);
                day.Dinner.MealId = Convert.ToInt32(mealPlanList[i + 2]);  //meal3.MealId;

                days.Add(day);
            }

            mealPlan.Days = days;

            mealPlan.MealPlanId = mealPlanDAL.CreateMealPlan(mealPlan);
            int id = mealPlan.MealPlanId;

            //int mealPlanId = mealPlanDAL.CreateMealPlan(mealPlanViewModel.ModelMealPlan);
            return(RedirectToAction("MealPlanDetail", "Meal", new { id }));
        }
Example #13
0
        public ActionResult Create(MealPlanViewModel model)
        {
            JsonResult jsonResult = new JsonResult("");

            try
            {
                if (model == null || !ModelState.IsValid)
                {
                    jsonResult.Value = new { success = false, message = "Request error, please check input" };
                    return(jsonResult);
                }
                if (string.IsNullOrEmpty(model.Name))
                {
                    jsonResult.Value = new { success = false, message = "Request error, please check input" };
                    return(jsonResult);
                }
                if (model.Tags != null)
                {
                    model.Tags = model.Tags.Where(p => !string.IsNullOrWhiteSpace(p)).Distinct().ToArray();
                }
                if (model.MealItems != null)
                {
                    foreach (var p in model.MealItems)
                    {
                        if (p.Tags == null)
                        {
                            continue;
                        }
                        p.Name = UpcaseString(p.Name);
                        p.Tags = p.Tags.Where(t => !string.IsNullOrWhiteSpace(t)).Distinct().ToArray();
                    }
                }
                var planID = _bizMeal.CreatePlan(model.Name, model.Description, model.Tags, model.MealItems);
                jsonResult.Value = new { success = true, message = "Success", data = planID };
                return(jsonResult);
            }
            catch (Exception ex)
            {
                jsonResult.Value = new { success = false, message = ex.ToString() };
                return(jsonResult);
            }
        }
Example #14
0
 public MealPlanPage(RootPage root)
 {
     try
     {
         InitializeComponent();
         _model = new MealPlanViewModel(App.CurrentApp.MainPage.Navigation)
         {
             Root = root,
             BindDataSourceAction = () =>
             {
                 AccordionMain.DataSource = _model.AccordionSources;
                 AccordionMain.DataBind();
             },
         };
         Init();
     }
     catch (Exception exception)
     {
         var msg = exception;
     }
 }
Example #15
0
        public void Save(MealPlanViewModel mealPlanDisplay)
        {
            ApplicationDbContext db       = new ApplicationDbContext();
            MealPlan             mealPlan = new MealPlan();

            mealPlan.MealPlanId      = mealPlanDisplay.MealPlanId;
            mealPlan.Description     = mealPlanDisplay.Description;
            mealPlan.PhotoFilePath   = mealPlanDisplay.PhotoFilePath;
            mealPlan.PrepTime        = mealPlanDisplay.PrepTime;
            mealPlan.PrepTimeUnit    = mealPlanDisplay.PrepTimeUnit;
            mealPlan.CostPerServing  = mealPlanDisplay.CostPerServing;
            mealPlan.Active          = mealPlanDisplay.Active;
            mealPlan.Created         = DateTime.Now;
            db.Entry(mealPlan).State = EntityState.Modified;
            db.SaveChanges();

            PreparationRepository preparationRepository = new PreparationRepository();

            preparationRepository.ProcessList(mealPlan.MealPlanId, mealPlanDisplay.Preparations);

            MealPlanAssignedCategoryRepository mealPlanAssignedCategoryRepository = new MealPlanAssignedCategoryRepository();

            mealPlanAssignedCategoryRepository.ProcessList(mealPlan.MealPlanId, mealPlanDisplay.MealPlanAssignedCategories);

            MealPlanAssignedDietPlanRepository mealPlanAssignedDietPlanRepository = new MealPlanAssignedDietPlanRepository();

            mealPlanAssignedDietPlanRepository.ProcessList(mealPlan.MealPlanId, mealPlanDisplay.MealPlanAssignedDietPlans);

            MealPlanAssignedNutrientRepository mealPlanAssignedNutrientRepository = new MealPlanAssignedNutrientRepository();

            mealPlanAssignedNutrientRepository.ProcessList(mealPlan.MealPlanId, mealPlanDisplay.MealPlanAssignedNutrients);

            MealPlanAssignedIngredientRepository mealPlanAssignedIngredientRepository = new MealPlanAssignedIngredientRepository();

            mealPlanAssignedIngredientRepository.ProcessList(mealPlan.MealPlanId, mealPlanDisplay.MealPlanAssignedIngredients);

            MealPlanAssignedDishRepository mealPlanAssignedDishRepository = new MealPlanAssignedDishRepository();

            mealPlanAssignedDishRepository.ProcessList(mealPlan.MealPlanId, mealPlanDisplay.MealPlanAssignedDishes);
        }
Example #16
0
        public ActionResult Info(long id)
        {
            var plan = _bizMeal.GetPlan(id);

            if (plan == null)
            {
                return(View());
            }
            var mealItems = _bizMeal.GetMealItems(plan.ID);
            MealPlanViewModel viewModel = new MealPlanViewModel()
            {
                Name        = plan.Name,
                Description = plan.Description,
                ID          = plan.ID,
                Tags        = plan.Tags,
                Createtime  = plan.Createtime,
                UpdateTime  = plan.UpdateTime,
                MealItems   = mealItems
            };

            return(View(viewModel));
        }
        public IActionResult CreatePlan(int id = 0)
        {
            MealPlanViewModel mealPlanViewModel = new MealPlanViewModel();
            MealPlan          mealPlan          = new MealPlan();
            List <Day>        days = new List <Day>();

            if (id == 0)
            {
                mealPlan.Days = days;
            }
            else
            {
                mealPlan = mealPlanDAL.GetMealPlanById(id);
            }


            mealPlanViewModel.ModelMealPlan = mealPlan;

            ViewBag.ExistingMeals   = mealPlanDAL.GetAllMeals();
            ViewBag.ExistingRecipes = recipeDAL.GetAllRecipes();

            return(View("CreatePlan", mealPlanViewModel));
        }
Example #18
0
        public async Task TestSaveAndUpdateHotelMeal_Update_ByHotelMealPredicate_Failed_Error()
        {
            //Arrange
            BaseResult <HotelMealType> baseResult = new BaseResult <HotelMealType>();

            baseResult.Result = new HotelMealType()
            {
            };
            List <MealPlanViewModel> mealPlanViewModelList = new List <MealPlanViewModel>();

            List <CuisineTypeViewModel> cuisineTypeViewModelList = new List <CuisineTypeViewModel>();
            CuisineTypeViewModel        cuisine1 = new CuisineTypeViewModel()
            {
                Id          = 1,
                Cusine      = "Indian",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };
            CuisineTypeViewModel cuisine2 = new CuisineTypeViewModel()
            {
                Id          = 2,
                Cusine      = "Asian",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };

            cuisineTypeViewModelList.Add(cuisine1);
            cuisineTypeViewModelList.Add(cuisine2);

            MealPlanViewModel mealPlanViewModel = new MealPlanViewModel()
            {
                HotelId         = 1103,
                MealId          = 1,
                IsSelected      = true,
                ObjectState     = ObjectState.Modified,
                MealPlanOptions = new MealOptionViewModel()
                {
                    CurrencyId  = 1,
                    Price       = 1000,
                    ObjectState = ObjectState.Modified,
                }
            };

            mealPlanViewModel.MealPlanOptions.CuisineOptions.AddRange(cuisineTypeViewModelList);
            mealPlanViewModelList.Add(mealPlanViewModel);

            var hotelMeal = new HotelMeal()
            {
            };
            var hotelMealbaseResult = new BaseResult <List <HotelMeal> >()
            {
                Result = new List <HotelMeal>()
                {
                    hotelMeal
                }
            };
            var pred = new Func <HotelMeal, bool>(x => x.HotelId == hotelMeal.HotelId && !x.IsDeleted);

            iHotelMealConnectionLibrary.Setup(x => x.GetListByPredicate(It.Is <Func <HotelMeal, bool> >(y => y.GetType() == pred.GetType()))).Returns(Task.FromResult(hotelMealbaseResult));

            //Act
            Task <BaseResult <HotelMealType> > actionResult = mealPlanRepository.SaveAndUpdateHotelMealAndMealType(mealPlanViewModelList, It.IsAny <string>());

            //Assert
            Assert.IsTrue(actionResult.Result.IsError);
            Assert.IsTrue(actionResult.Result.ExceptionMessage != null);
        }
Example #19
0
        /// <summary>
        ///  Return the mapped HotelMeal and HotelMealType model
        /// </summary>
        /// <param name="hotelAssociateMealPlanViewModel"></param>
        /// <returns></returns>
        public static void MapHotelMealAndHotelMealType(ref HotelMeal hotelMeal, ref List <HotelMealType> hotelMealTypeList, MealPlanViewModel mealPlanViewModel, string userName)
        {
            hotelMeal            = new HotelMeal();
            hotelMeal.HotelId    = mealPlanViewModel.HotelId;
            hotelMeal.MealId     = mealPlanViewModel.MealId;
            hotelMeal.Code       = "Meal_" + hotelMeal.HotelId + "_" + hotelMeal.MealId;
            hotelMeal.Price      = mealPlanViewModel.MealPlanOptions.Price;
            hotelMeal.CurrencyId = (mealPlanViewModel.MealPlanOptions.CurrencyId == null)? 0: mealPlanViewModel.MealPlanOptions.CurrencyId.Value;
            hotelMeal.CreatedBy  = userName;
            hotelMeal.UpdatedBy  = userName;
            if (mealPlanViewModel.IsSelected)
            {
                hotelMeal.IsDeleted = false;
            }
            else
            {
                hotelMeal.IsDeleted = true;
            }
            hotelMealTypeList = new List <HotelMealType>();
            foreach (var cuisine in mealPlanViewModel.MealPlanOptions.CuisineOptions)
            {
                HotelMealType model = new HotelMealType();
                model.HotelId       = mealPlanViewModel.HotelId;
                model.MealId        = mealPlanViewModel.MealId;
                model.CuisineTypeId = cuisine.Id;
                model.Code          = "MealType_" + hotelMeal.HotelId + "_" + hotelMeal.MealId + "_" + model.CuisineTypeId;
                model.Name          = cuisine.Cusine;
                model.NameItemId    = 1;
                model.CreatedBy     = userName;
                model.UpdatedBy     = userName;
                model.IsActive      = true;

                if (cuisine.IsSelected)
                {
                    model.IsDeleted = false;
                }
                else
                {
                    model.IsDeleted = true;
                }
                hotelMealTypeList.Add(model);
            }
        }