예제 #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "countrylist/{country}")]
            HttpRequest req, ILogger log, string country)
        {
            string        requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            string        input       = country.ToUpper();
            List <string> path        = null;

            log.LogInformation("C# HTTP trigger function processed a request.");

            // This computes the path and catches the two main error cases
            try
            {
                path = CountrySearch.shortestPath(input);
            }
            catch (KeyNotFoundException)
            {
                log.LogInformation($"Key {input} not contained in the map.");
                return(new BadRequestObjectResult($"The destination {input} is not contained in North America"));
            }
            if (path.Count == 0)
            {
                log.LogInformation($"No path from USA to {input} found in the map.");
                return(new BadRequestObjectResult($"No path from USA to {input} found in the map"));
            }

            // format and return succesful response
            PathResponse okPathResponce = new PathResponse {
                Start = "USA", Destination = input, Path = path
            };
            var okJsonResponse = JsonConvert.SerializeObject(okPathResponce);

            return(new JsonResult(okPathResponce));
        }
        public PagedResponse <CountryDto> Execute(CountrySearch search)
        {
            var query = context.Countries.AsQueryable();

            if (!string.IsNullOrEmpty(search.Name) || !string.IsNullOrWhiteSpace(search.Name))
            {
                query = query.Where(x => x.Name.ToLower().Contains(search.Name.ToLower()));
            }

            return(query.Paged <CountryDto, Domain.Entities.Country>(search, mapper));
        }
예제 #3
0
        public IActionResult Search([FromBody] CountrySearch model)
        {
            CountryListResult result = this.countryService.Search(model.Keywords, model.OrderBy, model.PageNo, model.PageSize, model.BlockSize);

            return(Ok(result));
        }
 public IActionResult Get(
     [FromQuery] CountrySearch search, [FromServices] IGetCountriesQuery query)
 {
     return(Ok(executor.ExecuteQuery(query, search)));
 }
예제 #5
0
        public override async Task <Tuple <List <Model.Response.Country>, int> > GetByParametersAsync(CountrySearch search, string order, string nameOfColumnOrder, int start, int length)
        {
            var query = ctx.Countries.AsQueryable();

            if (!string.IsNullOrWhiteSpace(search.Name))
            {
                query = query.Where(x => x.Name.Contains(search.Name, StringComparison.CurrentCultureIgnoreCase));
            }
            if (!string.IsNullOrWhiteSpace(search.ShortName))
            {
                query = query.Where(x => x.ShortName.Contains(search.ShortName, StringComparison.CurrentCultureIgnoreCase));
            }
            if (!string.IsNullOrWhiteSpace(search.PhoneCode))
            {
                query = query.Where(x => x.PhoneNumberCode == search.PhoneCode);
            }
            if (search.Active != null)
            {
                query = query.Where(x => x.Active == search.Active);
            }

            if (nameof(Database.Country.Name) == nameOfColumnOrder)
            {
                query = query.OrderByAscDesc(x => x.Name, order);
            }
            else if (nameof(Database.Country.ShortName) == nameOfColumnOrder)
            {
                query = query.OrderByAscDesc(x => x.ShortName, order);
            }
            else if (nameof(Database.Country.PhoneNumberCode) == nameOfColumnOrder)
            {
                query = query.OrderByAscDesc(x => x.PhoneNumberCode, order);
            }
            else if (nameof(Database.Country.ID) == nameOfColumnOrder)
            {
                query = query.OrderByAscDesc(x => x.ID, order);
            }

            var count = await query.CountAsync();

            query = query.Skip(start).Take(length);
            return(new Tuple <List <Model.Response.Country>, int>(mapper.Map <List <Model.Response.Country> >(await query.ToListAsync()), count));
        }