public async Task <IActionResult> PutAuthor(int id, Author author)
        {
            if (id != author.AuthorId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutStore(string id, Store store)
        {
            if (id != store.StoreId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("LanguageID,LanguageName")] Language language)
        {
            if (ModelState.IsValid)
            {
                _context.Add(language);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(language));
        }
        public async Task <IActionResult> Create(Translator translator)
        {
            if (ModelState.IsValid)
            {
                _context.Add(translator);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(translator));
        }
Ejemplo n.º 5
0
        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));
            }
        }