Beispiel #1
0
        public async Task <IActionResult> Get(int planId)
        {
            try
            {
                var planEntities = await _planRepository.GetAsync(planId);

                return(Ok(planEntities));
            }
            catch (Exception)
            {
                // _logger.LogCritical($"Exception {planId}.", ex);
                return(StatusCode(500, "A problem happend while handling your request."));
            }
        }
Beispiel #2
0
        public async Task <DietModel> GetDietAsyc(DietParams @params)
        {
            var validation = await new DietParamValidator().ValidateAsync(@params);

            if (validation.Failed)
            {
                throw new ArgumentException(validation.Message);
            }

            var profile = await profileRepository.GetByUserIdAsync(@params.UserId);

            var plan = await planRepository.GetAsync(@params.PlanId);

            var foods = await foodRepository.ListAsync();

            var bmrValue               = GetBMRValue((double)profile.Weight, (double)profile.Height, profile.Age, (Gender)profile.Gender);
            var levelFactor            = GetActivityLevelValue(plan.ActivityLevel);
            var totalEnergyExpenditure = bmrValue * levelFactor;
            var calorieIntakePerDay    = totalEnergyExpenditure;

            if (plan.Goal == Goal.Change_Weight)
            {
                double requiredCalorieChangePerDay = GetTargetGainOrLossCaloriePerDay((int)plan.Pace, (double)plan.Target, (double)profile.Weight, plan.Duration);
                calorieIntakePerDay = GetCalorieIntakePerDay((double)plan.Target, (double)profile.Weight, requiredCalorieChangePerDay, totalEnergyExpenditure);
            }
            var foodList = GetFoodList(calorieIntakePerDay, DietFactory.ConvertToFoodModel(foods), profile.IsVeg);

            ShowDietOutput(foodList);//Testing Purpose Only

            return(DietFactory.CreateDiet(@params.UserId, @params.Date, plan.Id, calorieBalance, message, foodList));
        }
        public async Task <IResult> UpdateAsync(PlanModel model)
        {
            var validation = await new UpdatePlanModelValidator().ValidateAsync(model);

            if (validation.Failed)
            {
                return(Result.Fail(validation.Message));
            }

            var plan = await _repository.GetAsync(model.Id);

            if (plan == default)
            {
                return(Result.Success());
            }
            if (model.Status == (int)Status.Active)
            {
                plan.Activate();
            }
            else
            {
                plan.Inactivate();
            }

            await _repository.UpdateStatusAsync(plan);

            await _unitOfWork.SaveChangesAsync();

            return(Result.Success());
        }