예제 #1
0
        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));
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
 public Connection()
 {
     validations = new Validations.Validations();
 }