Example #1
0
        public async Task <bool> EditAsync(BookDto bookDto, CancellationToken cancellationToken)
        {
            var exists = await BookExists(bookDto, cancellationToken);

            if (exists == true)
            {
                return(false);
            }
            var bookList = bookDto.ToEntity();
            await _bookList.UpdateAsync(bookList, cancellationToken);

            return(true);
        }
Example #2
0
        public async Task <bool> EditAsync(BookDto bookDto, CancellationToken cancellationToken)
        {
            //TODO : قابلیت ویرایش شابک را حذف کن
            bool exists = await _Book.Table.Where(c => c.Id == bookDto.Id).AnyAsync(cancellationToken);

            if (exists != true)
            {
                return(false);
            }

            Book Book = bookDto.ToEntity();
            await _Book.UpdateAsync(Book, cancellationToken);

            return(true);
        }
Example #3
0
        public async Task <BookSelectDto> AddBookAsync(BookDto bookDto, CancellationToken cancellationToken)
        {
            var bookList = bookDto.ToEntity();
            await _bookList.AddAsync(bookList, cancellationToken, saveNow : false);

            foreach (var item in bookDto.BooksISBN)
            {
                var book = new Book()
                {
                    BookListId = bookList.Id,
                    ISBN       = item
                };
                await _repository.AddAsync(book, cancellationToken);
            }


            var resultDto = await _repository.TableNoTracking.ProjectTo <BookSelectDto>().SingleOrDefaultAsync(p => p.Id.Equals(bookList.Id), cancellationToken);

            return(resultDto);
        }
Example #4
0
        /// <summary>
        /// افزودن کتاب
        /// </summary>
        /// <param name="bookDto"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <BookSelectDto> AddBookAsync(BookDto bookDto, CancellationToken cancellationToken)
        {
            Book Book    = bookDto.ToEntity();
            int  fieldId = 0;

            if (bookDto.FieldId == FieldStatus.N)
            {
                fieldId = 1;
            }

            if (bookDto.FieldId == FieldStatus.C)
            {
                fieldId = 2;
            }

            if (bookDto.FieldId == FieldStatus.PC)
            {
                fieldId = 3;
            }

            if (bookDto.FieldId == FieldStatus.S)
            {
                fieldId = 4;
            }

            if (bookDto.FieldId == FieldStatus.M)
            {
                fieldId = 5;
            }

            if (bookDto.FieldId == FieldStatus.O)
            {
                fieldId = 6;
            }

            await _Book.AddAsync(Book, cancellationToken);

            if (bookDto.FieldId != FieldStatus.N)
            {
                var field = await _filedRepository.TableNoTracking.Where(c => c.Id == fieldId).SingleOrDefaultAsync(cancellationToken);

                if (field == null)
                {
                    throw new BadRequestException("رشته مورد نظر یافت نشد");
                }
                Book.FieldId = fieldId;
                await _Book.UpdateAsync(Book, cancellationToken);
            }
            else
            {
                await _Book.UpdateAsync(Book, cancellationToken);
            }

            List <Isbn> isbns = new List <Isbn>();

            foreach (string item in bookDto.BooksISBN)
            {
                isbns.Add(new Isbn {
                    BookId = Book.Id, Value = item
                });
            }

            await _isbnRepository.AddRangeAsync(isbns, cancellationToken);

            BookSelectDto resultDto = await _repository.TableNoTracking.Include(c => c.ISBNs).ProjectTo <BookSelectDto>().SingleOrDefaultAsync(p => p.Id.Equals(Book.Id), cancellationToken);

            return(resultDto);
        }