コード例 #1
0
        public async Task <GetBookForEditOutput> GetForEdit(NullableIdDto <long> input)
        {
            var         output = new GetBookForEditOutput();
            BookEditDto editDto;
            // 已选中的标签Id
            List <long> bookTagIds = null;
            // 所有标签
            var allbookTag = (await _bookTagManager.GetAll()).MapTo <List <BookTagSelectListDto> >();

            if (input.Id.HasValue)
            {
                var entity = await _entityRepository.GetAsync(input.Id.Value);

                editDto = entity.MapTo <BookEditDto>();


                bookTagIds = (await _bookAndBookTagRelationshipManager.GetByBookId(input.Id.Value))
                             .Select(o => o.BookTagId)
                             .ToList();


                foreach (var bookTag in allbookTag)
                {
                    if (bookTagIds.Exists(o => o == bookTag.Id))
                    {
                        bookTag.IsSelected = true;
                    }
                }
            }
            else
            {
                editDto = new BookEditDto();
            }

            output.Book     = editDto;
            output.BookTags = allbookTag;

            return(output);
        }
コード例 #2
0
        public async Task <GetBookForEditOutput> GetForEdit(NullableIdDto <long> input)
        {
            var         output = new GetBookForEditOutput();
            BookEditDto editDto;


            List <long> tagIds = null;
            //获取所有标签
            //哪些是选择了的,哪些是没有选择的
            var booktagListDtos = (await _bookTagManager.GetAll()).MapTo <List <BookTagSelectListDto> >();

            if (input.Id.HasValue)
            {
                var entity = await _entityRepository.GetAsync(input.Id.Value);

                editDto = entity.MapTo <BookEditDto>();

                //bookEditDto = ObjectMapper.Map<List<bookEditDto>>(entity);


                tagIds = (await _entityManager.GetTagsByBookId(entity.Id)).Select(a => a.BookTagId).ToList();
                foreach (var bookTag in booktagListDtos)
                {
                    if (tagIds.Exists(a => a == bookTag.Id))
                    {
                        bookTag.IsSelected = true;
                    }
                }
            }
            else
            {
                editDto = new BookEditDto();
            }

            output.Book     = editDto;
            output.BookTags = booktagListDtos;
            return(output);
        }