//componentValue为营养成分数值,所以需要反过来计算食品应该是多少克
        private List <Food> GetRecommendFood(string nameCode, string classify, float componentValue, int dataCount, int click, List <Guid> dislikeFoodOidList)
        {
            //依据食材分类,重要程度,获取指定食材
            List <Food> foodList = _mapper.Map <List <Food> >(_foodRepository.GetFoodByClassify(classify, click));

            //去除客户讨厌的食物
            List <Food> likeFoodList = foodList;

            foreach (var foodOid in dislikeFoodOidList)
            {
                var temp = likeFoodList.Where(c => c.OID != foodOid);
                likeFoodList = new List <Food>();
                likeFoodList = temp.ToList();
            }

            //获取指定数目食材
            List <Food> recommendFoodList = likeFoodList.OrderBy(c => Guid.NewGuid()).Take(dataCount).ToList();

            //增加营养元素的数据
            foreach (var recommendFood in recommendFoodList)
            {
                //获取Food所对应的Component列表
                var recommendFoodComponentList = _foodComponentRepository.GetFoodComponentByFoodOid(recommendFood.OID);
                //获取Food重量
                foreach (var recommendFoodComponent in recommendFoodComponentList)
                {
                    var component = _componentRepository.GetById(recommendFoodComponent.ComponentOid);
                    if (component.NameCode == nameCode)
                    {
                        if (string.IsNullOrEmpty(recommendFoodComponent.Value.ToString()) || string.IsNullOrWhiteSpace(recommendFoodComponent.Value.ToString()))
                        {
                            recommendFood.Value = -1f;
                        }
                        else
                        {
                            recommendFood.Value = componentValue * 100f / recommendFoodComponent.Value;
                        }
                        recommendFood.Unit = "g";
                        break;
                    }
                }
                //增加营养元素的数据
                List <FoodComponent> foodComponentList = new List <FoodComponent>();
                foreach (var recommendFoodComponent in recommendFoodComponentList)
                {
                    var recommendComponent = _mapper.Map <FoodComponent>(_componentRepository.GetById(recommendFoodComponent.ComponentOid));
                    recommendComponent.Value = (recommendFoodComponent.Value * recommendFood.Value) / 100f;
                    foodComponentList.Add(recommendComponent);
                }
                recommendFood.FoodComponentList = foodComponentList;
            }

            return(recommendFoodList.OrderByDescending(c => c.Value).ToList());
        }
Example #2
0
        public Course AddComponent(int courseId, int componentId)
        {
            var course    = _courseRepository.GetById(courseId);
            var component = _componentRepository.GetById(courseId);

            if (course == null || component == null)
            {
                return(null);
            }
            course.Components.Add(component);
            return(_courseRepository.Update(course));
        }
Example #3
0
        public Component UpdateComponent(string name, int componentId, float minPointsToPass, float maxPoints)
        {
            var component = _componentRepository.GetById(componentId);

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

            component.Name = name;
            component.MinimumPointsToPass = minPointsToPass;
            component.MaximumPoints       = maxPoints;

            return(_componentRepository.Update(component));
        }
Example #4
0
        public QueryFoodListByPageResponse QueryFoodListByPage(string foodName, float foodValue, int pageIndex, int pageSize)
        {
            QueryFoodListByPageResponse result;

            try
            {
                //依据条件查询食材列表
                var existingFoodList = _foodRepository.QueryFoodListByPage(foodName, pageIndex, pageSize);

                //查询食材列表的总条数
                var existingFoodListCount = _foodRepository.QueryFoodListCount(foodName);

                //映射为返回类型
                result               = new QueryFoodListByPageResponse();
                result.FoodList      = new PageModel <FoodByPage>();
                result.FoodList.Data = _mapper.Map <List <FoodByPage> >(existingFoodList);

                //组合页码数据
                result.FoodList.PageIndex = pageIndex + 1;                                                          //页码索引
                result.FoodList.PageSize  = pageSize;                                                               //每页大小
                result.FoodList.DataCount = existingFoodListCount;                                                  //数据总数
                result.FoodList.PageCount = Convert.ToInt32(Math.Ceiling(existingFoodListCount * 1.0d / pageSize)); //总页数

                //增加能量,3大营养素数据
                int i = 0;
                foreach (var existingFood in result.FoodList.Data)
                {
                    result.FoodList.Data[i].Value = foodValue;
                    result.FoodList.Data[i].Unit  = "g";

                    //获取Food所对应的Component列表
                    var existingFoodComponentList = _foodComponentRepository.GetFoodComponentByFoodOid(existingFood.OID);
                    //增加营养元素的数据
                    List <FoodComponent> foodComponentList = new List <FoodComponent>();
                    foreach (var existingFoodComponent in existingFoodComponentList)
                    {
                        var existingComponent = _mapper.Map <FoodComponent>(_componentRepository.GetById(existingFoodComponent.ComponentOid));
                        existingComponent.Value = (existingFoodComponent.Value * foodValue) / 100f;
                        foodComponentList.Add(existingComponent);
                    }
                    existingFood.FoodComponentList = foodComponentList;
                    existingFood.ID = (pageIndex * pageSize) + i + 1;
                    i++;
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(result);
        }
 public async Task <Component> GetById(Guid id)
 {
     return(await _componentRepository.GetById(id));
 }
Example #6
0
 public Component GetComponentById(int id)
 {
     return(_componentRepository.GetById(x => x.Id == id));
 }