public async Task <ActionResult> Create(CreateBooksRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var response = await _bookRepo.CreateAsync(request);

            if (response.IsSuccessStatusCode)
            {
                return(View("SuccessfullyCreatedBook"));
            }

            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        private async void btnAdd_Click(object sender, EventArgs e)
        {
            var bookName    = txtBookName.Text;
            var pages       = txtPages.Text;
            var publishedAt = txtPublishedAt.Text;
            var edition     = txtEdition.Text;
            var author      = txtAuthor.Text;
            var genre       = (Genre)cboGenre.SelectedIndex;

            if (bookName.IsNullOrEmpty() || author.IsNullOrEmpty())
            {
                return;
            }

            try
            {
                Cursor = Cursors.WaitCursor;

                var book = new BookEntity
                {
                    BookName    = bookName,
                    Pages       = pages,
                    PublishedAt = publishedAt,
                    Edition     = edition,
                    Author      = author,
                    Genre       = genre
                };

                var createdBook = await BookRepository.CreateAsync(book);

                ctlDataGridView.PopulateDataGridView(createdBook);

                LocalizeDataGridView();

                btnClear.PerformClick();
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                MessageBox.Show(Resource_Localization.ErrorUnknown);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
        public async Task HTTPClient_CreateBook_ShouldReturnOkAndReturnPOSTMethodToCorrecHTTP()
        {
            //Arrange
            var createdBook = new CreateBooksRequest()
            {
                Id             = 1,
                Title          = "pippi",
                Descriptions   = "Långstrump",
                PageCount      = 220,
                Published      = DateTime.Parse("2020-02-20"),
                AuthorName     = "Jörgen",
                AuthorLastName = "Brink",
                Category       = "Baby"
            };
            var json         = JsonConvert.SerializeObject(createdBook);
            var url          = "https://localhost:44382/api/Books/Create";
            var content      = new StringContent(json, Encoding.UTF8, "application/json");
            var httpResponse = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
            };

            var mockHttpClientProvider = new Mock <IHttpClientProvider>();

            mockHttpClientProvider.Setup(t => t.PostAsync(url, content))
            .ReturnsAsync(httpResponse).Verifiable();

            var response = new BookRepository(mockHttpClientProvider.Object);

            // ACT
            var result = await response.CreateAsync(createdBook);

            //Assert
            var expectedUri = new Uri("https://localhost:44382/api/Books/Create");

            result.Should().NotBeNull();
            mockHttpClientProvider.Verify(x => x.PostAsync(expectedUri.ToString(), result.Content), Times.Once());
            ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post &&
                                           req.RequestUri == expectedUri);
        }
Beispiel #4
0
        public async Task CreateBookAsync(CreateBookViewModel cNPDTO)
        {
            Book tempPaper = Mapper.Map <CreateBookViewModel, Book> (cNPDTO);

            await _bookRepository.CreateAsync(tempPaper);
        }
Beispiel #5
0
        public async Task <IActionResult> Add([FromBody] Book book)
        {
            await bookRepository.CreateAsync(book);

            return(RedirectToAction("index"));
        }