public bool SelectUserCards(UserCardViewModel userCardVm) { if (AnyCardsSelected(userCardVm.userId, userCardVm.gameId)) { return(true); } foreach (var cardId in userCardVm.cardIds) { try { var userCardToSelect = _context.UserCards.Single(userCard => userCard.CardId == cardId && userCard.GameId == userCardVm.gameId && userCard.UserId == userCardVm.userId); userCardToSelect.Selected = true; _context.SaveChanges(); } catch (Exception) { return(false); } } return(true); }
public UserHandDto GetUserCards(UserCardViewModel userCardVm) { var cardsInHand = new UserHandDto(); var whiteCards = GetWhiteCards(userCardVm.userId, userCardVm.gameId); if (whiteCards.Any()) { cardsInHand.whiteCards = whiteCards; cardsInHand.blackCard = GetBlackCard(userCardVm.gameId); return(cardsInHand); } var takenCards = GetTakenCards(userCardVm.gameId) .IgnoreQueryFilters() .Select(userCard => userCard.CardId) .ToList(); cardsInHand.whiteCards = GetNewWhiteCards(takenCards, userCardVm.gameId, userCardVm.userId); if (IsUserTurn(userCardVm.userId, userCardVm.gameId)) { cardsInHand.blackCard = GetNewBlackCard(userCardVm, takenCards); } else { cardsInHand.blackCard = GetBlackCard(userCardVm.gameId); } return(cardsInHand); }
public async Task <UserCardViewModel> GetUserCardAsync(string cardToken) { if (string.IsNullOrEmpty(cardToken)) { return(null); } var user = await _userManager.FindByCardTokenAsync(cardToken); if (user == null) { return(null); } var res = new UserCardViewModel() { UserId = user.Id, UserName = user.NameSurname, // UserChildName = user.ChildNameSurname, UserLogin = user.UserName, UserEmail = user.Email, CardToken = user.CardTag, // PictureId = user.PictureId }; return(res); }
public IEnumerable <UserCard> GrabNewUserCards(UserCardViewModel userCardVm) { var usedCards = GetTakenCards(userCardVm.gameId).IgnoreQueryFilters().Select(usedCard => usedCard.CardId).ToList(); var numOfCardsToDraw = HAND_LIMIT - GetTakenCards(userCardVm.gameId) .Include(uCard => uCard.Card) .Where(uCard => uCard.Card.TypeId == GetWhiteType().Id) .Count(usedCard => usedCard.UserId == userCardVm.userId); return(GetNewWhiteCards(usedCards, userCardVm.gameId, userCardVm.userId, numOfCardsToDraw)); }
public List <UserCard> GetSelectedCards(UserCardViewModel userCardVm) { var selectedCards = _context.UserCards.Where(uCard => uCard.GameId == userCardVm.gameId) .Include(uCard => uCard.Card) .Include(uCard => uCard.User) .Where(uCard => uCard.Selected) .ToList(); return(selectedCards); }
public IViewComponentResult Invoke(GetPublicUserModel userModel, string imageDataUrl) { var model = new UserCardViewModel { User = userModel, ImageDataUrl = imageDataUrl }; return(View(model)); }
public async Task <IActionResult> RemoveVisit(UserCardViewModel inputModel) { if (this.cardsService.HasCardVisits(inputModel.Id) == false) { return(this.Redirect($"/Administration/Cards/UserCard?noVisits=true&userId={inputModel.UserId}")); } await this.cardsService.RemoveVisitFromCard(inputModel.Id); return(this.Redirect($"/Administration/Cards/RemoveSuccess?userId={inputModel.UserId}")); }
public QuestionItemViewModel(Question question) { Question = question; Title = question.DecodedTitle; Tags = question.Tags.ToListViewModel(); User = new UserCardViewModel(question); score = question.Score; answers = question.AnswerCount; views = question.ViewCount; HasAGoodAnswer = question.IsAnswered; HasAnAcceptedAnswer = question.AcceptedAnswerId.HasValue; }
public void Test_Formats_Reputation(int reputation, string expected) { Subject = new UserCardViewModel(new Question() { Owner = new ShallowUser() { DisplayName = "Name", Reputation = reputation } }); Assert.Equal(expected, Subject.Reputation); }
public void Test_Handles_Users_With_Empty_Image_URLs() { Subject = new UserCardViewModel(new Question() { Owner = new ShallowUser() { DisplayName = "Name", Link = "https://www.example.com", ProfileImage = "", Reputation = 0, UserId = 1 } }); Assert.Null(Subject.ImageUrl); }
public UserCard GetNewBlackCard(UserCardViewModel userCardVm, List <int> usedCards) { var drawnBlackCardId = DrawNewBlackCard(usedCards); var drawnBlackCard = new UserCard { UserId = userCardVm.userId, GameId = userCardVm.gameId, CardId = drawnBlackCardId }; _context.UserCards.Add(drawnBlackCard); _context.SaveChanges(); return(GetBlackCard(userCardVm.gameId)); }
public async Task <IActionResult> AddVisits(UserCardViewModel inputModel) { if (inputModel.Visits != 12 && inputModel.Visits != 16 && inputModel.Visits != 20 && inputModel.Visits != 30) { return(this.Redirect("/Administration/Cards/UserCard")); } if (this.cardsService.HasCardVisits(inputModel.Id)) { return(this.Redirect($"/Administration/Cards/UserCard?hasVisits=true&userId={inputModel.UserId}")); } await this.cardsService.AddVisitsToUser(inputModel.UserId, inputModel.Visits); return(this.Redirect($"/Administration/Cards/AddSuccess?userId={inputModel.UserId}")); }
public int SoftDeleteUserCards(UserCardViewModel userCardVm) { foreach (var cardId in userCardVm.cardIds) { try { var userCardToSelect = _context.UserCards.Single(userCard => userCard.CardId == cardId && userCard.GameId == userCardVm.gameId && userCard.UserId == userCardVm.userId); userCardToSelect.DeletedAt = DateTime.Now; _context.SaveChanges(); } catch (Exception) { return(-1); } } return(1); }
public CommentViewModel(Comment comment) { Score = comment.Score.ToString(); Poster = new UserCardViewModel(comment); var paragraph = (Paragraph)HtmlHelper.ConvertHtmlToBlocks(comment.Body); paragraph.Inlines.Add(new Run() { Text = " - " }); paragraph.Inlines.Add(new Bold() { Inlines = { new Run() { Text = Poster.Owner } } }); Body = paragraph; }
public UserHandDto SetupNextRound(UserCardViewModel userCardVm) { var nextRoundBlackCard = new UserHandDto(); var result = SoftDeleteUserCards(userCardVm); if (result < 0) { return(nextRoundBlackCard); } var gameUsers = _context.GameUsers.Where(gUser => gUser.GameId == userCardVm.gameId) .Include(gUser => gUser.User) .OrderBy(gUser => gUser.User.Email) .ToList(); var turnIdx = gameUsers.FindIndex(gUser => gUser.IsTurn); gameUsers[turnIdx].IsTurn = false; _context.SaveChanges(); turnIdx = turnIdx == gameUsers.Count() - 1 ? 0 : ++turnIdx; gameUsers[turnIdx].IsTurn = true; _context.SaveChanges(); userCardVm.userId = gameUsers[turnIdx].UserId; var takenBlackCards = GetTakenCards(userCardVm.gameId) .IgnoreQueryFilters() .Include(uCard => uCard.Card) .Where(uCard => uCard.Card.TypeId == GetBlackType().Id) .Select(userCard => userCard.CardId) .ToList(); nextRoundBlackCard.blackCard = GetNewBlackCard(userCardVm, takenBlackCards); return(nextRoundBlackCard); }
public UserHandDto Get([FromQuery] UserCardViewModel userCardVm) { return(_userCardDal.GetUserCards(userCardVm)); }
public List <UserCard> GetSelectedCards([FromQuery] UserCardViewModel userCardVm) { return(_userCardDal.GetSelectedCards(userCardVm)); }
public ActionResult <bool> AnyCardsSelected([FromQuery] UserCardViewModel userCardVm) { return(_userCardDal.AnyCardsSelected(userCardVm.userId, userCardVm.gameId)); }
public ActionResult <bool> SelectCards([FromBody] UserCardViewModel userCardVm) { return(_userCardDal.SelectUserCards(userCardVm)); }
public IEnumerable <UserCard> DeleteCards([FromBody] UserCardViewModel userCardVm) { var cardsDeleted = _userCardDal.SoftDeleteUserCards(userCardVm); return(cardsDeleted == 1 ? _userCardDal.GrabNewUserCards(userCardVm) : new List <UserCard>()); }
public UserHandDto SetupNextRound([FromBody] UserCardViewModel userCardVm) { return(_userCardDal.SetupNextRound(userCardVm)); }
public UserCard GetBlackCard([FromQuery] UserCardViewModel userCardVm) { return(_userCardDal.GetBlackCard(userCardVm.gameId)); }