public HoneypotUser GetByUsername(string username) { HoneypotUser user = this.context .Users .FirstOrDefault(x => x.UserName == username); return(user); }
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(); }
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); } }
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); } }
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); }
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(); }
protected HoneypotUser CreateUserData() { var user = new HoneypotUser() { UserName = TestsConstants.Username, Id = TestsConstants.UserId }; this.context.Users.Add(user); this.context.SaveChanges(); return(user); }
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(); }
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); }
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); }
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); }
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); }
//INPUT DATA VALIDATION METHODS private void ValidateAddToBookshelf(int bookshelfId, int bookId, Book bookResult, HoneypotUser user) { ValidateBookExists(bookResult); ValidateUserBookshelfIdExists(bookshelfId, user); ValidateBookIsntInBookshelf(bookId, bookshelfId); }
private void ChangeRating(HoneypotUser user, int bookId, StarRating starRating) { var rating = this.ratingService.GetUserBookRating(user.Id, bookId); rating.Stars = starRating; }