public int ReplaceBook(ReplaceBooksModel model)
        {
            var oldBookInRent = LibraryRepository.GetBookInRent(model.OldBookId);

            if (oldBookInRent == null)
            {
                throw new Exception($"The book with ID = {model.OldBookId} has not been rent.");
            }

            var newBookInRent = LibraryRepository.GetBookInRent(model.NewBookId);

            if (newBookInRent != null)
            {
                throw new Exception($"The book with ID = {model.NewBookId} has already been rent.");
            }

            var user = LibraryRepository.GetUser(model.UserId);

            if (user == null)
            {
                throw new Exception($"The user with ID = {model.UserId} doesn't exist.");
            }

            newBookInRent = new BookInRent
            {
                BookID = model.NewBookId,
                UserID = model.UserId
            };

            newBookInRent = LibraryRepository.ReplaceBook(oldBookInRent, newBookInRent);
            return(newBookInRent.ID);
        }
 public IHttpActionResult ReplaceBooks([FromBody] ReplaceBooksModel model)
 {
     try
     {
         var newRentId = LibraryService.ReplaceBook(model);
         return(Ok(newRentId));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }