Ejemplo n.º 1
0
        public void UpdateResourceIndex(string name, int grade, int resourceType, int resourceCategory, int resourceId, List <string> words, int creator)
        {
            var resourceIndexs = ResourceIndexRepository.GetResourceIndices(resourceId, resourceCategory);

            if (resourceIndexs != null && resourceIndexs.Count > 0)
            {
                var keywords   = resourceIndexs.Select(s => s.Yrx_Keyword);
                var enumerable = keywords as string[] ?? keywords.ToArray();

                //删除数据库中存在的部分数据
                var resourceDel = enumerable.Except(words).ToList();
                var ids         = new List <int>();
                foreach (var delWord in resourceDel)
                {
                    ids = resourceIndexs.Where(x => x.Yrx_Keyword == delWord).Select(s => s.Yrx_Id).ToList();
                }
                if (ids.Count > 0)
                {
                    ResourceIndexRepository.Delete(ids.ToArray());
                }

                //添加新的部分数据
                var resourceAdd = words.Except(enumerable).ToList();
                foreach (var addWord in resourceAdd)
                {
                    Yw_ResourceIndex resourceIndex = new Yw_ResourceIndex()
                    {
                        Yrx_Keyword          = addWord,
                        Yrx_Grade            = grade,
                        Yrx_ResourceType     = resourceType,
                        Yrx_ResourceId       = resourceId,
                        Yrx_ResourceCategory = resourceCategory,
                        Yrx_CreateTime       = DateTime.Now,
                        Yrx_Creator          = creator
                    };
                    ResourceIndexRepository.Add(resourceIndex);
                }

                ResourceIndexRepository.UpdateByIds(resourceIndexs.Select(s => s.Yrx_Id).ToList(), resourceType, grade);
            }
            else
            {
                foreach (var word in words)
                {
                    Yw_ResourceIndex resourceIndex = new Yw_ResourceIndex()
                    {
                        Yrx_Keyword          = word,
                        Yrx_Grade            = grade,
                        Yrx_ResourceType     = (int)resourceType,
                        Yrx_ResourceId       = resourceId,
                        Yrx_ResourceCategory = resourceCategory,
                        Yrx_CreateTime       = DateTime.Now,
                        Yrx_Creator          = creator
                    };
                    ResourceIndexRepository.Add(resourceIndex);
                }
            }
        }
Ejemplo n.º 2
0
        public void AddResourceIndex(string name, int grade, int resourceType, int resourceId, int category, List <string> words, int creator)
        {
            List <Yw_ResourceIndex> resourceIndices = new List <Yw_ResourceIndex>();

            foreach (var word in words)
            {
                Yw_ResourceIndex resourceIndex = new Yw_ResourceIndex()
                {
                    Yrx_Keyword          = word,
                    Yrx_Grade            = grade,
                    Yrx_ResourceType     = resourceType,
                    Yrx_ResourceId       = resourceId,
                    Yrx_ResourceCategory = category,
                    Yrx_CreateTime       = DateTime.Now,
                    Yrx_Creator          = creator
                };
                ResourceIndexRepository.Add(resourceIndex);
            }
        }