public async Task <GetBookListForEditOutput> GetForEdit(NullableIdDto <long> input)
        {
            var             output = new GetBookListForEditOutput();
            BookListEditDto editDto;

            var allBooks = (await _bookManager.GetAll()).MapTo <List <BookSelectListDto> >();

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

                editDto = entity.MapTo <BookListEditDto>();

                var bookIds = (await _bookListAndBookRelationshipManager.GetByBookListId(entity.Id))
                              .Select(o => o.BookId)
                              .ToList();

                foreach (var book in allBooks)
                {
                    if (bookIds.Exists(o => o == book.Id))
                    {
                        book.IsSelected = true;
                    }
                }
            }
            else
            {
                editDto = new BookListEditDto();
            }

            output.BookList = editDto;
            output.Books    = allBooks;
            return(output);
        }
Exemple #2
0
        protected virtual async Task Update(BookListEditDto input, ICollection <long> bookIds)
        {
            //TODO:更新前的逻辑判断,是否允许更新

            var entity = await _bookListRepository.GetAsync(input.Id.Value);

            //  input.MapTo(entity);
            //将input属性的值赋值到entity中
            ObjectMapper.Map(input, entity);
            await _bookListManager.UpdateAsync(entity);

            await _bookListManager.CreateBookAndBookList(entity.Id, bookIds);
        }
Exemple #3
0
        protected virtual async Task <BookListEditDto> Create(BookListEditDto input, ICollection <long> bookIds)
        {
            //TODO:新增前的逻辑判断,是否允许新增

            var entity = ObjectMapper.Map <BookList>(input);

            //调用领域服务
            entity = await _bookListManager.CreateAsync(entity);

            if (bookIds.Count > 0)
            {
                await _bookListManager.CreateBookAndBookList(entity.Id, bookIds);
            }
            var dto = ObjectMapper.Map <BookListEditDto>(entity);

            return(dto);
        }
        protected virtual async Task Update(BookListEditDto input, List <long> bookIds)
        {
            //TODO:更新前的逻辑判断,是否允许更新

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

            input.MapTo(entity);

            // ObjectMapper.Map(input, entity);
            await _entityRepository.UpdateAsync(entity);


            if (bookIds != null)
            {
                bookIds = bookIds.Where(o => o > 0).ToList();
                await _bookListAndBookRelationshipManager.CreateRelationship(entity.Id, bookIds);
            }
        }
        protected virtual async Task <BookListEditDto> Create(BookListEditDto input, List <long> bookIds)
        {
            //TODO:新增前的逻辑判断,是否允许新增

            // var entity = ObjectMapper.Map <BookList>(input);
            var entity = input.MapTo <BookList>();


            var entityId = await _entityRepository.InsertAndGetIdAsync(entity);

            if (bookIds != null)
            {
                bookIds = bookIds.Where(o => o > 0).ToList();
                await _bookListAndBookRelationshipManager.CreateRelationship(entity.Id, bookIds);
            }


            return(entity.MapTo <BookListEditDto>());
        }
Exemple #6
0
        public async Task <GetBookListForEditOutput> GetForEdit(NullableIdDto <long> input)
        {
            var             output = new GetBookListForEditOutput();
            BookListEditDto editDto;
            List <long>     allSelectedBookIds = null;
            var             allBooks           = ObjectMapper
                                                 .Map <List <BookSelectedListDto> >((await _bookRepository.GetAllListAsync()));

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

                editDto            = ObjectMapper.Map <BookListEditDto>(entity);
                allSelectedBookIds = (await _bookListManager.GetBookTagsByBookId(editDto.Id)).Select(b => b.BookId).ToList();
                if (allSelectedBookIds.Count > 0)
                {
                    foreach (var book in allBooks)
                    {
                        if (allSelectedBookIds.Any(b => b == book.Id))
                        {
                            book.IsSelected = true;
                        }
                    }
                }
            }
            else
            {
                editDto = new BookListEditDto();
            }



            output.BookList = editDto;
            output.Books    = allBooks;
            return(output);
        }