Ejemplo n.º 1
0
        public IHttpActionResult GetUserByUserId()
        {
            UserProfileService userProfileService = CreateUserProfileService();
            UserProfileDisplay profileDisplay     = userProfileService.GetUserByUserId();

            return(Ok(profileDisplay));
        }
Ejemplo n.º 2
0
        //User Profile Methods
        public async Task <UserProfileDisplay> GetUserProfile()
        {
            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", $"{AccessToken}");
            HttpResponseMessage response = _client.GetAsync($"https://localhost:44388/api/GetsUserByUserId").Result;

            if (response.IsSuccessStatusCode)
            {
                UserProfileDisplay profile = await response.Content.ReadAsAsync <UserProfileDisplay>();

                return(profile);
            }
            return(null);
        }
Ejemplo n.º 3
0
        public UserProfileDisplay GetUserByUserId()
        {
            UserProfile profileToGet = _context.UserProfiles.SingleOrDefault(u => u.OwnerId == _userId);

            if (profileToGet == default)
            {
                return(null);
            }
            UserProfileDisplay profileDisplay = new UserProfileDisplay()
            {
                UserProfileId = profileToGet.UserProfileId,
                UserName      = profileToGet.UserName,
                BooksToRead   = profileToGet.BooksToRead.Select(b => new BookToReadDisplay
                {
                    BookId = b.BookId,
                    Title  = b.Title
                }).ToList(),

                Bookshelves = profileToGet.Bookshelves.Select(bs => new BookshelfDisplay
                {
                    BookshelfId = bs.BookshelfId,
                    Title       = bs.Title,
                    Books       = bs.Books.Select(b => new BookshelfBookDisplay
                    {
                        BookId = b.BookId,
                        Title  = b.Title
                    }).ToList()
                }).ToList(),

                BookReviews = profileToGet.BookReviews.Select(br => new UserProfileBookReviewDisplay
                {
                    ReviewId   = br.ReviewId,
                    BookId     = br.BookId,
                    BookTitle  = br.Book.Title,
                    BookRating = br.BookRating,
                    ReviewText = br.ReviewText
                }).ToList()
            };

            return(profileDisplay);
        }
Ejemplo n.º 4
0
        //User logs in with email and password, method generates a new authorization token that is stored in the
        // BookLoverService AccessToken property and can then be used for other requests
        public void LogIn()
        {
            Console.WriteLine("Welcome to the BookLover API, please enter your " +
                              "email and password to log in.\n");
            Console.Write("Email: ");
            string email = Console.ReadLine();

            Console.Write("\nPassword: "******"Here's your token: {token}");
            Service.AccessToken = token;
            UserProfileDisplay profile = Service.GetUserProfile().Result;

            if (profile == null)
            {
                Console.WriteLine("Warning, no profile exists for this user.");
                Console.WriteLine("Please enter desired username for profile: ");
                string     userName   = Console.ReadLine();
                List <int> bookIds    = new List <int>();
                bool       keepAdding = true;
                while (keepAdding)
                {
                    Console.Write("Enter Book Id number to add to your To Read List or enter 0 to continue: ");
                    int id = int.Parse(Console.ReadLine());
                    if (id == 0)
                    {
                        keepAdding = false;
                    }
                    bookIds.Add(id);
                }
                string profileAdded = Service.AddUserProfile(userName, bookIds).Result;
                Console.WriteLine(profileAdded);
            }


            Console.ReadKey();
        }
Ejemplo n.º 5
0
        public UserProfileDisplay GetUserById(int id)
        {
            UserProfile        profileToGet   = _context.UserProfiles.Single(u => u.UserProfileId == id);
            UserProfileDisplay profileDisplay = new UserProfileDisplay()
            {
                UserProfileId = profileToGet.UserProfileId,
                UserName      = profileToGet.UserName,
                BooksToRead   = profileToGet.BooksToRead.Select(b => new BookToReadDisplay
                {
                    BookId = b.BookId,
                    Title  = b.Title
                }).ToList(),

                Bookshelves = profileToGet.Bookshelves.Select(bs => new BookshelfDisplay
                {
                    BookshelfId = bs.BookshelfId,
                    Title       = bs.Title,
                    Books       = bs.Books.Select(b => new BookshelfBookDisplay
                    {
                        BookId = b.BookId,
                        Title  = b.Title
                    }).ToList()
                }).ToList(),

                BookReviews = profileToGet.BookReviews.Select(br => new UserProfileBookReviewDisplay
                {
                    ReviewId   = br.ReviewId,
                    BookId     = br.BookId,
                    BookTitle  = br.Book.Title,
                    BookRating = br.BookRating,
                    ReviewText = br.ReviewText
                }).ToList()
            };

            return(profileDisplay);
        }