public async Task <IActionResult> Create() { try { var citiesDTO = await _cityAccessService.GetCitiesAsync(User); var city = _mapper.Map <CityDTOs.CityDTO, CityVMs.CityViewModel>(citiesDTO.First()); return(View("CreateEdit", await GetCreateEditViewModel(city, AnnualReportOperation.Creating))); } catch (InvalidOperationException e) { ViewData["ErrorMessage"] = e.Message; return(View("CreateEdit")); } catch (Exception e) { _loggerService.LogError($"Exception: {e.Message}"); return(RedirectToAction("HandleError", "Error", new { code = StatusCodes.Status500InternalServerError })); } }
///<inheritdoc/> public async Task <IEnumerable <AnnualReportDTO> > GetAllAsync(User user) { var annualReports = await _repositoryWrapper.AnnualReports.GetAllAsync( include : source => source .Include(ar => ar.Creator) .Include(ar => ar.City) .ThenInclude(c => c.Region)); var citiesDTO = await _cityAccessService.GetCitiesAsync(user); var filteredAnnualReports = annualReports.Where(ar => citiesDTO.Any(c => c.ID == ar.CityId)); return(_mapper.Map <IEnumerable <AnnualReport>, IEnumerable <AnnualReportDTO> >(filteredAnnualReports)); }
public async Task GetCitiesAsyncAdmin() { // Arrange _userManager.Setup(u => u.GetUserAsync(It.IsAny <ClaimsPrincipal>())) .ReturnsAsync(new User()); _userManager.Setup(u => u.GetRolesAsync(It.IsAny <User>())) .ReturnsAsync(new List <string> { AdminRoleName }); _repositoryWrapper.Setup(r => r.City.GetAllAsync(null, null)) .ReturnsAsync(new List <DatabaseEntities.City> { new DatabaseEntities.City() }); // Act await _cityAccessService.GetCitiesAsync(new User()); // Assert _mapper.Verify(m => m.Map <IEnumerable <DatabaseEntities.City>, IEnumerable <CityDTO> >(It.IsAny <IEnumerable <DatabaseEntities.City> >())); }
public async Task <IActionResult> GetCitiesThatUserHasAccessTo() { return(Ok(new { cities = await _cityAccessService.GetCitiesAsync(User) })); }