public async Task <Response <Book> > CreateBook([FromBody] Book book)
        {
            var response = new Response <Book>();

            try
            {
                await _bookManager.CreateBook(book);
            }
            catch (Exception ex)
            {
                response.ErrorList.Add(ex.Adapt <ApiException>());
            }
            return(response);
        }
        public IActionResult Create([FromBody] B book)
        {
            if (book == null)
            {
                return(BadRequest());
            }

            if (_manager.CreateBook(new BookDto()))
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
        public async Task <IActionResult> CreateBook([FromBody] AddBookDto model)
        {
            var book = _mapper.Map <Book>(model);

            try
            {
                if (!await _manager.CreateBook(book))
                {
                    return(Ok(new JsonMessageResult("Fail", 0, null)));
                }

                return(CreatedAtAction(nameof(GetBook), new { book.Id }, book));
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                return(Ok(new JsonMessageResult("Fail", 0, null)));
            }
        }
Ejemplo n.º 4
0
        public async void CreateBook()
        {
            NewBook.DateAdded       = DateTime.Now;
            NewBook.AvailableCopies = NewBook.TotalCopies;

            if (!PerformValidation())
            {
                DisplayErrorMessage(FormatError);
                return;
            }

            bool success = await bookManager.CreateBook(NewBook).ConfigureAwait(false);

            if (success)
            {
                ClearBookDetails(NewBook);
                OnPropertyChanged("NewBook");
                MessageBox.Show("Book Successfully Added !", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                DisplayErrorMessage(InsertionError);
            }
        }