Example #1
0
        /// <summary>
        /// Add Book into Wish List
        /// </summary>
        /// <param name="userID">User-ID</param>
        /// <param name="wishList">Wish List Data</param>
        /// <returns>If Data Added Successfully return Response Data else null or Bad Request</returns>
        public async Task <BookResponse> AddBookIntoWishList(int userID, int wishListID, WishListBookRequest wishListBook)
        {
            try
            {
                BookResponse responseData = null;
                SQLConnection();
                using (SqlCommand cmd = new SqlCommand("AddBookIntoWishList", conn))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@UserID", userID);
                    cmd.Parameters.AddWithValue("@WishListID", wishListID);
                    cmd.Parameters.AddWithValue("@BookID", wishListBook.BookID);
                    cmd.Parameters.AddWithValue("@IsMoved", false);

                    conn.Open();
                    SqlDataReader dataReader = await cmd.ExecuteReaderAsync();

                    responseData = BookResponseModel(dataReader);
                };
                return(responseData);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Example #2
0
        public BookResponse GetBook(string id)
        {
            BookResponse resp = new BookResponse();
            int          bookId;

            if (int.TryParse(id, out bookId))
            {
                using (TablesContext context = new TablesContext())
                {
                    resp.Book = context.Books.Find(bookId);
                    if (resp.Book != null && !resp.Book.Deleted)
                    {
                        resp.Status  = (int)Constants.STATUSES.OK;
                        resp.Message = Constants.SUCCESS;
                    }
                    else
                    {
                        resp.Book    = null;
                        resp.Status  = (int)Constants.STATUSES.ERROR;
                        resp.Message = Constants.BOOK_NOT_FOUND;
                    }
                }
            }
            else
            {
                resp.Status  = (int)Constants.STATUSES.ERROR;
                resp.Message = Constants.ENTER_INT;
            }

            return(resp);
        }
Example #3
0
        private bool HandleObjectMessage(string msg)
        {
            var response = BitmexJsonSerializer.Deserialize <JObject>(msg);

            // ********************
            // ADD OBJECT HANDLERS BELOW
            // ********************

            return

                (TradeResponse.TryHandle(response, Streams.TradesSubject) ||
                 TradeBinResponse.TryHandle(response, Streams.TradeBinSubject) ||
                 BookResponse.TryHandle(response, Streams.BookSubject) ||
                 QuoteResponse.TryHandle(response, Streams.QuoteSubject) ||
                 LiquidationResponse.TryHandle(response, Streams.LiquidationSubject) ||
                 PositionResponse.TryHandle(response, Streams.PositionSubject) ||
                 OrderResponse.TryHandle(response, Streams.OrderSubject) ||
                 WalletResponse.TryHandle(response, Streams.WalletSubject) ||


                 ErrorResponse.TryHandle(response, Streams.ErrorSubject) ||
                 SubscribeResponse.TryHandle(response, Streams.SubscribeSubject) ||
                 InfoResponse.TryHandle(response, Streams.InfoSubject) ||
                 AuthenticationResponse.TryHandle(response, Streams.AuthenticationSubject));
        }
        private async void LoadBooks()
        {
            var connection = await this.apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    connection.Message,
                    Languages.Accept);

                return;
            }

            var apiBibles = Application.Current.Resources["APIbibles"].ToString();
            var response  = await this.apiService.Get <BookResponse>(
                apiBibles,
                "/api",
                string.Format("/books?language={0}", bible.LangShort));

            if (!response.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    response.Message,
                    Languages.Accept);

                return;
            }

            this.bookResponse = (BookResponse)response.Result;

            if (bible.LangShort != "en")
            {
                var response2 = await this.apiService.Get <BookResponse>(
                    apiBibles,
                    "/api",
                    "/books?language=en");

                if (!response2.IsSuccess)
                {
                    await Application.Current.MainPage.DisplayAlert(
                        Languages.Error,
                        response2.Message,
                        Languages.Accept);

                    return;
                }

                var booksResult2 = (BookResponse)response2.Result;

                for (int i = 0; i < this.bookResponse.Books.Count; i++)
                {
                    this.bookResponse.Books[i].Shortname = booksResult2.Books[i].Shortname;
                }
            }

            this.Books = new ObservableCollection <BookItemViewModel>(
                this.ToBookItemViewModel());
        }
Example #5
0
 public List <BookResponse> GetAllBooks()
 {
     try
     {
         List <BookResponse> bookResponseList = new List <BookResponse>();
         var responseList = this.dbContext.Books;
         foreach (var response in responseList)
         {
             if (response.IsDeleted == "No")
             {
                 BookResponse bookResponse = new BookResponse();
                 bookResponse.BookId      = response.BookId;
                 bookResponse.BookName    = response.BookName;
                 bookResponse.AuthorName  = response.AuthorName;
                 bookResponse.Description = response.Description;
                 bookResponse.Price       = response.Price;
                 bookResponse.Quantity    = response.Quantity;
                 bookResponse.CreatedDate = response.CreatedDate;
                 bookResponse.Image       = response.Image;
                 bookResponseList.Add(bookResponse);
             }
         }
         return(bookResponseList);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Example #6
0
        public async Task <ActionResult <BookResponse> > GetBookById(int id)
        {
            var book = await this._context.Books
                       .Where(book => book.Id == id)
                       .Include(a => a.Author)
                       .SingleOrDefaultAsync();

            if (book == null)
            {
                return(NotFound());
            }

            var bookResponse = new BookResponse()
            {
                Id          = book.Id,
                Title       = book.Title,
                ImageSrc    = book.ImageSrc,
                Price       = book.Price,
                Description = book.Description,
                Author      = new BookAuthor()
                {
                    Id       = book.AuthorId,
                    FullName = $"{book.Author.FirstName} {book.Author.LastName}"
                }
            };

            return(this.Ok(bookResponse));
        }
Example #7
0
        // TODO: invalid response and created response are coming back null
        public async Task <BookResponse> GetAllBooks()
        {
            var client = new RestClient($"https://bookclubapiservicev2.azurewebsites.net/api/books");

            client.Timeout = -1;

            //var bearerAccessToken = $"bearer " + ctx.Request.Cookies["access_token"]; // may need later

            var bookGetRequest = new RestRequest(Method.GET);

            //bookAddRequest.AddHeader("Authorization", bearerAccessToken);

            var bookGetResponse = await client.ExecuteAsync <BookResponse>(bookGetRequest);

            if (bookGetResponse.StatusCode.ToString() != "OK")
            {
                BookResponse invalidResponse = JsonConvert.DeserializeObject <BookResponse>(bookGetResponse.Content);

                return(invalidResponse);
            }

            List <Book> returnedBooks = JsonConvert.DeserializeObject <List <Book> >(bookGetResponse.Content);

            BookResponse createdResponse = new BookResponse
            {
                ResponseMessage = bookGetResponse.StatusCode.ToString(),
                Books           = returnedBooks
            };

            return(createdResponse);
        }
Example #8
0
        public async Task <BookResponse> GetBooks()
        {
            BookResponse peopleResponse = new BookResponse();
            string       endpoint       = Configurations.bookEndPoint;
            var          response       = await HttpClientBaseService.GetAsync(endpoint);

            if (response.Content == null)
            {
                return((BookResponse)Convert.ChangeType(response, typeof(BookResponse)));
            }
            else
            {
                string data = await response.Content.ReadAsStringAsync();

                if (string.IsNullOrEmpty(data))
                {
                    return(new BookResponse
                    {
                    });
                }

                var result = JsonConvert.DeserializeObject <IList <Book> >(data);
                peopleResponse.Books = result;
                return(peopleResponse);
            }
        }
Example #9
0
        public BookResponse ReadOne(int id)
        {
            var response = new BookResponse();
            var book     = _database.Books
                           .Include(b => b.AuthorLinks)
                           .Include(b => b.Account)
                           .Include(b => b.SubCategoriesLink)
                           .ThenInclude(subCLink => subCLink.SubCategory)
                           .Include(b => b.TagLinks)
                           .ThenInclude(taglink => taglink.Tag)
                           .SingleOrDefault(t => t.Id == id);

            if (book == null)
            {
                return(response);
            }
            response.Id          = book.Id;
            response.Name        = book.Name;
            response.Base64Image = book.BookImage;
            response.Authors     = book.AuthorLinks.Select(al => al.Author).ToList();
            response.Editor      = new Editor
            {
                Id          = book.Account.Id,
                Address     = book.Account.Address,
                Email       = book.Account.Email,
                FirstName   = book.Account.FirstName,
                LastName    = book.Account.LastName,
                PhoneNumber = book.Account.PhoneNumber,
            };
            response.SubCategories = book.SubCategoriesLink.Select(sl => sl.SubCategory).ToList();
            response.Tags          = book.TagLinks.Select(tl => tl.Tag).ToList();
            return(response);
        }
Example #10
0
        public async Task <IHttpActionResult> GetById([FromUri] int?id)
        {
            if (id == null)
            {
                return(BadRequest());
            }

            var book = await _repoWrapper.Book.GetBookByIdAsync((int)id);

            if (book == null)
            {
                return(NotFound());
            }

            var bookReponse = new BookResponse
            {
                Id           = book.Id,
                Title        = book.Title,
                Descriptions = book.Descriptions,
                ISBN         = book.ISBN,
                PageCount    = book.PageCount,
                Published    = book.Published,
                Author       = book.AuthorId.ToString(),
                Category     = book.CategoryId.ToString()
            };

            return(Json(bookReponse));
        }
        /// <summary>
        /// Handles object messages sent by bitmex.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <param name="streams">The streams.</param>
        /// <returns></returns>
        public static bool HandleObjectMessage(string msg, BitmexClientStreams streams)
        {
            var response = BitmexJsonSerializer.Deserialize <JObject>(msg);

            // ********************
            // ADD OBJECT HANDLERS BELOW
            // ********************

            return
                (TradeResponse.TryHandle(response, streams.TradesSubject) ||
                 TradeBinResponse.TryHandle(response, streams.TradeBinSubject) ||
                 BookResponse.TryHandle(response, streams.BookSubject) ||
                 QuoteResponse.TryHandle(response, streams.QuoteSubject) ||
                 LiquidationResponse.TryHandle(response, streams.LiquidationSubject) ||
                 PositionResponse.TryHandle(response, streams.PositionSubject) ||
                 MarginResponse.TryHandle(response, streams.MarginSubject) ||
                 OrderResponse.TryHandle(response, streams.OrderSubject) ||
                 WalletResponse.TryHandle(response, streams.WalletSubject) ||
                 InstrumentResponse.TryHandle(response, streams.InstrumentSubject) ||
                 ExecutionResponse.TryHandle(response, streams.ExecutionSubject) ||
                 FundingResponse.TryHandle(response, streams.FundingsSubject) ||


                 ErrorResponse.TryHandle(response, streams.ErrorSubject) ||
                 SubscribeResponse.TryHandle(response, streams.SubscribeSubject) ||
                 InfoResponse.TryHandle(response, streams.InfoSubject) ||
                 AuthenticationResponse.TryHandle(response, streams.AuthenticationSubject));
        }
Example #12
0
 /// <summary>
 /// List of Book Response Method
 /// </summary>
 /// <param name="dataReader">Sql Data Reader</param>
 /// <returns>It return List of Book Response Data</returns>
 private List <BookResponse> ListBookResponseModel(SqlDataReader dataReader)
 {
     try
     {
         List <BookResponse> bookList     = new List <BookResponse>();
         BookResponse        responseData = null;
         while (dataReader.Read())
         {
             responseData = new BookResponse
             {
                 BookID   = Convert.ToInt32(dataReader["BookID"]),
                 Name     = dataReader["Name"].ToString(),
                 Author   = dataReader["Author"].ToString(),
                 Language = dataReader["Language"].ToString(),
                 Category = dataReader["Category"].ToString(),
                 ISBN     = dataReader["ISBN"].ToString(),
                 Pages    = dataReader["Pages"].ToString(),
             };
             bookList.Add(responseData);
         }
         return(bookList);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
        public void HandleOrderBook(BookResponse response)
        {
            if (response.Action == CoinbaseAction.Delete)
            {
                foreach (var bookLevel in response.Data)
                {
                    RemoveBook(bookLevel);
                }
            }

            if (response.Action == CoinbaseAction.Insert ||
                response.Action == CoinbaseAction.Partial)
            {
                foreach (var bookLevel in response.Data)
                {
                    InsertNewBook(bookLevel);
                }
            }

            if (response.Action == CoinbaseAction.Update)
            {
                foreach (var bookLevel in response.Data)
                {
                    UpdateBook(bookLevel);
                }
            }
        }
Example #14
0
        private bool HandleObjectMessage(string msg)
        {
            // ********************
            // ADD OBJECT HANDLERS BELOW
            // ********************

            return

                (ErrorResponse.TryHandle(msg, Streams.ErrorSubject) ||
                 SubscribeResponse.TryHandle(msg, Streams.SubscribeSubject) ||

                 BookResponse.TryHandle(msg, Streams.BookSubject) ||
                 TradeResponse.TryHandle(msg, Streams.TradesSubject) ||
                 QuoteResponse.TryHandle(msg, Streams.QuoteSubject) ||
                 LiquidationResponse.TryHandle(msg, Streams.LiquidationSubject) ||
                 PositionResponse.TryHandle(msg, Streams.PositionSubject) ||
                 MarginResponse.TryHandle(msg, Streams.MarginSubject) ||
                 OrderResponse.TryHandle(msg, Streams.OrderSubject) ||
                 WalletResponse.TryHandle(msg, Streams.WalletSubject) ||
                 ExecutionResponse.TryHandle(msg, Streams.ExecutionSubject) ||
                 FundingResponse.TryHandle(msg, Streams.FundingsSubject) ||
                 InstrumentResponse.TryHandle(msg, Streams.InstrumentSubject) ||
                 TradeBinResponse.TryHandle(msg, Streams.TradeBinSubject) ||


                 InfoResponse.TryHandle(msg, Streams.InfoSubject) ||
                 AuthenticationResponse.TryHandle(msg, Streams.AuthenticationSubject));
        }
Example #15
0
        public BookResponse Map(Book request)
        {
            if (request == null)
            {
                return(null);
            }

            var response = new BookResponse
            {
                Id             = request.Id,
                Name           = request.Name,
                Description    = request.Description,
                LabelName      = request.LabelName,
                PictureUri     = request.PictureUri,
                ReleaseDate    = request.ReleaseDate,
                Format         = request.Format,
                AvailableStock = request.AvailableStock,
                GenreId        = request.GenreId,
                Genre          = _genreMapper.Map(request.Genre),
                AuthorId       = request.AuthorId,
                Author         = _authorMapper.Map(request.Author),
            };

            if (request.Price != null)
            {
                response.Price = new PriceResponse {
                    Currency = request.Price.Currency, Amount = request.Price.Amount
                };
            }

            return(response);
        }
Example #16
0
 private void AssertBookResponse(BookResponse book, Guid bookId, string bookTitle, string category)
 {
     book.Id.Should().Be(bookId);
     book.Title.Should().Be(bookTitle);
     book.Category.Should().Be(category);
     book.Links.Should().BeEquivalentTo(_links);
 }
Example #17
0
        /// <summary>
        /// Add Book Details into the database
        /// </summary>
        /// <param name="adminID">Admin-ID</param>
        /// <param name="email">Email</param>
        /// <param name="book">Book Data</param>
        /// <returns>If data added successfull return Response Data else nnull or Exception</returns>
        public async Task <BookResponse> AddBook(int adminID, BookRequest bookDetails)
        {
            try
            {
                BookResponse responseData = null;
                SQLConnection();
                using (SqlCommand cmd = new SqlCommand("AddBookDetails", conn))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@AdminID", adminID);
                    cmd.Parameters.AddWithValue("@Name", bookDetails.Name);
                    cmd.Parameters.AddWithValue("@Author", bookDetails.Author);
                    cmd.Parameters.AddWithValue("@Language", bookDetails.Language);
                    cmd.Parameters.AddWithValue("@Category", bookDetails.Category);
                    cmd.Parameters.AddWithValue("@ISBN", bookDetails.ISBN);
                    cmd.Parameters.AddWithValue("@Pages", bookDetails.Pages);

                    conn.Open();
                    SqlDataReader dataReader = await cmd.ExecuteReaderAsync();

                    responseData = BookResponseModel(dataReader);
                };
                return(responseData);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Example #18
0
        void HandleScanResultReturn(ZXing.Result result)
        {
            string msg = "";

            if (result != null && !string.IsNullOrEmpty(result.Text))
            {
                msg = "Found Barcode: " + result.Text;
            }
            else
            {
                msg = "Scanning Canceled!";
            }

            this.RunOnUiThread(() => Toast.MakeText(this, msg, ToastLength.Short).Show());
            _QrCode = result.Text;
            BookResponse bookResponse = _RequestSender.SendUpdateCopiesRequest(_QrCode, false, user.UserInfo.Id);


            if (bookResponse != null && bookResponse.WasUpdated)
            {
                foreach (var book in user.BorrowedBooks)
                {
                    if (book.QRCode.ToString() == _QrCode)
                    {
                        user.BorrowedBooks.Remove(book);
                        break;
                    }
                }
                Refresh();
            }
        }
        public async Task <IActionResult> Get(string id)
        {
            BookResponse book = await _bookService.GetBookDetailAsync(id);

            BookDetailModel bookDetailModel = new BookDetailModel().TransformToModel(book);

            return(Ok(bookDetailModel));
        }
Example #20
0
        public ActionResult EditBook(int id)
        {
            BookResponse result = client.GetBook(id.ToString());

            ViewBag.Msg = GlobalVariables.responseMessage;
            GlobalVariables.responseMessage = null;
            return(View(result.book));
        }
        public IActionResult UpdateBookForAuthor(Guid authorId, Guid id,
                                                 [FromBody] BookUpdateRequest book)
        {
            if (book == null)
            {
                return(BadRequest());
            }

            if (book.Description == book.Title)
            {
                ModelState.AddModelError(nameof(BookUpdateRequest),
                                         "The provided description should be different from the title.");
            }

            if (!ModelState.IsValid)
            {
                return(new UnprocessableEntityObjectResult(ModelState));
            }


            if (!_libraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var bookForAuthorFromRepo = _libraryRepository.GetBookForAuthor(authorId, id);

            if (bookForAuthorFromRepo == null)
            {
                var bookToAdd = book.ConvertToBook();
                bookToAdd.Id = id;

                _libraryRepository.AddBookForAuthor(authorId, bookToAdd);

                if (!_libraryRepository.Save())
                {
                    throw new Exception($"Upserting book {id} for author {authorId} failed on save.");
                }

                var bookToReturn = new BookResponse(bookToAdd);

                return(CreatedAtRoute("GetBookForAuthor",
                                      new { authorId = authorId, id = bookToReturn.Id },
                                      bookToReturn));
            }

            bookForAuthorFromRepo.Title       = book.Title;
            bookForAuthorFromRepo.Description = book.Description;

            _libraryRepository.UpdateBookForAuthor(bookForAuthorFromRepo);

            if (!_libraryRepository.Save())
            {
                throw new Exception($"Updating book {id} for author {authorId} failed on save.");
            }

            return(NoContent());
        }
Example #22
0
        public async Task <IHttpActionResult> Create([FromBody] CreateBookRequest createBookRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var author = await _repoWrapper.Author.CreateAsync(new Author()
            {
                FirstName = createBookRequest.AuthorName, LastName = createBookRequest.AuthorLastName
            });

            if (author == null)
            {
                return(BadRequest("No Authors was inputed"));
            }

            var category = await _repoWrapper.Category.GetCategoryByName(createBookRequest.Category);

            if (category == null)
            {
                return(BadRequest("No Category could be found with that name!"));
            }

            var book = new IBooks
            {
                Title        = createBookRequest.Title,
                Descriptions = createBookRequest.Descriptions,
                Published    = createBookRequest.Published,
                PageCount    = createBookRequest.PageCount,
                ISBN         = _repoWrapper.Book.CreateISBN(),
                AuthorId     = author.Id,
                CategoryId   = category.Id
            };

            var created = await _repoWrapper.Book.CreateAsync(book);

            if (!created)
            {
                return(BadRequest("Something went wrong when creating a new book"));
            }

            var response = new BookResponse
            {
                Id           = book.Id,
                ISBN         = book.ISBN,
                Descriptions = book.Descriptions,
                Published    = book.Published,
                PageCount    = book.PageCount,
                Title        = book.Title,
                Author       = $"{author.FirstName} {author.LastName}",
                Category     = category.Name
            };

            return(Json(response));
        }
Example #23
0
        public async Task <IActionResult> UpdateBook(BookResponse book)
        {
            _logger.LogInformation($"Updating book info {@book.BookId}");

            var updatedBook = await _bookService.UpdateBookAsync(book);

            var bookResponse = _mapper.Map <BookResponse>(updatedBook);

            return(Ok(bookResponse));
        }
Example #24
0
        public async Task <IActionResult> AddBook(BookResponse book)
        {
            _logger.LogInformation($"Adding a new book record");

            var newBook = await _bookService.AddBookAsync(book);

            var bookResponse = _mapper.Map <BookResponse>(newBook);

            return(Ok(bookResponse));
        }
Example #25
0
        public async Task <IActionResult> AddBookAsync([FromBody] CreateBookRequest BookRequest)
        {
            (bool succeed, string message, CreateBookResponse BookResponse) = await Mediator.Send(BookRequest);

            if (succeed)
            {
                return(Ok(BookResponse.ToResponse()));
            }
            return(BadRequest(message.ToResponse(false, message)));
        }
        private OrderBookLevelBulk ConvertDiff(BookResponse response)
        {
            var action = ConvertAction(response.Action);
            var bulk   = new OrderBookLevelBulk(action, ConvertLevels(response.Data), CryptoOrderBookType.L2)
            {
                ExchangeName = ExchangeName
            };

            return(bulk);
        }
Example #27
0
        public async Task <ActionResult <BookDetailResource> > DeleteBook(int id)
        {
            BookResponse response = await _BookService.DeleteAsync(id);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }

            BookDetailResource deletedResource = _mapper.Map <BookDetailResource>(response.Book);

            return(Ok(deletedResource));
        }
Example #28
0
        public async Task <IEnumerable <Item> > GetItemsAsync(string query)
        {
            if (!string.IsNullOrEmpty(query) && CrossConnectivity.Current.IsConnected)
            {
                var json = await client.GetStringAsync($"{Utils.Util.SearchUriRequest}/{query}");

                BookResponse response = await Task.Run(() => JsonConvert.DeserializeObject <BookResponse>(json));

                items = response.Books;
            }

            return(items);
        }
Example #29
0
 public ViewResult RegBookForm(BookResponse bookResponse)
 {
     if (ModelState.IsValid)
     {
         Repository.AddResponse(bookResponse);
         return(View("Thanks", bookResponse));
     }
     else
     {
         // Hay un error de validacion y retornamos una vista en blanco.
         return(View());
     }
 }
Example #30
0
        public async Task <ActionResult <BookDetailResource> > GetBook(int id)
        {
            BookResponse response = await _BookService.FindByIdAsync(id);

            if (!response.Success)
            {
                return(NotFound(response.Message));
            }

            BookDetailResource resource = _mapper.Map <BookDetailResource>(response.Book);

            return(Ok(resource));
        }
 public object GetBook()
 {
     var response = new BookResponse();
     return response;
 }