Пример #1
0
        public async Task <List <TownItem> > ListForUser(ClaimsPrincipal user, ISpecification <TownItem> specification)
        {
            var vUser = await _userManager.GetUserAsync(user);

            if (vUser == null)
            {
                return(new List <TownItem>());
            }
            if (await _userManager.IsInRoleAsync(vUser, "TownManager"))
            {
                var townId = vUser.TownId;
                if (townId != null)
                {
                    return(new List <TownItem>()
                    {
                        await _townRepository.GetByIdEagerAsync(townId.Value)
                    }.Where(specification.Criteria.Compile()).ToList());
                }
            }
            else
            {
                return((await _townRepository.ListAllEagerAsync()).Where(specification.Criteria.Compile()).ToList());;
            }
            return(new List <TownItem>());
        }
Пример #2
0
        public async Task <IActionResult> OnGetAsync(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var town = await _townRepository.GetByIdEagerAsync(id.Value);

            if (town == null)
            {
                return(NotFound());
            }
            TownItem    = new TownDetailViewModel(town);
            GlobalFiles = (await _userFileService.GetGlobalUserFilesAsync()).Select(t => new UserFileListViewModel(t)).ToList();
            UserFiles   = (await _userFileService.GetUserFilesForTownAsync(id.Value)).Select(t => new UserFileListViewModel(t)).ToList();

            return(Page());
        }