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

            return(user);
        }
示例#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();
        }
示例#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);
     }
 }
示例#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);
     }
 }
示例#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);
        }
示例#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();
        }
示例#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);
        }
示例#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();
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
 }
示例#14
0
        private void ChangeRating(HoneypotUser user, int bookId, StarRating starRating)
        {
            var rating = this.ratingService.GetUserBookRating(user.Id, bookId);

            rating.Stars = starRating;
        }