public async Task <IHttpActionResult> UpdateBook([FromBody] BookModel book) { bool isQuantityChanged = false; var list = _Book.UpdateBook(book, ref isQuantityChanged); if (isQuantityChanged && _Book.IsBookInWaitlist(book.BookID)) { var userID = _Book.GetUserInWaitlist(book.BookID); CartXBookModel cartXBookModel = new CartXBookModel(); cartXBookModel.BookID = book.BookID; cartXBookModel.Quantity = 1; CartModel cart = _Cart.GetCartByUserID(userID); if (cart != null) { _Book.AddBookToCart(cart.CartID, cartXBookModel); } else { List <CartXBookModel> cartXBookModelList = new List <CartXBookModel>(); cartXBookModelList.Add(cartXBookModel); _Cart.CreateCart(new CartModel { UserID = userID, CartID = new Guid(), CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, BookList = cartXBookModelList }); } var currentUser = await _UserManager.FindByIdAsync(userID.ToString()); var user = _Account.GetUserInfo(currentUser); OutWaitlistEmail(user, book); } if (list) { return(Ok()); } return(BadRequest()); }