/* * make for razor page */ public Task <GetCityByIdOutputDto> GetcityById(int id) { var places = placeRepository.GetQuery() .Include(p => p.City) .Include(p => p.Comments) .Include(p => p.Rates) .Where(p => p.City.Id == id) .ToList(); if (places == null) { throw new KeyNotFoundException("Not found any city with this id"); } var result = new GetCityByIdOutputDto(); result.Name = places.Select(p => p.City.Name).FirstOrDefault(); result.Image = places.Select(p => p.City.Image).FirstOrDefault(); result.Places = places.Select(p => new Place() { Id = p.Id, Description = p.Description, Image = p.Image, Name = p.Name, Comments = p.Comments.Count, AverageRates = p.Rates.Average(x => x.UserRate), Visit = p.Visit }) .ToList(); return(Task.Run(() => result)); }
public async Task OnGet(int id) { City = await cityService.GetcityById(id); }