Exemple #1
0
        public async Task <IActionResult> Create([Bind("AuthorID,Imie,Nazwisko")] Author author)
        {
            if (ModelState.IsValid)
            {
                _context.Add(author);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(author));
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("UserID,Imie,Nazwisko,Zapisany_od,Books")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("BookID,Tytul,AuthorID,Gatunek")] Book book)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(book);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            PopulateAuthorDropdownList(book.Autor);
            PopulateGatunekDropDownList(book.Gatunek);
            return(View(book));
        }