コード例 #1
0
        public async Task <CategoryListDTO> GetCategoryById(int CategoryId)
        {
            var category = await _repositoryCategory.GetByIdAsync(CategoryId);

            var dTO = new CategoryListDTO
            {
                Description = category.Description,
                Name        = category.Name,
                ParentId    = category.ParentId,
                Id          = category.Id
            };

            return(dTO);
        }
コード例 #2
0
        public async Task <IActionResult> List()
        {
            var currentUser = await GetCurrentUserAsync();

            var categories = uow.Categories.Find(k => k.ApplicationUser == currentUser);
            var viewmodel  = new List <CategoryListDTO>();

            foreach (var item in categories)
            {
                var model = new CategoryListDTO();
                model.CategoryId   = item.CategoryId;
                model.CategoryName = item.CategoryName;

                model.LearnedCount = uow.WordStatistics.GetAll()
                                     .Include(i => i.Word)
                                     .ThenInclude(i => i.WordCategories)
                                     .ThenInclude(i => i.Category)
                                     .Where(s => s.Word.WordCategories.Any(a => a.CategoryId == item.CategoryId) && s.IsLearned == true).Count();

                model.TotalCount = uow.WordStatistics.GetAll()
                                   .Include(i => i.Word)
                                   .ThenInclude(i => i.WordCategories)
                                   .ThenInclude(i => i.Category)
                                   .Where(s => s.Word.WordCategories.Any(a => a.CategoryId == item.CategoryId)).Count();

                if (model.TotalCount > 0)
                {
                    model.Percentage = (int)(((Double)model.LearnedCount / (Double)model.TotalCount) * 100);
                }
                else
                {
                    model.Percentage = 100;
                }

                viewmodel.Add(model);
            }
            return(View(viewmodel));
        }