コード例 #1
0
        public async Task <JsonResult> GetUserBookPropertiesAsync(string isbn, [FromServices] IUserBooksLogic booksLogic)
        {
            var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            var properties = await booksLogic.GetUserBookPropertiesAsync(userId, isbn);

            var propertiesViewModel = new UserBookPropertiesViewModel();

            if (properties != null)
            {
                var bookHistory = new List <BookHistoryViewModel>();
                if (properties.UserBookHistory != null)
                {
                    foreach (var historyItem in properties.UserBookHistory)
                    {
                        bookHistory.Add(new BookHistoryViewModel()
                        {
                            StartDate = historyItem.StartDate,
                            EndDate   = historyItem.EndDate
                        });
                    }
                }

                propertiesViewModel.BookHistory = bookHistory;

                propertiesViewModel.IsBookToRead       = properties.UserBookToRead != null;
                propertiesViewModel.IsCurrentlyReading = properties.UserBookReading != null;
                propertiesViewModel.IsInBookshelf      = properties.UserBookshelf != null && properties.UserBookshelf.IsInterested == false;
                propertiesViewModel.IsInterested       = properties?.UserBookshelf?.IsInterested ?? false;
            }
            ;

            return(Json(propertiesViewModel));
        }
コード例 #2
0
        public async Task UpdateBookPropertiesAsync(BookSearchResultViewModel book, UserBookPropertiesViewModel properties, [FromServices] IBookPropertiesLogic bookLogic)
        {
            try
            {
                var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

                var bookToSave = new BookSearchResult();
                bookToSave.Title         = book.Title;
                bookToSave.Description   = book.Description;
                bookToSave.CoverImageUrl = book.CoverImageUrl;
                bookToSave.Rating        = ParseExtensions.TryParseDouble(book.Rating);
                bookToSave.RatingCount   = ParseExtensions.TryParseInt(book.RatingCount, 0).Value;
                bookToSave.PublishedDate = ParseExtensions.TryParseDateTime(book.PublishedDate);
                bookToSave.PageCount     = ParseExtensions.TryParseInt(book.PageCount);
                bookToSave.Isbn          = book.Isbn;

                if (book.Authors != null)
                {
                    bookToSave.Authors = book.Authors.Split(",");
                }

                if (book.Genres != null)
                {
                    bookToSave.Genres = book.Genres.Split(",");
                }

                await bookLogic.UpdateBookProperties(userId, bookToSave, properties.IsCurrentlyReading, properties.IsBookToRead, properties.IsInBookshelf, properties.IsInterested);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Unable to update book properties.");

                Response.StatusCode = 500;
            }
        }