Ejemplo n.º 1
0
        public async Task <BookListModel> AddBookToList(string bookId, int bookListId)
        {
            BookListModel bookList = await GetRaw(bookListId, true);

            if (bookList == null)
            {
                return(null);
            }

            BookModel book = await _book.Add(await _book.Get(bookId));

            if (book == null)
            {
                return(null);
            }

            if (bookList.Books.Select(b => b.Id).Contains(book.Id))
            {
                return(bookList);
            }


            BookListModel currentBookList = await _book.UserBookList(book.Id);

            if (currentBookList != null)
            {
                List <Book_BookListModel> book_bookList_list = currentBookList.Book_BookLists.Where(b => b.Book.Id == book.Id).ToList();
                _context.Remove(book_bookList_list.First());
            }

            bookList.Book_BookLists.Add(new Book_BookListModel()
            {
                Book     = book,
                BookList = bookList
            });

            _context.Update(bookList);
            await _context.SaveChangesAsync();

            return(bookList);
        }
Ejemplo n.º 2
0
        public async Task <AuthorModel> Edit(AuthorModel author)
        {
            try
            {
                author.Name = author.Name.ToUpper();
                _context.Update(author);
                await _context.SaveChangesAsync();

                return(author);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(await Get(author.Id));
            }
        }
Ejemplo n.º 3
0
        public async Task <BookCategoryModel> Edit(BookCategoryModel category)
        {
            try
            {
                category.Name = category.Name.ToUpper();
                _context.Update(category);
                await _context.SaveChangesAsync();

                return(category);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(await Get(category.Id));
            }
        }
Ejemplo n.º 4
0
        public async Task <PublisherModel> Edit(PublisherModel publisher)
        {
            try
            {
                publisher.Name = publisher.Name.ToUpper();
                _context.Update(publisher);
                await _context.SaveChangesAsync();

                return(publisher);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(await Get(publisher.Id));
            }
        }