Esempio n. 1
0
        public IEnumerable<UserDailyMenu> GetUserDailyMenu(int userID, int day)
        {
            List<UserDailyMenu> userDailyMenuList = new List<UserDailyMenu>();
            IEnumerable<spUserDailyMenuSelectByDay_Result> userDailyMenuEFList;
            using (var context = new NutritionEntities())
            {
                userDailyMenuEFList = context.spUserDailyMenuSelectByDay(userID, day).ToList();
                foreach (spUserDailyMenuSelectByDay_Result item in userDailyMenuEFList)
                {
                    UserDailyMenu userDailyMenu = new UserDailyMenu();
                    userDailyMenu.MenuMealTimeFoodXRefID = item.MenuMealTimeFoodXRefID;
                    userDailyMenu.UserProgramXRefID = item.UserProgramXRefID;
                    userDailyMenu.MenuMealTimeOrderID = item.MenuMealTimeOrderID;
                    userDailyMenu.MealTimeTypeID = item.MealTimeTypeID;
                    userDailyMenu.MealTimeName = item.MealTimeName;
                    userDailyMenu.FoodName = item.FoodName;
                    userDailyMenu.Qty = item.Qty;
                    userDailyMenu.Calories = item.Calories;
                    userDailyMenuList.Add(userDailyMenu);

                }
            }

            return userDailyMenuList;
        }
Esempio n. 2
0
        public IEnumerable<spSelectFoodBySponsorAndMealTimeType_Result> GetFoodBySponsorAndMealTimeType(int sponsorID, int mealTimeTypeID)
        {
            List<spSelectFoodBySponsorAndMealTimeType_Result> foodList=null;

            using (var context = new NutritionEntities())
            {
                foodList = context.spSelectFoodBySponsorAndMealTimeType(sponsorID, mealTimeTypeID).ToList();
            }

            return foodList;
        }
Esempio n. 3
0
        public decimal GetUserMenuCalories(int userID, int programID)
        {
            decimal? calories;
            using (var context = new NutritionEntities())
            {
                calories = context.spUserMenuCalories(userID, programID).FirstOrDefault().Calories;                
            }
            return calories.HasValue ? calories.Value : 0;

        }
Esempio n. 4
0
        public int UserUpdateFoodMenu(int menuMealTimeFoodXRefID, Food food)
        {
            spUserProgramDayMealTimeFoodXRefUpdate_Result result=null;

            using (var context = new NutritionEntities())
            {               
                result = context.spUserProgramDayMealTimeFoodXRefUpdate(menuMealTimeFoodXRefID, food.FoodID, food.Carbohydrate, food.Protein, food.Fat, food.Calories, food.Qty).FirstOrDefault();                                
            }

            return result!=null ?result.RowCount:0;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        /// <remarks>
        /// Se llama cuando el usuario inicia su programa.   
        /// Si ya inicio almenos un programa la siguiente vez, el birthdate y sexo no deben cambiar
        /// </remarks>
        public User UpdateUserRegistration(User user)
        {            

            using (var context = new RegistrationEntities())
            {
                decimal heigh = user.HeighInt + UnitConverter.CentimetersToMeters(user.HeighDec); //estatura en metros
                                
                user.BMI = Selery.BO.Nutrition.Profile.GetBMI(heigh, user.Weight);
                
                int age = Selery.Library.Common.Helper.GetAge(user.BirthDate.Value);
                              

                //selecctionar el goaltype en base al bmi
                Selery.BO.Core.Enum.GoalType goalTypeID = Selery.BO.Nutrition.Profile.GetGoalType(user.BMI);
                                
                                
                //TODO: por ahora solo tenemos 2 goals, el 1 es de LoseWeight y el 2 es de Maintain
                //cuando haya mas Goals vamos a tener que hacer refactor a este metodo.

                int goalID = (goalTypeID == Selery.BO.Core.Enum.GoalType.LoseWeight ? (int)Selery.BO.Core.Enum.GoalType.LoseWeight : (int)Selery.BO.Core.Enum.GoalType.Maintain);

                
                //Las calorias ya vienen en el usuario
                int? rowcount = context.spUserRegistrationUpdate(user.UserID,
                     user.Gender,
                     user.HeighInt,
                     user.HeighDec,
                     user.BirthDate,
                     goalID,
                     user.BMI,
                     user.Calories).SingleOrDefault();
                

                decimal? id = context.spUserActivityInsert(user.UserID, user.ActivityID).SingleOrDefault();

            }

            using (var context = new WorkoutEntities())
            {
                //iniciar el programa
                //guardar cual es el BMI del usuario al inicio del programa
                int? rowcount = context.spUserProgramUpdate(user.UserID, user.CurrentProgram.ProgramID, user.BMI).SingleOrDefault();
            }

            //insertar el peso
            this.UserWeightInsert(user.UserID, user.Weight);
            
            //inicializar menu           
            using (var context = new  NutritionEntities())
            {  
                
                int? rowcount = context.spUserDailyMenuInitialize(user.UserID, user.CurrentProgram.ProgramID).SingleOrDefault();
            }

            return this.SelectUserByID(user.UserID);
        }