Exemple #1
0
        public async Task <IActionResult> PutAuthor_Book(int id, Author_Book author_Book)
        {
            if (id != author_Book.AuthurId)
            {
                return(BadRequest());
            }

            _context.Entry(author_Book).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Author_BookExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #2
0
        public void AddAuthor_Book(int idBook, int idAuthor)
        {
            Author_Book authbook = new Author_Book
            {
                IdAuthors = idAuthor,
                IdBooks   = idBook,
            };

            GetAuthor_BooksTable().InsertOnSubmit(authbook);
            Dc.SubmitChanges();
        }
Exemple #3
0
        public string Register(Author_Book author_Book)
        {
            var testbook   = b_repository.GetAll().Where(ab => ab.id == author_Book.Bookid).ToList().Count;
            var testauthor = a_repository.GetAll().Where(ab => ab.id == author_Book.Authorid).ToList().Count;

            if (testauthor == 0)
            {
                return("Not Found any author with this id");
            }
            if (testbook == 0)
            {
                return("Not Found any book with this id");
            }

            repository.Insert(author_Book);
            repository.Save();
            return(author_Book.id + " register...");
        }
Exemple #4
0
        public async Task <ActionResult <Author_Book> > PostAuthor_Book(Author_Book author_Book)
        {
            _context.Author_Books.Add(author_Book);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (Author_BookExists(author_Book.AuthurId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetAuthor_Book", new { id = author_Book.AuthurId }, author_Book));
        }
        public async Task <IActionResult> Create(BookCreateViewModel ViewModel)
        {
            if (ModelState.IsValid)
            {
                List <Author_Book>     author_Books = new List <Author_Book>();
                List <Book_Translator> translators  = new List <Book_Translator>();
                List <Book_Category>   categories   = new List <Book_Category>();
                DateTime?PublishDate = null;
                if (ViewModel.IsPublish == true)
                {
                    PublishDate = DateTime.Now;
                }
                Book book = new Book()
                {
                    Delete      = false,
                    ISBN        = ViewModel.ISBN,
                    IsPublish   = ViewModel.IsPublish,
                    NumOfPages  = ViewModel.NumOfPages,
                    Stock       = ViewModel.Stock,
                    Price       = ViewModel.Price,
                    LanguageID  = ViewModel.LanguageID,
                    Summary     = ViewModel.Summary,
                    Title       = ViewModel.Title,
                    PublishYear = ViewModel.PublishYear,
                    PublishDate = PublishDate,
                    Weight      = ViewModel.Weight,
                    PublisherID = ViewModel.PublisherID
                };
                await _context.Books.AddAsync(book);

                if (ViewModel.AuthorID != null)
                {
                    for (int i = 0; i < ViewModel.AuthorID.Length; i++)
                    {
                        Author_Book author_Book = new Author_Book()
                        {
                            BookID   = book.BookID,
                            AuthorID = ViewModel.AuthorID[i],
                        };
                        author_Books.Add(author_Book);
                    }
                }
                await _context.Author_Books.AddRangeAsync(author_Books);

                if (ViewModel.TranslatorID != null)
                {
                    for (int i = 0; i < ViewModel.TranslatorID.Length; i++)
                    {
                        Book_Translator translator = new Book_Translator()
                        {
                            BookID       = book.BookID,
                            TranslatorID = ViewModel.TranslatorID[i],
                        };

                        translators.Add(translator);
                    }

                    await _context.Book_Translators.AddRangeAsync(translators);
                }

                if (ViewModel.CategoryID != null)
                {
                    for (int i = 0; i < ViewModel.CategoryID.Length; i++)
                    {
                        Book_Category category = new Book_Category()
                        {
                            BookID     = book.BookID,
                            CategoryID = ViewModel.CategoryID[i],
                        };

                        categories.Add(category);
                    }

                    await _context.Book_Categories.AddRangeAsync(categories);
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction("index"));
            }
            else
            {
                ViewBag.LanguageID  = new SelectList(_context.Languages, "LanguageID", "LanguageName");
                ViewBag.PublisherID = new SelectList(_context.Publishers, "PublisherID", "PublisherName");
                ViewBag.AuthorID    = new SelectList(_context.Authors.Select(t => new AuthorList {
                    AuthorID = t.AuthorID, NameFamily = t.FirstName + " " + t.LastName
                }), "AuthorID", "NameFamily");
                ViewBag.TranslatorID = new SelectList(_context.Translator.Select(t => new TranslatorList {
                    TranslatorID = t.TranslatorID, NameFamily = t.Name + " " + t.Family
                }), "TranslatorID", "NameFamily");
                ViewModel.Categories = _repository.GenerateAllTree();

                return(View(ViewModel));
            }
        }