public async Task <ActionResult <Author> > Store([FromServices] OceanOfLettersContext _context, Author author) { Response response = new Response(); Validations.Validations validation = new Validations.Validations(); try { response = validation.Validate(author); if (validation.IsValid) { response = await new AuthorsApplication(_context).Store(author); } else { response.BadRequest = true; } } catch (Exception ex) { response.Message = ex.Message; response.BadRequest = true; } if (response.BadRequest) { return(BadRequest(response)); } else { return(CreatedAtAction("GetAuthor", new { id = author.Id }, response)); } }
public async Task <IActionResult> PutCountry([FromServices] OceanOfLettersContext _context, int id, Country country) { if (id != country.Id) { return(BadRequest()); } _context.Entry(country).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CountryExists(_context, id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Language> > GetLanguage([FromServices] OceanOfLettersContext _context, int id) { var language = await _context.Language.FindAsync(id); if (language == null) { return(NotFound()); } return(language); }
public async Task <ActionResult <PublishingCompany> > GetPublishingCompany([FromServices] OceanOfLettersContext _context, int id) { var publishingCompany = await _context.PublishingCompany.FindAsync(id); if (publishingCompany == null) { return(NotFound()); } return(publishingCompany); }
public async Task <ActionResult <Series> > GetSeries([FromServices] OceanOfLettersContext _context, int id) { var series = await _context.Series.FindAsync(id); if (series == null) { return(NotFound()); } return(series); }
public async Task <ActionResult <Brand> > GetBrand([FromServices] OceanOfLettersContext _context, int id) { var brand = await _context.Brand.FindAsync(id); if (brand == null) { return(NotFound()); } return(brand); }
public async Task <ActionResult <Author> > GetAuthor([FromServices] OceanOfLettersContext _context, int id) { var author = await _context.Author.FindAsync(id); if (author == null) { return(NotFound()); } return(author); }
public async Task <ActionResult <Genre> > GetGenre([FromServices] OceanOfLettersContext _context, int id) { var genre = await _context.Genre.FindAsync(id); if (genre == null) { return(NotFound()); } return(genre); }
public async Task <ActionResult <Country> > GetCountry([FromServices] OceanOfLettersContext _context, int id) { var country = await _context.Country.FindAsync(id); if (country == null) { return(NotFound()); } return(country); }
public async Task <ActionResult <Book> > GetBook([FromServices] OceanOfLettersContext _context, int id) { var book = await _context.Book.FindAsync(id); if (book == null) { return(NotFound()); } return(book); }
public async Task <ActionResult <Language> > DeleteLanguage([FromServices] OceanOfLettersContext _context, int id) { var language = await _context.Language.FindAsync(id); if (language == null) { return(NotFound()); } _context.Language.Remove(language); await _context.SaveChangesAsync(); return(language); }
public async Task <ActionResult <Genre> > DeleteGenre([FromServices] OceanOfLettersContext _context, int id) { var genre = await _context.Genre.FindAsync(id); if (genre == null) { return(NotFound()); } _context.Genre.Remove(genre); await _context.SaveChangesAsync(); return(genre); }
public async Task <ActionResult <Book> > DeleteBook([FromServices] OceanOfLettersContext _context, int id) { var book = await _context.Book.FindAsync(id); if (book == null) { return(NotFound()); } _context.Book.Remove(book); await _context.SaveChangesAsync(); return(book); }
public async Task <ActionResult <Series> > DeleteSeries([FromServices] OceanOfLettersContext _context, int id) { var series = await _context.Series.FindAsync(id); if (series == null) { return(NotFound()); } _context.Series.Remove(series); await _context.SaveChangesAsync(); return(series); }
public async Task <ActionResult <Author> > DeleteAuthor([FromServices] OceanOfLettersContext _context, int id) { var author = await _context.Author.FindAsync(id); if (author == null) { return(NotFound()); } _context.Author.Remove(author); await _context.SaveChangesAsync(); return(author); }
public async Task <ActionResult <Country> > DeleteCountry([FromServices] OceanOfLettersContext _context, int id) { var country = await _context.Country.FindAsync(id); if (country == null) { return(NotFound()); } _context.Country.Remove(country); await _context.SaveChangesAsync(); return(country); }
public async Task <ActionResult <Response> > Avatars([FromServices] OceanOfLettersContext _context, [FromForm] FilesUp filesUp, [FromQuery] string path, [FromQuery] string name) { Response response = new Response(); Avatar avatar = new Avatar(); try { if (filesUp.File.Length > 0) { if (!Directory.Exists(Environment.WebRootPath + "\\Avatars\\")) { Directory.CreateDirectory(Environment.WebRootPath + "\\Avatars\\"); } using FileStream fileStream = System.IO.File.Create(Environment.WebRootPath + "\\Avatars\\" + path); await filesUp.File.CopyToAsync(fileStream); fileStream.Flush(); avatar.Url = "http://localhost:5000/Avatars/" + path; avatar.Path = path; avatar.Name = name; response.Avatar = avatar; _context.Add(avatar); await _context.SaveChangesAsync(); } else { response.Message = "Arquivo vázio!"; response.BadRequest = true; } } catch (Exception ex) { response.Message = ex.Message; response.BadRequest = true; } if (response.BadRequest) { return(BadRequest(response)); } else { return(Ok(response)); } }
public async Task <ActionResult <Series> > Store([FromServices] OceanOfLettersContext _context, Series series) { Response response = new Response(); Validations.Validations validation = new Validations.Validations(); try { response = validation.Validate(series); if (validation.IsValid) { response = await new SeriesApplication(_context).Store(series); } else { response.BadRequest = true; } } catch (Exception ex) { response.Message = ex.Message; response.BadRequest = true; } if (response.BadRequest) { return(BadRequest(response)); } else { return(CreatedAtAction("GetSeries", new { id = series.Id }, response)); } //_context.Series.Add(series); //await _context.SaveChangesAsync(); //return CreatedAtAction("GetSeries", new { id = series.Id }, series); }
public async Task <ActionResult <PublishingCompany> > Store([FromServices] OceanOfLettersContext _context, PublishingCompany publishingCompany) { Response response = new Response(); Validations.Validations validation = new Validations.Validations(); try { response = validation.Validate(publishingCompany); if (validation.IsValid) { response = await new PublishingCompaniesApplication(_context).Store(publishingCompany); } else { response.BadRequest = true; } } catch (Exception ex) { response.Message = ex.Message; response.BadRequest = true; } if (response.BadRequest) { return(BadRequest(response)); } else { return(CreatedAtAction("GetPublishingCompany", new { id = publishingCompany.Id }, response)); } //_context.PublishingCompany.Add(publishingCompany); //await _context.SaveChangesAsync(); //return CreatedAtAction("GetPublishingCompany", new { id = publishingCompany.Id }, publishingCompany); }
public async Task <ActionResult <List <PublishingCompany> > > Index([FromServices] OceanOfLettersContext _context, [FromQuery] bool brands, [FromQuery] bool books, [FromQuery] bool authors, [FromQuery] bool genres, [FromQuery] bool series, [FromQuery] int publishing_companies) { Response response = new Response(); try { response = await new PublishingCompaniesApplication(_context).Index(brands, books, authors, genres, series, publishing_companies); } catch (Exception ex) { response.Message = ex.Message; response.BadRequest = true; } if (response.BadRequest) { return(BadRequest(response)); } else { return(Ok(response)); } }
public async Task <ActionResult <List <Book> > > Index([FromServices] OceanOfLettersContext _context, [FromQuery] bool series, [FromQuery] bool authors, [FromQuery] bool genres, [FromQuery] bool language, [FromQuery] bool country, [FromQuery] bool publishing_company, [FromQuery] bool brand, [FromQuery] int books) { Response response = new Response(); try { response = await new BooksApplication(_context).Index(series, authors, genres, language, country, publishing_company, brand, books); } catch (Exception ex) { response.Message = ex.Message; response.BadRequest = true; } if (response.BadRequest) { return(BadRequest(response)); } else { return(Ok(response)); } }
public async Task <ActionResult <List <Country> > > Index([FromServices] OceanOfLettersContext _context, [FromQuery] bool language, [FromQuery] bool books, [FromQuery] bool authors, [FromQuery] int countries) { Response response = new Response(); try { response = await new CountriesApplication(_context).Index(language, books, authors, countries); } catch (Exception ex) { response.Message = ex.Message; response.BadRequest = true; } if (response.BadRequest) { return(BadRequest(response)); } else { return(Ok(response)); } }
public PublishingCompaniesApplication(OceanOfLettersContext context) { Context = context; }
private bool PublishingCompanyExists(OceanOfLettersContext _context, int id) { return(_context.PublishingCompany.Any(e => e.Id == id)); }
private bool BookExists(OceanOfLettersContext _context, int id) { return(_context.Book.Any(e => e.Id == id)); }
private bool CountryExists(OceanOfLettersContext _context, int id) { return(_context.Country.Any(e => e.Id == id)); }
public async Task <ActionResult <Book> > Store([FromServices] OceanOfLettersContext _context, Book book) { Response response = new Response(); Validations.Validations validation = new Validations.Validations(); try { response = validation.Validate(book); if (validation.IsValid) { //foreach (AuthorsBook authorBook in book.AuthorsBook) //{ // if (!new AuthorApplication(_context).ExistAuthorById(authorBook.AuthorId)) // { // repost.Message = "Autor não cadastrado!"; // return BadRequest(repost); // } //} //if (!new PublishingCompanyApplication(_context).ExistPublishingCompany(book.PublishingCompanyId)) //{ // repost.Message = "Editora não cadastrada!"; // return BadRequest(repost); //} //if (book.SeriesId != null) //{ // if (!new SeriesApplication(_context).ExistSeries(book.SeriesId)) // { // repost.Message = "Série não cadastrada!"; // return BadRequest(repost); // } //} //if (book.BrandId != null) //{ // if (!new BrandApplication(_context).ExistBrand(book.BrandId)) // { // repost.Message = "Marca de editora não cadastrada!"; // return BadRequest(repost); // } //} //if (!new CountryApplication(_context).ExistCountry(book.CountryId)) //{ // repost.Message = "País não cadastrado!"; // return BadRequest(repost); //} //if (new LanguageApplication(_context).ExistLanguage(book.LanguageId) == false) //{ // repost.Message = "Idioma não cadastrado!"; // return BadRequest(repost); //} //foreach (GenresBook genresBook in book.GenresBooks) //{ // if (!new GenreApplication(_context).ExistGenre(genresBook.GenreId)) // { // repost.Message = "Gênero não cadastrado!"; // return BadRequest(repost); // } //} response = await new BooksApplication(_context).Store(book); } else { response.BadRequest = true; } } catch (Exception ex) { response.Message = ex.Message; response.BadRequest = true; } if (response.BadRequest) { return(BadRequest(response)); } else { return(CreatedAtAction("GetBook", new { id = book.Id }, response)); } //_context.Book.Add(book); //await _context.SaveChangesAsync(); //return CreatedAtAction("GetBook", new { id = book.Id }, book); }
public BooksApplication(OceanOfLettersContext context) { Context = context; }
public AuthorsApplication(OceanOfLettersContext context) { Context = context; }
private bool LanguageExists(OceanOfLettersContext _context, int id) { return(_context.Language.Any(e => e.Id == id)); }