Exemplo n.º 1
0
        public ActionResult <List <VocabularyWithProgressModel> > GetDictionaries()
        {
            var userId       = int.Parse(User.FindFirst(TokenClaims.Id).Value);
            var vocabularies = _vocabularyService.GetByUser(userId);

            if (vocabularies == null)
            {
                return(new List <VocabularyWithProgressModel>());
            }
            var results = new List <VocabularyWithProgressModel>();

            foreach (var item in vocabularies)
            {
                var topics   = _topicService.GetByVocabulary(item.Id);
                var progress = _vocabularyService.GetProgress(userId, item.Id);
                var model    = new VocabularyWithProgressModel
                {
                    Id       = item.Id,
                    LevelId  = item.LevelId,
                    Name     = item.Name,
                    Progress = progress,
                    Topics   = TopicsToModels(topics)
                };
                results.Add(model);
            }

            return(results);
        }