Exemplo n.º 1
0
        public void ReturnBook(int bookID)
        {
            var book = _context.BookOrders.Where(b => b.BookId == bookID).SingleOrDefault();

            book.IsReturned = true;
            _context.Update(book);
            _context.SaveChanges();
        }
Exemplo n.º 2
0
 private void ChangeCountBooksOnStore(List <BookOrder> booksOrder)
 {
     booksOrder.ForEach((BookOrder bo) =>
     {
         var book = _context.Books.Where(b => b.Id == bo.BookId).SingleOrDefault();
         if (book.Count < bo.CountOfBook)
         {
             throw new Exception("Кол-во книг на складе меньше кол-ва книг для пользователя");
         }
         book.Count -= bo.CountOfBook;
         _context.Update(book);
     });
     _context.SaveChanges();
 }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(string id, [Bind("Id,Name,AuthorId,CollectionId,Year,GenreId")] Book book)
        {
            if (id != book.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(book);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookExists(book.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorId"]     = new SelectList(_context.Author, "Id", "Id", book.AuthorId);
            ViewData["CollectionId"] = new SelectList(_context.Collection, "Id", "Id", book.CollectionId);
            return(View(book));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(string id, [Bind("Id,Content,BookId")] Review review)
        {
            if (id != review.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(review);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReviewExists(review.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"] = new SelectList(_context.Book, "Id", "Id", review.BookId);
            return(View(review));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> PutBook([FromRoute] int id, [FromBody] Book book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != book.BookId)
            {
                return(BadRequest());
            }

            _context.Update(book);
            // _context.Entry(book).State = EntityState.Modified;

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

            return(NoContent());
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,FirstName,LastName,DateOfBirth,Mobile,Address,City,Province,Country,PostalCode")] UserProfileModel userProfileModel)
        {
            if (id != userProfileModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userProfileModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserProfileModelExists(userProfileModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(userProfileModel));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Edit(int id, Two twoR)
        {
            if (id != twoR.Book.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    twoR.Book.Author = _context.Author.Where(r => r.ID == twoR.Book.AuthorRefId).SingleOrDefault();
                    _context.Update(twoR.Book);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookExists(twoR.Book.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            Two two = new Two();

            two.Authors = _context.Author.ToList();
            two.Book    = twoR.Book;
            return(View(two));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Edit(string id, [Bind("Id,Title")] Collection collection)
        {
            if (id != collection.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(collection);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CollectionExists(collection.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(collection));
        }
        public async Task <IActionResult> Edit(int id, [Bind("id,userId")] ReadingCard readingCard)
        {
            if (id != readingCard.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(readingCard);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReadingCardExists(readingCard.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["userId"] = new SelectList(_context.User, "id", "id", readingCard.userId);
            return(View(readingCard));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Title,Description,Author,ISBN,College,Rate,ImagePath")] BookADS bookADS)
        {
            if (id != bookADS.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(bookADS);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookADSExists(bookADS.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(bookADS));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Email,Score,Comments")] Review review)
        {
            if (id != review.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(review);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReviewExists(review.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(review));
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Edit(string id, [Bind("Id,Name,Surname")] Author author)
        {
            if (id != author.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(author);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AuthorExists(author.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(author));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Edit(int id, [Bind("BookId,UserId,Rating")] UserBook userBook)
        {
            if (id != userBook.BookId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userBook);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserBookExists(userBook.BookId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"] = new SelectList(_context.Books, "Id", "Author", userBook.BookId);
            return(View(userBook));
        }
Exemplo n.º 14
0
        public async Task <IActionResult> Edit(int id, [Bind("id,name")] Genre genre)
        {
            if (id != genre.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(genre);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GenreExists(genre.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(genre));
        }
Exemplo n.º 15
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Author,ISBN,ReleaseYear")] Books books)
        {
            if (id != books.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(books);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BooksExists(books.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(books));
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Edit(int id, [Bind("id,name,description,imageUrl,genre,authorId,posterId")] Book book)
        {
            if (id != book.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(book);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookExists(book.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["authorId"] = new SelectList(_context.Author, "id", "id", book.authorId);
            ViewData["posterId"] = new SelectList(_context.Poster, "id", "id", book.posterId);
            return(View(book));
        }
Exemplo n.º 17
0
 public async Task <IActionResult> AddOrEdit(int id, [Bind("Id,NameBook,GenreBook,AuthorBook,Pages,Data")] MyBooksModel booksModel)
 {
     if (ModelState.IsValid)
     {
         if (id == 0)
         {
             booksModel.Date = DateTime.Now;
             db.Add(booksModel);
             await db.SaveChangesAsync();
         }
         // Обнова
         else
         {
             try
             {
                 booksModel.Date = DateTime.Now;
                 db.Update(booksModel);
                 await db.SaveChangesAsync();
             }
             catch (DbUpdateConcurrencyException)
             {
                 if (!BooksModelExists(booksModel.Id))
                 {
                     return(NotFound());
                 }
                 else
                 {
                     throw;
                 }
             }
         }
         return(Json(new { isValid = true, html = RenderRazorViewToString(this, "Index", db.Books.ToList()) }));
     }
     return(Json(new { isValid = false, html = RenderRazorViewToString(this, "AddOrEdit", booksModel) }));
 }
Exemplo n.º 18
0
        public async Task <IActionResult> Edit(string id, [Bind("Id,Title,AuthorId")] Comics comics)
        {
            if (id != comics.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(comics);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ComicsExists(comics.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorId"] = new SelectList(_context.Author, "Id", "Id", comics.AuthorId);
            return(View(comics));
        }
Exemplo n.º 19
0
        public async Task <IActionResult> Edit(int id, [Bind("id,name,email,password,readingCardId")] User user)
        {
            if (id != user.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Exemplo n.º 20
0
        public async Task <IActionResult> Edit(string id, [Bind("Id,GenreId,BookId")] BooksGenres booksGenres)
        {
            if (id != booksGenres.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(booksGenres);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BooksGenresExists(booksGenres.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"]  = new SelectList(_context.Book, "Id", "Id", booksGenres.BookId);
            ViewData["GenreId"] = new SelectList(_context.Genre, "Id", "Id", booksGenres.GenreId);
            return(View(booksGenres));
        }
        public async Task <IActionResult> Edit(int id, [Bind("BookId,Isbn,Title,Publisher")] Book book)
        {
            if (id != book.BookId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(book);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookExists(book.BookId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
Exemplo n.º 22
0
        public IActionResult UpdateStock(string isbn, [FromBody] Book bookIn)
        {
            Book book     = _context.Book.FirstOrDefault(b => b.ISBN == isbn);
            int  oldStock = book.Stock;
            int  newStock = oldStock - 1;

            book.Stock = newStock;
            _context.Update(book);
            return(Ok(book));
        }
Exemplo n.º 23
0
        public async Task <IActionResult> Edit(int id, Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Update(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View(book));
            }
        }
Exemplo n.º 24
0
        public async Task <IActionResult> PutBook(Book book)
        {
            if (book == null)
            {
                return(BadRequest());
            }
            if (!_context.Books.Any(x => x.Id == book.Id))
            {
                return(NotFound());
            }

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

            return(Ok(book));
        }
Exemplo n.º 25
0
    public async Task UpdateBookAsync()
    {
        Book?book = await _booksContext.Books.FindAsync(1);

        if (book != null)
        {
            // detach the existing object from the context which allows to attach it with the Update method
            _booksContext.Entry(book).State = EntityState.Detached;
            Book bookUpdate = book with {
                Title = "Professional C# and .NET - 2021 Edition"
            };
            _booksContext.Update(bookUpdate);
            int records = await _booksContext.SaveChangesAsync();

            Console.WriteLine($"{records} record updated");
        }
        Console.WriteLine();
    }
Exemplo n.º 26
0
        public async Task <IActionResult> UpdateAsync([FromBody] Libros libro)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var _libro = await _context.Libros.SingleOrDefaultAsync(i => i.Isbn == libro.Isbn);

                    if (_libro == null)
                    {
                        return(NotFound());
                    }

                    _libro.Titulo        = libro.Titulo;
                    _libro.Sinopsis      = libro.Sinopsis;
                    _libro.NPaginas      = libro.NPaginas;
                    _libro.EditorialesId = libro.EditorialesId;
                    _libro.Editoriales   = await _context.Editoriales.SingleOrDefaultAsync(x => x.Id == libro.EditorialesId);

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

                    return(Ok(_libro));
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LibroExists(libro.Isbn))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                return(BadRequest());
            }
        }
Exemplo n.º 27
0
        public async Task <IActionResult> UpdateAsync([FromBody] Autores autor)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var _autor = await _context.Autores.SingleOrDefaultAsync(i => i.Id == autor.Id);

                    if (_autor == null)
                    {
                        return(NotFound());
                    }

                    _autor.Nombre    = autor.Nombre;
                    _autor.Apellidos = autor.Apellidos;

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

                    return(Ok(_autor));
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AutoresExists(autor.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                return(BadRequest());
            }
        }
Exemplo n.º 28
0
 public string Update(T item)
 {
     booksContext.Update(item);
     return(item.id + " updated...");
 }
Exemplo n.º 29
0
 public void IncCountBooks(Book book)
 {
     book.Count++;
     _context.Update(book);
     _context.SaveChanges();
 }
 public async Task EditElem(Order elem)
 {
     _context.Update(elem);
     await _context.SaveChangesAsync();
 }