예제 #1
0
        public async Task <IActionResult> AddBook(BookRequest book)
        {
            try
            {
                var user = HttpContext.User;
                if ((user.HasClaim(u => u.Type == "TokenType")) && (user.HasClaim(u => u.Type == "UserRole")))
                {
                    if ((user.Claims.FirstOrDefault(u => u.Type == "TokenType").Value == "login") &&
                        (user.Claims.FirstOrDefault(u => u.Type == "UserRole").Value == "Admin"))
                    {
                        int adminID = Convert.ToInt32(user.Claims.FirstOrDefault(u => u.Type == "AdminID").Value);
                        var data    = await _bookBusiness.AddBook(adminID, book);

                        if (data != null)
                        {
                            success = true;
                            message = "Book Details Added Successfully";
                            return(Ok(new { success, message, data }));
                        }
                        else
                        {
                            message = "No Data Provided";
                            return(NotFound(new { success, message }));
                        }
                    }
                }
                message = "You are not allowed to add Book, Token Invalid!";
                return(BadRequest(new { success, message }));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { ex.Message }));
            }
        }
예제 #2
0
 public IActionResult AddBooks([FromBody] BookModel model)
 {
     try
     {
         var result = business.AddBook(model);
         if (result != null)
         {
             return(Ok(new { Status = true, Message = "Book Added Successfull", Data = result }));
         }
         return(BadRequest(new { Status = false, Message = "Error While Adding Book" }));
     }
     catch (Exception e)
     {
         return(NotFound(new { Status = false, Message = e.Message }));
     }
 }
예제 #3
0
        public void IsBookInserted()
        {
            Book book = new Book();

            book.ISBN        = "1213";
            book.NameAuthor  = "Njegos";
            book.Quantity    = 6;
            book.Title       = "Lampa";
            book.YearOfIssue = 1234;

            // Arrange
            mockBookRepository.Setup(x => x.AddBook(book)).Returns(true);
            this.bookBusiness = new BookBusiness();
            // Act
            var result = bookBusiness.AddBook(book);

            // Assert
            Assert.IsTrue(result);
        }