public async Task <IActionResult> Post(BooksViewModel book)
        {
            if (!string.IsNullOrEmpty(book.BookName))
            {
                var isExist = await _BookService.GetByName(book.BookName);

                if (isExist != null && isExist.Id > 0)
                {
                    return(BadRequest("Book already exists"));
                }
                var newBook = new Books()
                {
                    BookName    = book.BookName,
                    CreatedBy   = book.CreatedBy,
                    CreatedDate = DateTime.UtcNow,
                    Price       = book.Price,
                };

                _BookService.AddAsync(newBook);

                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Example #2
0
        public async Task <IActionResult> Post([FromBody] BookModel model, CancellationToken cancellationToken)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(await GetBadRequestResult(ModelState, "api/v1/manage/add"));
                }

                await _service.AddAsync(model.ToEntity(), cancellationToken);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(await GetServerErrorResult(ex, "api/v1/manage/add"));
            }
        }
Example #3
0
        public async Task <IActionResult> PostAsync([FromBody] BookInputModel value)
        {
            if (value == null)
            {
                return(BadRequest("Invalid input"));
            }

            var result = await _booksService.AddAsync(value);

            if (result == null)
            {
                return(BadRequest("Book not inserted"));
            }

            return(CreatedAtRoute("BookGetAsync",
                                  new
            {
                id = result.Id
            },
                                  result));
        }