public async Task <IActionResult> OnGetAsync(long?id) { if (id == null) { return(NotFound()); } var group = await _context.Groups.Where(m => m.Id == id) .Include(t => t.Town) .Include(t => t.Vehicles) .Include(t => t.Drivers).ThenInclude(d => d.Vehicles) .Include(t => t.UserFiles) .Include(t => t.SecurityPersons).ThenInclude(s => s.Group) .Include(t => t.SecurityPersons).ThenInclude(s => s.Town) .SingleOrDefaultAsync(); if (group == null) { return(NotFound()); } GroupItem = new GroupViewModel(group); Vehicles = group.Vehicles.Select(t => new VehicleListViewModel(t)).ToList(); Drivers = group.Drivers.Select(t => new DriverListViewModel(t)).ToList(); UserFiles = group.UserFiles.Where(t => t.Status == StatusType.OK && t.Visibility == VisibilityType.CurrentGroup).Select(t => new UserFileListViewModel(t)).ToList(); Securemans = group.SecurityPersons.Select(t => new SecureManListViewModel() { Id = t.Id, Name = t.Name, Address = t.Address, RegisterAddress = t.RegisterAddress, Company = t.Company, GroupName = t.Group?.Name, TownName = t.Town?.Name, IdCardNum = t.IdCardNum, Tel = t.Tel, Title = t.Title, }).ToList(); var gf = (await _userFileService.GetGlobalUserFilesAsync()).Select(t => new UserFileListViewModel(t)).ToList(); var tf = (await _userFileService.GetUserFilesForTownAsync(group.TownId.Value)).Select(t => new UserFileListViewModel(t)).ToList(); GlobalFiles = gf.Union(tf).ToList(); return(Page()); }
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()); }