public PagedResponse <CountryDto> Execute(CountryQuery request) { var query = Context.Countries.AsQueryable(); query = query.Where(c => c.IsDeleted == false); if (request.Name != null) { query = query.Where(c => c.Name.ToLower().Contains(request.Name.ToLower())); } var totalCount = query.Count(); query = query.Skip((request.PageNumber - 1) * request.PerPage).Take(request.PerPage); var pagesCount = (int)Math.Ceiling((double)totalCount / request.PerPage); return(new PagedResponse <CountryDto> { CurrentPage = request.PageNumber, TotalCount = totalCount, PagesCount = pagesCount, Data = query.Select(c => new CountryDto { Id = c.Id, Name = c.Name }) }); }
// GET Country public IHttpActionResult Get([FromUri] CountryQuery request) { var list = CountryService.List(request); var mapped = list.Map <Country, CountryModel>(); // Returns a 200 status with custom headers (paging) return(Page(mapped)); }
public async Task <CountryDto> Query(Guid id) { var query = new CountryQuery { CountryId = id }; var country = await dispatcher.Query <CountryQuery, Country>(query); return(Mapper.Map(country).ToANew <CountryDto>()); }
public ActionResult Index(CountryQuery query) { if (ModelState.IsValid) { return(RedirectToAction("Result", query)); } return(View(query)); }
public async Task <ActionResult> Result(CountryQuery query) { // var result = await _mediator.Send<CountryViewModel>(query); // TODO Use Mediator and depedenacy injection var handler = new CountryHandler(new WorldBankDataService(new DeserializerService())); var result = await handler.Handle(query); return(View(result)); }
public UserController(UserManager <SimpleCustomerAccount, Guid> userManager, IMapper mapper, SendEmailCommand sendEmailCommand, AddressUnitByShortNameQuery addressUnitByShortNameQuery, CountryQuery countryQuery) : base(userManager, mapper) { _userManager = userManager; _mapper = mapper; _sendEmailCommand = sendEmailCommand; _addressUnitByShortNameQuery = addressUnitByShortNameQuery; _countryQuery = countryQuery; }
public async Task <QueryResult <Country> > GetCountries(CountryQuery queryObj) { var result = new QueryResult <Country>(); var query = context.Countries.Include(c => c.Governerates).AsQueryable(); result.TotalItems = await query.CountAsync(); result.Items = query.ApplyPaging(queryObj); return(result); }
/// <summary> /// Search by criteria /// </summary> /// <param name="request">Filter, pagination, sorting parameters</param> /// <returns>Paged result (sorted)</returns> public PagedList <Country> List(CountryQuery request) { var query = base.List(); // Build que query if (!string.IsNullOrWhiteSpace(request.Name)) { query = query.Where(i => i.Name.Contains(request.Name)); } // Apply paging and sorting var result = query.ToPaged(request); return(result); }
public IActionResult Get([FromQuery] CountryQuery query) { try { return(Ok(getCountries.Execute(query))); } catch (Exception e) { return(StatusCode(500, new { Errors = new List <string> { e.Message } })); } }
// GET: Countries public ActionResult Index([FromQuery] CountryQuery query) { try { return(View(executor.ExecuteQuery(getCountries, query))); } catch (EntityNotAllowedException) { return(RedirectToAction("PageNotFound", "Redirections")); } catch (Exception e) { TempData["error"] = e.Message; } return(RedirectToAction("Home", "Index")); }
public async Task Handle_ValidInvoke_CallsLoadCountry() { // Arrange var query = new CountryQuery { Iso2Code = "br" }; var worldBankDataServiceMock = new Mock <IWorldBankDataService>(); worldBankDataServiceMock.Setup(x => x.LoadCountry(query.Iso2Code)).ReturnsAsync(new Models.WorldBank.Country()); var handler = new CountryHandler(worldBankDataServiceMock.Object); // Act await handler.Handle(query); // Asset worldBankDataServiceMock.Verify(x => x.LoadCountry(query.Iso2Code), Times.Exactly(1)); }
public async Task Handle_CountryLoaded_MapsToViewModel() { // Arrange var query = new CountryQuery { Iso2Code = "br" }; var country = new Models.WorldBank.Country { Iso2Code = "br", CapitalCity = "capital city", Name = "My city", Longitude = 34.4545d, Latitude = -3.5658787d, AdminRegion = "Admin region" }; var expectedCountryViewModel = new CountryViewModel { Iso2Code = country.Iso2Code, CapitalCity = country.CapitalCity, AdminRegion = country.AdminRegion, Longitude = country.Longitude, Latitude = country.Latitude, Name = country.Name }; var worldBankDataServiceMock = new Mock <IWorldBankDataService>(); worldBankDataServiceMock.Setup(x => x.LoadCountry(query.Iso2Code)).ReturnsAsync(country); var handler = new CountryHandler(worldBankDataServiceMock.Object); // Act var actualCountryViewModel = await handler.Handle(query); // Assert Assert.IsTrue(expectedCountryViewModel.IsDeepEqual(actualCountryViewModel)); }
public async Task <IEnumerable <CountryDto> > Query() { var query = new CountryQuery(); var countries = await dispatcher.Query <CountryQuery, IEnumerable <Country> >(query); var countryDtos = new List <CountryDto>(); foreach (var country in countries) { var countryDto = new CountryDto { Id = country.Id, Name = country.Name, UserId = country.UserId }; foreach (var province in country.Provinces) { countryDto.Provinces.Add(province.Name); } countryDtos.Add(countryDto); } return(countryDtos); }
public async Task <IEnumerable <Country> > Query(CountryQuery query) { return(await mainDbContext.Country.Include(x => x.Provinces).ToListAsync()); }
public ContinentController(AppDbContext context) { _context = context; countryQuery = new CountryQuery(_context); }
public async Task <QueryResult <CountryResource> > GetCountries(CountryQuery filterResource) { var queryResult = await repository.GetCountries(filterResource); return(mapper.Map <QueryResult <Country>, QueryResult <CountryResource> >(queryResult)); }