示例#1
0
 public Card(SearchDeckCards.SearchResultCard card, IStringLocalizer <DecksController> localizer, string currentUser)
 {
     CardId                  = card.CardId;
     FrontSide               = card.FrontSide;
     Tags                    = card.Tags;
     Heap                    = DisplayServices.HeapName(card.Heap, localizer);
     ExpiryUtcDate           = card.ExpiryUtcDate;
     Expired                 = card.Expired;
     NbTimesInNotLearnedHeap = card.NbTimesInNotLearnedHeap;
     BiggestHeapReached      = card.BiggestHeapReached;
     LastLearnUtcDate        = card.LastLearnUtcDate;
     AddToDeckUtcTime        = card.AddToDeckUtcTime;
     RemoveAlertMessage      = localizer["RemoveAlertMessage"] + " " + Heap + "\n" + localizer["DateAddedToDeck"] + " ";
     VisibleToCount          = card.VisibleTo.Count();
     if (VisibleToCount == 1)
     {
         var visibleToUser = card.VisibleTo.First();
         if (visibleToUser != currentUser)
         {
             throw new ApplicationException($"Card visible to single user should be current user, is {visibleToUser}");
         }
         VisibleTo = localizer["YouOnly"].ToString();
     }
     else
     {
         if (VisibleToCount == 0)
         {
             VisibleTo = localizer["AllUsers"].ToString();
         }
         else
         {
             VisibleTo = string.Join(',', card.VisibleTo);
         }
     }
 }
示例#2
0
 public GetCardsCardViewModel(GetCardsToLearn.ResultCard applicationResult, IStringLocalizer localizer, string currentUser)
 {
     CardId                  = applicationResult.CardId;
     HeapId                  = applicationResult.Heap;
     Heap                    = DisplayServices.HeapName(applicationResult.Heap, localizer);
     LastLearnUtcTime        = applicationResult.LastLearnUtcTime;
     LastChangeUtcTime       = applicationResult.LastChangeUtcTime;
     BiggestHeapReached      = applicationResult.BiggestHeapReached;
     NbTimesInNotLearnedHeap = applicationResult.NbTimesInNotLearnedHeap;
     FrontSide               = RenderMarkdown(applicationResult.FrontSide);
     BackSide                = RenderMarkdown(applicationResult.BackSide);
     AdditionalInfo          = RenderMarkdown(applicationResult.AdditionalInfo);
     Owner                   = applicationResult.Owner;
     Tags                    = applicationResult.Tags.OrderBy(tag => tag);
     RemoveAlertMessage      = localizer["RemoveAlertMessage"] + " " + Heap + "\n" + localizer["DateAddedToDeck"] + " ";
     VisibleToCount          = applicationResult.VisibleTo.Count();
     AddToDeckUtcTime        = applicationResult.AddToDeckUtcTime;
     CurrentUserRating       = applicationResult.UserRating;
     AverageRating           = Math.Round(applicationResult.AverageRating, 1);
     CountOfUserRatings      = applicationResult.CountOfUserRatings;
     if (VisibleToCount == 1)
     {
         var visibleToUser = applicationResult.VisibleTo.First();
         if (visibleToUser != currentUser)
         {
             throw new ApplicationException($"Card visible to single user should be current user, is {visibleToUser}");
         }
         VisibleTo = localizer["YouOnly"].ToString();
     }
     else
     {
         if (VisibleToCount == 0)
         {
             VisibleTo = localizer["AllUsers"].ToString();
         }
         else
         {
             VisibleTo = string.Join(',', applicationResult.VisibleTo);
         }
     }
     Images            = applicationResult.Images.Select(applicationImage => new GetCardsImageViewModel(applicationImage, localizer));
     MoveToHeapTargets = applicationResult.MoveToHeapExpiryInfos.Select(moveToHeapInfo =>
                                                                        new GetCardsHeapModel(moveToHeapInfo.HeapId, DisplayServices.HeapName(moveToHeapInfo.HeapId, localizer), moveToHeapInfo.UtcExpiryDate, localizer)
                                                                        ).OrderBy(heapModel => heapModel.HeapId);
     RegisteredForNotifications = applicationResult.RegisteredForNotifications;
 }
示例#3
0
            public RunQueryCardViewModel(SearchCards.ResultCard card, string?currentUser, IStringLocalizer <SearchController> localizer, IStringLocalizer <DecksController> decksControllerLocalizer)
            {
                CardId             = card.CardId;
                FrontSide          = card.FrontSide;
                Tags               = card.Tags.OrderBy(tag => tag);
                VisibleToCount     = card.VisibleTo.Count();
                AverageRating      = card.AverageRating;
                CurrentUserRating  = card.CurrentUserRating;
                CountOfUserRatings = card.CountOfUserRatings;
                PopoverVisibility  = localizer["Visibility"].Value;
                if (VisibleToCount == 1)
                {
                    var visibleToUser = card.VisibleTo.First();
                    if (visibleToUser != currentUser)
                    {
                        throw new ApplicationException($"Card visible to single user should be current user, is {visibleToUser}");
                    }
                    PopoverVisibility = localizer["YouOnly"].ToString();
                }
                else
                {
                    if (VisibleToCount == 0)
                    {
                        PopoverVisibility = localizer["AllUsers"].ToString();
                    }
                    else
                    {
                        PopoverVisibility = string.Join(',', card.VisibleTo);
                    }
                }

                Decks = card.DeckInfo.Select(deckInfo =>
                                             new RunQueryCardDeckViewModel(
                                                 deckInfo.DeckId,
                                                 deckInfo.DeckName,
                                                 deckInfo.CurrentHeap,
                                                 DisplayServices.HeapName(deckInfo.CurrentHeap, decksControllerLocalizer),
                                                 deckInfo.NbTimesInNotLearnedHeap,
                                                 DisplayServices.HeapName(deckInfo.BiggestHeapReached, decksControllerLocalizer),
                                                 deckInfo.AddToDeckUtcTime,
                                                 deckInfo.LastLearnUtcTime,
                                                 deckInfo.Expired,
                                                 deckInfo.ExpiryUtcDate));
            }
示例#4
0
 public GetAllStaticDataViewModel(IEnumerable <GetUserDecksWithHeapsAndTags.ResultModel> userDecks, IEnumerable <GetAllAvailableTags.ViewModel> allTags, IEnumerable <GetUsers.ViewModel> allUsers, IStringLocalizer <SearchController> localizer, IStringLocalizer <DecksController> decksControllerLocalizer, MemCheckUser?currentUser)
 {
     UserDecks = new[] { new GetAllStaticDataDeckViewModel(Guid.Empty, localizer["Ignore"].Value) }
     .Concat(userDecks.Select(applicationResult => new GetAllStaticDataDeckViewModel(applicationResult, localizer, decksControllerLocalizer)));
     AllDecksForAddingCards = userDecks.Select(applicationResult => new GetAllStaticDataDeckForAddViewModel(applicationResult.DeckId, applicationResult.Description));
     AllApplicableTags      = allTags.Select(tag => new GetAllStaticDataTagViewModel(tag.TagId, tag.Name));
     AllRequirableTags      = new[] { new GetAllStaticDataTagViewModel(noTagFakeGuid, localizer["None"].Value) }
     .Concat(allTags.Select(tag => new GetAllStaticDataTagViewModel(tag.TagId, tag.Name)));
     AllExcludableTags = new[] {
         new GetAllStaticDataTagViewModel(noTagFakeGuid, localizer["None"].Value),
         new GetAllStaticDataTagViewModel(allTagsFakeGuid, localizer["All"].Value)
     }
     .Concat(allTags.Select(tag => new GetAllStaticDataTagViewModel(tag.TagId, tag.Name)));
     AllUsers = new[] { new GetAllStaticDataUserViewModel(Guid.Empty, localizer["Any"].Value) }
     .Concat(allUsers.Select(user => new GetAllStaticDataUserViewModel(user.UserId, user.UserName)));
     LocalizedText        = new GetAllStaticDataLocalizedTextViewModel(localizer);
     PossibleHeapsForMove = Enumerable.Range(0, MoveCardToHeap.MaxTargetHeapId).Select(heapId => new GetAllStaticDataHeapViewModel(heapId, DisplayServices.HeapName(heapId, decksControllerLocalizer)));
     CurrentUserId        = currentUser == null ? Guid.Empty : currentUser.Id;
     ShowDebugInfo        = DisplayServices.ShowDebugInfo(currentUser);
 }
示例#5
0
        public IActionResult GetHeapsOfDeck(Guid deckId)
        {
            var applicationResult = new GetHeapsOfDeck(dbContext).Run(deckId);

            return(base.Ok(applicationResult.OrderBy(heapId => heapId).Select(heapId => new GetHeapsOfDeckViewModel(heapId, DisplayServices.HeapName(heapId, localizer)))));
        }
示例#6
0
 public GetUserDecksWithHeapsViewModel(Guid deckId, string description, string heapingAlgorithmName, string heapingAlgorithmDescription, int cardCount, IEnumerable <GetUserDecksWithHeaps.ResultHeapModel> heaps, IStringLocalizer <DecksController> localizer)
 {
     DeckId                      = deckId;
     Description                 = description;
     HeapingAlgorithmName        = heapingAlgorithmName;
     HeapingAlgorithmDescription = heapingAlgorithmDescription;
     CardCount                   = cardCount;
     Heaps = heaps.Select(heap => new GetUserDecksWithHeapsHeapViewModel(heap.HeapId, DisplayServices.HeapName(heap.HeapId, localizer), heap.TotalCardCount, heap.ExpiredCardCount, heap.NextExpiryUtcDate));
 }
示例#7
0
 public GetAllStaticDataDeckViewModel(GetUserDecksWithHeapsAndTags.ResultModel applicationResult, IStringLocalizer <SearchController> localizer, IStringLocalizer <DecksController> decksControllerLocalizer)
 {
     DeckId   = applicationResult.DeckId;
     DeckName = applicationResult.Description;
     Heaps    = new[] { new GetAllStaticDataHeapViewModel(-1, localizer["Any"].Value) }
     .Concat(applicationResult.Heaps.OrderBy(heap => heap).Select(heap => new GetAllStaticDataHeapViewModel(heap, DisplayServices.HeapName(heap, decksControllerLocalizer))));
     RequirableTags = new[] { new GetAllStaticDataTagViewModel(noTagFakeGuid, localizer["None"].Value) }
     .Concat(applicationResult.Tags.Select(tag => new GetAllStaticDataTagViewModel(tag.TagId, tag.TagName)));
     ExcludableTags = new[] {
         new GetAllStaticDataTagViewModel(noTagFakeGuid, localizer["None"].Value),
         new GetAllStaticDataTagViewModel(allTagsFakeGuid, localizer["All"].Value)
     }
     .Concat(applicationResult.Tags.Select(tag => new GetAllStaticDataTagViewModel(tag.TagId, tag.TagName)));
 }
示例#8
0
        public async Task <IActionResult> UserDecks()
        {
            try
            {
                var user = await userManager.GetUserAsync(HttpContext.User);

                var userId = (user == null) ? Guid.Empty : user.Id;
                var decks  = new GetUserDecksWithTags(dbContext).Run(userId);
                var result = decks.Select(deck => new UserDecksViewModel(deck.DeckId, deck.Description, DisplayServices.ShowDebugInfo(user), deck.Tags, localizer));
                return(base.Ok(result));
            }
            catch (Exception e)
            {
                return(ControllerError.BadRequest(e, this));
            }
        }