コード例 #1
0
        public Task <UpdateObjectCategoryResponse> UpdateCategoryAsync(UpdateObjectCategory dto)
        {
            return(Task.Run(() =>
            {
                switch (dto.type)
                {
                case Contact.Enum.UpdateCategoryTypeEnum.Works:
                    var worksEntity = _worksRepository.TableNoTracking.Where(t => t.Id.Equals(dto.object_id)).SingleOrDefault();
                    if (worksEntity == null)
                    {
                        throw new RequestErrorException("该作品不存在!");
                    }
                    break;

                case Contact.Enum.UpdateCategoryTypeEnum.Product:
                    var productEntity = _pruoductRepository.TableNoTracking.Where(t => t.Id.Equals(dto.object_id)).SingleOrDefault();
                    if (productEntity == null)
                    {
                        throw new RequestErrorException("该产品不存在!");
                    }

                    break;

                case Contact.Enum.UpdateCategoryTypeEnum.News:
                    var newsEntity = _newsRepository.TableNoTracking.Where(t => t.Id.Equals(dto.object_id)).SingleOrDefault();
                    if (newsEntity == null)
                    {
                        throw new RequestErrorException("该新闻不存在!");
                    }

                    break;

                default:
                    throw new RequestErrorException("更新的资源类型不匹配");
                    break;
                }

                var id = dto.object_id.ToString("D");
                var deleteCount = _dapperRepository.Execute(DELETE_CATEGORY_RELATIONSHIPS, new { objectId = id });
                var idList = dto.categorie_ids.Split(',');
                List <CategoryRelationshipsEntity> relaList = new List <CategoryRelationshipsEntity>();
                for (int i = 0; i < idList.Length; i++)
                {
                    relaList.Add(new CategoryRelationshipsEntity()
                    {
                        CategoryId = Convert.ToInt32(idList[i]),
                        CreatedDate = DateTime.Now,
                        ObjectId = dto.object_id
                    });
                }
                _categoryRelationshipsRepository.Insert(relaList);
                return new UpdateObjectCategoryResponse();
            }));
        }
コード例 #2
0
        public async Task <IHttpActionResult> Post([FromBody] UpdateObjectCategory dto)
        {
            var resp = await _categoryService.UpdateCategoryAsync(dto);

            return(Ok(resp));
        }