示例#1
0
        public static async Task <SelectList> BuildFilteredSelectListExcludeArchivedAsync <T>(this IBaseArchiveableRepository <T> repository, Func <T, bool> filterExpression, string dataTextField, string dataGroupField = null) where T : class, IArchiveableEntity
        {
            var list = await repository.ListAllNonArchivedAsync();

            SelectList selectListItems = new SelectList(list.Where(filterExpression), nameof(IEntityBase.Id), dataTextField, null, dataGroupField);

            return(selectListItems);
        }
示例#2
0
        private async Task PopulateModels()
        {
            var allSkillsBySkillArea = await _skillService.ListAllNonArchivedSkillsByAreaAndLevel();

            NewViewModel.SkillsByArea = _mapper.Map <Dictionary <SkillAreaViewModel, Dictionary <SkillLevelViewModel, List <ReviewedSkillViewModel> > > >(allSkillsBySkillArea);

            var allSkillEntities = await _skillRepository.ListAllNonArchivedAsync();

            NewViewModel.UserReviewedSkills = _mapper.Map <List <ReviewedSkillViewModel> >(allSkillEntities);

            Users = await _userRepository.BuildSelectListAsync(nameof(Swifty.Core.Entities.User.Email));
        }
示例#3
0
        // Ideally I should use classes for this much nesting and separate the logic into separate functions in future, this is too messy
        private async Task <Dictionary <SkillArea, Dictionary <SkillLevel, List <Skill> > > > GetAllSkillsByAreaAndLevel(bool excludeArchived)
        {
            List <Skill> allSkills = excludeArchived ? await _skillRepository.ListAllNonArchivedAsync() : await _skillRepository.ListAllAsync();

            Dictionary <SkillArea, Dictionary <SkillLevel, List <Skill> > > toReturn = new Dictionary <SkillArea, Dictionary <SkillLevel, List <Skill> > >();

            // Loop through all skills
            foreach (Skill skill in allSkills)
            {
                // If we've already grouped by this area, add to the dictionary using skill area as key
                if (toReturn.ContainsKey(skill.Area))
                {
                    if (!excludeArchived || (!skill.Area.IsArchived && !skill.Level.IsArchived))
                    {
                        // Add to collection based on level key if we have found this level before
                        if (toReturn[skill.Area].ContainsKey(skill.Level))
                        {
                            toReturn[skill.Area][skill.Level].Add(skill);
                        }
                        else
                        {
                            // Instantiate new dictionary if we haven't found this level before
                            toReturn[skill.Area].Add(skill.Level, new List <Skill>()
                            {
                                skill
                            });
                        }
                    }
                }
                else
                {
                    // If we haven't grouped by this area yet, add to the dictionary as a new key
                    if (!excludeArchived || (!skill.Area.IsArchived && !skill.Level.IsArchived))
                    {
                        toReturn.Add(skill.Area,
                                     new Dictionary <SkillLevel, List <Skill> >()
                        {
                            { skill.Level, new List <Skill>()
                              {
                                  skill
                              } }
                        });
                    }
                }
            }

            return(toReturn);
        }