Exemplo n.º 1
0
 public IActionResult AddPublisher([FromBody] PublisherVM publisher)
 {
     try
     {
         var newPublisher = _publisherService.AddPublisher(publisher);
         return(Created(nameof(AddPublisher), newPublisher));
     }
     catch (PublisherNameException ex)
     {
         return(BadRequest($"{ex.Message}, Publisher name: {ex.PublisherName}"));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Exemplo n.º 2
0
        public IActionResult AddPublisher([FromBody] PublisherViewModel publisher)
        {
            try
            {
                _publisherService.AddPublisher(publisher);
                return(Created(nameof(publisher), publisher));
            }
            catch (PublisherNameException exception)
            {
                return(BadRequest($"{exception.Message}, Publisher name: {exception.PublisherName}"));
            }

            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemplo n.º 3
0
        private static void FillDbUsingJsonFiles(BookRankingDbContext context, AuthorService authorService, PublisherService publisherService, BookService bookService)
        {
            using (var dbContextTransaction = context.Database.BeginTransaction())
            {
                try
                {
                    var settings = new JsonSerializerSettings();
                    settings.TypeNameHandling = TypeNameHandling.Auto;

                    var file       = File.ReadAllText("publishers.json");
                    var publishers = ((JArray)JsonConvert.DeserializeObject(file, settings)).ToObject <List <PublisherDTO> >();

                    foreach (var publisher in publishers)
                    {
                        publisherService.AddPublisher(publisher);
                    }

                    file = File.ReadAllText("authors.json");
                    var authors = ((JArray)JsonConvert.DeserializeObject(file, settings)).ToObject <List <AuthorDTO> >();

                    foreach (var author in authors)
                    {
                        authorService.AddAuthor(author);
                    }

                    file = File.ReadAllText("book.json");
                    var books = ((JArray)JsonConvert.DeserializeObject(file, settings)).ToObject <List <BookDTO> >();

                    foreach (var book in books)
                    {
                        bookService.AddBook(book);
                    }

                    context.SaveChanges();

                    dbContextTransaction.Commit();
                }
                catch (Exception e)
                {
                    dbContextTransaction.Rollback();
                }
            }
        }
Exemplo n.º 4
0
        public async Task AddShouldAddPublisher()
        {
            var optionsBuilder = new DbContextOptionsBuilder <BookTubeContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var dbContext = new BookTubeContext(optionsBuilder.Options);
            var service   = new PublisherService(dbContext);

            var publisher = new Publisher
            {
                Id       = 1,
                Name     = "Siela",
                Contacts = "Sofia, Bulgaria"
            };

            await service.AddPublisher(publisher.Name, publisher.Contacts);

            var publisherFromDb = dbContext.Publishers.Select(x => x.Name).First();

            Assert.Equal(publisherFromDb, publisher.Name);
        }
 public IActionResult AddPublisher([FromBody] PublisherDTO publisherDTO)
 {
     _publisherService.AddPublisher(publisherDTO);
     return(Ok());
 }
Exemplo n.º 6
0
 public static Publisher AddPublisher(Publisher publisher)
 {
     return(PublisherService.AddPublisher(publisher));
 }
Exemplo n.º 7
0
        public IActionResult AddBook([FromBody] PublisherVM publisher)
        {
            var newPublisher = _publisherrService.AddPublisher(publisher);

            return(Created(nameof(AddBook), newPublisher));
        }
Exemplo n.º 8
0
 public IActionResult AddAuthor([FromBody] PublisherVm publisher)
 {
     _publisherService.AddPublisher(publisher);
     return(Ok());
 }