Esempio n. 1
0
        public HoneypotUser GetByUsername(string username)
        {
            HoneypotUser user = this.context
                                .Users
                                .FirstOrDefault(x => x.UserName == username);

            return(user);
        }
Esempio n. 2
0
        private void OnPostUnlikeQuote(Quote quote, HoneypotUser user)
        {
            var quoteToUnlike =
                this.context.UsersQuotes.FirstOrDefault(x => x.QuoteId == quote.Id && x.UserId == user.Id);

            this.context.UsersQuotes.Remove(quoteToUnlike);
            this.context.SaveChanges();
        }
Esempio n. 3
0
 private void ValidateUserBookshelfIdExists(int bookshelfId, HoneypotUser user)
 {
     if (this.bookshelfService.GetUserBookshelfById(bookshelfId, user.Id) == null)
     {
         var errorMessage = string.Format(GeneralConstants.DoesntExist, typeof(Bookshelf).Name);
         ModelState.AddModelError("Bookshelf", errorMessage);
     }
 }
Esempio n. 4
0
 private async Task AddRoleToAccountAsync(HoneypotUser user)
 {
     if (this.context.Users.Count() == 1)
     {
         await this.userManager.AddToRoleAsync(user, Role.Admin);
     }
     else
     {
         await this.userManager.AddToRoleAsync(user, Role.User);
     }
 }
Esempio n. 5
0
        private void AddNewRating(HoneypotUser user, int bookId, StarRating starRating)
        {
            var rating = new Rating()
            {
                Stars  = starRating,
                UserId = user.Id,
                BookId = bookId
            };

            this.context.Ratings.Add(rating);
        }
Esempio n. 6
0
        private void OnPostAddToBookshelf(int bookshelfId, Book book, HoneypotUser user)
        {
            var bookBookshelf = new BookBookshelf()
            {
                BookId      = book.Id,
                Book        = book,
                BookshelfId = bookshelfId
            };

            user.CustomBookshelves.First(x => x.Id == bookshelfId).Books.Add(bookBookshelf);
            this.context.SaveChanges();
        }
Esempio n. 7
0
        protected HoneypotUser CreateUserData()
        {
            var user = new HoneypotUser()
            {
                UserName = TestsConstants.Username,
                Id       = TestsConstants.UserId
            };

            this.context.Users.Add(user);
            this.context.SaveChanges();
            return(user);
        }
Esempio n. 8
0
        private void OnPostLikeQuote(Quote quote, HoneypotUser user)
        {
            var userQuote = new UserQuote()
            {
                QuoteId = quote.Id,
                UserId  = user.Id
            };

            this.context.UsersQuotes.Add(userQuote);
            user.LikedQuotes.Add(userQuote);
            quote.LikedByUsers.Add(userQuote);
            this.context.SaveChanges();
        }
Esempio n. 9
0
        protected Rating CreateRatingData(HoneypotUser user, Book book)
        {
            Rating rating = new Rating()
            {
                UserId = user.Id,
                BookId = book.Id,
                Stars  = StarRating.Awesome
            };

            this.context.Ratings.Add(rating);
            this.context.SaveChanges();
            return(rating);
        }
Esempio n. 10
0
        protected UserQuote CreateUserQuoteData(HoneypotUser user, Quote quote)
        {
            var userQuote = new UserQuote()
            {
                UserId  = user.Id,
                QuoteId = quote.Id
            };

            user.LikedQuotes.Add(userQuote);
            this.context.UsersQuotes.Add(userQuote);
            this.context.SaveChanges();
            return(userQuote);
        }
Esempio n. 11
0
        protected Bookshelf CreateBookshelfData(HoneypotUser user)
        {
            var bookshelf = new Bookshelf()
            {
                Title  = TestsConstants.Title1,
                UserId = user.Id,
                Id     = TestsConstants.Id2
            };

            this.context.Bookshelves.Add(bookshelf);
            this.context.SaveChanges();
            return(bookshelf);
        }
Esempio n. 12
0
        public List <Quote> GetLikedQuotesByUser(HoneypotUser user)
        {
            var likedQuotesByUser = this.context
                                    .UsersQuotes
                                    .Include(x => x.Quote)
                                    .ThenInclude(x => x.Book)
                                    .ThenInclude(x => x.Author)
                                    .Where(x => x.User == user)
                                    .ToList()
                                    .ConvertAll(x => x.Quote);

            return(likedQuotesByUser);
        }
Esempio n. 13
0
 //INPUT DATA VALIDATION METHODS
 private void ValidateAddToBookshelf(int bookshelfId, int bookId, Book bookResult, HoneypotUser user)
 {
     ValidateBookExists(bookResult);
     ValidateUserBookshelfIdExists(bookshelfId, user);
     ValidateBookIsntInBookshelf(bookId, bookshelfId);
 }
Esempio n. 14
0
        private void ChangeRating(HoneypotUser user, int bookId, StarRating starRating)
        {
            var rating = this.ratingService.GetUserBookRating(user.Id, bookId);

            rating.Stars = starRating;
        }