예제 #1
0
        internal override void Remove(BaseItemWin item)
        {
            if (item is HomeworkWin)
            {
                Homework.Remove(item as HomeworkWin);
            }

            else if (item is ExamWin)
            {
                Exams.Remove(item as ExamWin);
            }

            else if (item is ScheduleWin)
            {
                Schedules.Remove(item as ScheduleWin);
            }

            else if (item is WeightCategoryWin)
            {
                WeightCategories.Remove(item as WeightCategoryWin);
            }

            else
            {
                throw new NotImplementedException("Item to be removed from Class wasn't any of the supported types.");
            }
        }
예제 #2
0
        private void UpdateWeightCategories()
        {
            if (Class == null || Class.IsNoClassClass)
            {
                return;
            }

            WeightCategories = GetWeightCategories(Class);

            if (SelectedWeightCategory == null || !WeightCategories.Contains(SelectedWeightCategory))
            {
                ViewItemWeightCategory selectedWeightCategory = null;
                if (EditParams != null)
                {
                    selectedWeightCategory = WeightCategories.FirstOrDefault(i => i.Identifier == EditParams.Item.WeightCategoryIdentifier);
                }
                else
                {
                    selectedWeightCategory = WeightCategories.FirstOrDefault(i => i.Identifier == NavigationManager.SelectedWeightCategoryIdentifier);
                }

                if (selectedWeightCategory == null)
                {
                    SelectedWeightCategory = ViewItemWeightCategory.UNASSIGNED;
                }
                else
                {
                    SelectedWeightCategory = selectedWeightCategory;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// This method will display the BMI weight status
        /// </summary>
        public string DisplayWeightStatus()
        {
            StringBuilder message = new StringBuilder("\n\t");
            if (BmiIndex < Underweight)
            {
                category = WeightCategories.Underweight;

            }
            else if ((BmiIndex > Underweight) && (User_BMI <= Normal))
            {
                category = WeightCategories.Normal;
            }
            else if ((BmiIndex > Normal) && (User_BMI <= Overweight))
            {
                category = WeightCategories.Overweight;
            }
            else if ((BmiIndex > Overweight) && (User_BMI <= OBESE_CLASS1))
            {
                category = WeightCategories.ObeseI;
            }
            else if ((BmiIndex > OBESE_CLASS1) && (User_BMI <= OBESE_CLASS2))
            {
                category = WeightCategories.ObeseII;
            }
            else if ((BmiIndex > OBESE_CLASS2) && (User_BMI <= OBESE_CLASS3))
            {
                category = WeightCategories.ObeseIII;
            }

            message.Append($"Your BMI is {BmiIndex:0.0}. " +
               $"You are {category}. ");
            return message.ToString();
        }       
예제 #4
0
        private void HandleWeightCategoryForHomeworkExam(BaseViewItemHomeworkExam item)
        {
            if (item.WeightCategoryIdentifier == PowerPlannerSending.BaseHomeworkExam.WEIGHT_CATEGORY_UNASSIGNED)
            {
                item.WeightCategory = ViewItemWeightCategory.UNASSIGNED;
            }
            else if (item.WeightCategoryIdentifier == PowerPlannerSending.BaseHomeworkExam.WEIGHT_CATEGORY_EXCLUDED)
            {
                item.WeightCategory = ViewItemWeightCategory.EXCLUDED;
            }
            else
            {
                if (WeightCategories == null)
                {
                    // WeightCategories should only be null in the scenario where the view group was loaded disregarding
                    // the weight categories (like from the live tile task)
                    item.WeightCategory = null;
                    return;
                }

                var weight = WeightCategories.FirstOrDefault(i => i.Identifier == item.WeightCategoryIdentifier);
                if (weight != null)
                {
                    item.WeightCategory = weight;
                }
                else
                {
                    item.WeightCategory = ViewItemWeightCategory.UNASSIGNED;
                }
            }
        }
        /// <summary>
        /// Determines the weight status of the user based on their BMI and the W.H.O's
        /// weight status guidelines.
        /// </summary>
        /// <returns>A string with the user's current weight status.</returns>
        public string DisplayWeightStatus()
        {
            StringBuilder message = new StringBuilder("\n\t");

            if (User_BMI < UNDERWEIGHT_MAX)
            {
                category = WeightCategories.Underweight;
            }
            else if ((User_BMI > UNDERWEIGHT_MAX) && (User_BMI <= NORMAL_MAX))
            {
                category = WeightCategories.Normal;
            }
            else if ((User_BMI > NORMAL_MAX) && (User_BMI <= OVERWEIGHT_MAX))
            {
                category = WeightCategories.Overweight;
            }
            else if ((User_BMI > OVERWEIGHT_MAX) && (User_BMI <= OBESE_I_MAX))
            {
                category = WeightCategories.ObeseI;
            }
            else if ((User_BMI > OBESE_I_MAX) && (User_BMI <= OBESE_III_MIN))
            {
                category = WeightCategories.ObeseII;
            }
            else if (User_BMI >= OBESE_III_MIN)
            {
                category = WeightCategories.ObeseIII;
            }

            message.Append($"Your BMI is {User_BMI:0.0}. " +
                           $"You are {category}.");
            return(message.ToString());
        }
예제 #6
0
        public async Task <ActionResult> Add(WeightCategories newWeightCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid request"));
            }
            if (newWeightCategory.MinWeight >= newWeightCategory.MaxWeight)
            {
                return(BadRequest("Minimum weight cannot be bigger than or equal to Maximum weight."));
            }
            var allCategories  = _db.WeightCategories.ToList();
            var weightCategory = new WeightCategories();

            if (allCategories.Count == 0)
            {
                weightCategory = new WeightCategories()
                {
                    Name      = newWeightCategory.Name,
                    MinWeight = newWeightCategory.MinWeight,
                    MaxWeight = newWeightCategory.MaxWeight,
                    IconId    = newWeightCategory.IconId
                };
                _db.WeightCategories.Add(weightCategory);
            }
            else
            {
                var greatestValue = allCategories.Max(a => a.MaxWeight);
                var lowestValue   = allCategories.Min(a => a.MinWeight);

                bool firstRow = newWeightCategory.MinWeight < lowestValue ? true : false;

                if (firstRow == true && newWeightCategory.MaxWeight != lowestValue)
                {
                    return(BadRequest("Overlaps and gaps between categories are not allowed."));
                }
                else
                {
                    if (firstRow == false && newWeightCategory.MinWeight != greatestValue)
                    {
                        return(BadRequest("Overlaps and gaps between categories are not allowed."));
                    }
                }

                weightCategory = new WeightCategories()
                {
                    Name      = newWeightCategory.Name,
                    MinWeight = newWeightCategory.MinWeight,
                    MaxWeight = newWeightCategory.MaxWeight,
                    IconId    = newWeightCategory.IconId
                };
                _db.WeightCategories.Add(weightCategory);
            }

            await _db.SaveChangesAsync();

            return(Ok((WeightCategoryModel)weightCategory));
        }
예제 #7
0
        public async Task <ActionResult> Update(WeightCategories updatedWeight)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid request"));
            }
            if (updatedWeight.MinWeight >= updatedWeight.MaxWeight)
            {
                return(BadRequest("Minimum weight cannot be greater than or equal to maximum weight."));
            }

            var allCategories = _db.WeightCategories.ToList();

            if (allCategories.Count == 0)
            {
                return(BadRequest("No weight categories were found"));
            }

            var oldWeightCategory = allCategories.FirstOrDefault(o => o.Id == updatedWeight.Id);
            var otherCategories   = allCategories.Where(o => o.Id != updatedWeight.Id).ToList();



            List <WeightCategories> combinedList = new List <WeightCategories>();

            combinedList.AddRange(otherCategories);
            combinedList.Add(updatedWeight);
            var checkList = combinedList.OrderBy(x => x.MinWeight).ToList();

            if (oldWeightCategory.MinWeight != updatedWeight.MinWeight || oldWeightCategory.MaxWeight != updatedWeight.MaxWeight)
            {
                for (var index = 0; index < checkList.Count; index++)
                {
                    if (checkList.Count - 1 != index && checkList[index].MaxWeight != checkList[index + 1].MinWeight)
                    {
                        return(BadRequest("No gaps are allowed between different categories."));
                    }
                }
            }

            oldWeightCategory.Name      = updatedWeight.Name;
            oldWeightCategory.IconId    = updatedWeight.IconId;
            oldWeightCategory.MinWeight = updatedWeight.MinWeight;
            oldWeightCategory.MaxWeight = updatedWeight.MaxWeight;

            _db.WeightCategories.Update(oldWeightCategory);

            await UpdateVehicles();

            await _db.SaveChangesAsync();

            return(Ok());
        }