Beispiel #1
0
        public async Task UpdateByBookIdAsync(Guid id, CreateUpdateBookDto input)
        {
            var data = await _bookRepository.GetAsync(id);

            if (data == null)
            {
                throw new BookAlreadyExistsException(id.ToString());
            }
            ///新输入的书名不能同名 也不能与数据库同名
            var FindBook = await _bookRepository.FindByNameAsync(input.Name);

            if (data.Name != input.Name && FindBook == null)
            {
                await _bookManger.ChangeNameAsync(data, input.Name);

                data.AuthorId = input.AuthorId;
                //data.Name = input.Name;
                data.Price       = input.Price; data.Type = input.Type;
                data.PublishDate = input.PublishDate;
                await _bookRepository.UpdateAsync(data);
            }
            else
            {
                throw new BookAlreadyExistsException(input.Name);
            }

            //var book = await _bookRepository.FindByNameAsync(input.Name);
            //if (book==null)
            //{
            //    await _bookManger.ChangeNameAsync(data, input.Name);
            //    //throw new  BookAlreadyExistsException(input.Name);
            //}
        }
Beispiel #2
0
        public async Task <BookDto> CreateBookAsync(CreateUpdateBookDto input)
        {
            var data = await _bookManger.CreateBook(input.Name, input.Type, input.PublishDate, input.Price, input.AuthorId);

            await _bookRepository.InsertAsync(data);

            return(ObjectMapper.Map <Book, BookDto>(data));
        }