예제 #1
0
        public async Task <IActionResult> PutGenre(int id, Genre genre)
        {
            var genres = _context.Genres.Where(sg => sg.Name == genre.Name).ToList().Count();

            if (genres != 0)
            {
                return(BadRequest("Жанр з такою назвою вже існує"));
            }
            if (id != genre.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #2
0
        public async Task <IActionResult> PutCountry(int id, Country country)
        {
            var countries = _context.Countries.Where(sg => sg.Name == country.Name).ToList().Count();

            if (countries != 0)
            {
                return(BadRequest("Країна з такою назвою вже існує"));
            }
            if (id != country.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #3
0
        public async Task <IActionResult> PutAuthor(int id, Author author)
        {
            var authors = _context.Authors.Where(sg => sg.Name == author.Name && sg.BitrhYear == author.BitrhYear && sg.CountryId == author.CountryId).ToList().Count();

            if (authors != 0)
            {
                return(BadRequest("Автор з таким ім'ям,країною і датою народження вже існує"));
            }
            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());
        }
예제 #4
0
        public async Task <IActionResult> PutBook(int id, Book book)
        {
            var books = _context.Books.Where(sg => sg.Name == book.Name && sg.AuthorId == book.AuthorId).ToList().Count();

            if (books != 0)
            {
                return(BadRequest("Книга з такою назвою вже існує"));
            }
            if (id != book.BookId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #5
0
        public async Task <IActionResult> PutBookGenre(int id, BookGenre bookGenre)
        {
            var bookGenres = _context.BookGenres.Where(sg => sg.GenreId == bookGenre.GenreId && sg.BookId == bookGenre.BookId).Include(sg => sg.Book).Include(sg => sg.Genre).ToList().Count();

            if (bookGenres != 0)
            {
                return(BadRequest("Книга з таким жанром вже існує"));
            }
            if (id != bookGenre.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }