Exemplo n.º 1
0
        public async Task <IHttpActionResult> Search([FromBody] AddressSearchModel searchdata)
        {
            var queryResult = _context.Addresses.AsQueryable();

            queryResult = queryResult.Where(q => q.State.ToLower() == searchdata.State.ToLower());
            queryResult = queryResult.Where(q => q.City.ToLower() == searchdata.City.ToLower());


            //todo: do fuzzy search on locality and address

            if (!string.IsNullOrWhiteSpace(searchdata.OwnersLastName))
            {
                queryResult = queryResult.Where(q => q.AddressOwnerships.Any(a => a.Person.LastName.ToLower() == searchdata.OwnersLastName.ToLower()));
            }

            if (!string.IsNullOrWhiteSpace(searchdata.OwnersFirstName))
            {
                queryResult = queryResult.Where(q => q.AddressOwnerships.Any(a => a.Person.FirstName.ToLower() == searchdata.OwnersFirstName.ToLower()));
            }

            var result = await queryResult.ToListAsync();

            result = result.Select(EfMapper.Map).ToList();

            return(Ok(result));

            //await queryResult.ToListAsync()
        }
Exemplo n.º 2
0
        public async Task <AddressSearchModel> GetAddresses(AddressSearchModel model)
        {
            var url    = CRMApiUri + "/Address/GetAddresss?" + GetFilterString(model);
            var result = await GetOdataResultFromApi(url);

            var searchResultCount = 0;

            if (result.Count != null)
            {
                int.TryParse(result.Count.ToString(), out searchResultCount);
            }
            model.TotalRows = searchResultCount;
            model.AddressSearchResult.Clear();
            try
            {
                model.AddressSearchResult.AddRange(result.Items.Select(item => JsonConvert.DeserializeObject <AddressDto>(item.ToString())));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(model);
        }
Exemplo n.º 3
0
        private string GetFilterString(AddressSearchModel searchModel)
        {
            var filterString = string.Empty;

            if (searchModel != null)
            {
                if (!string.IsNullOrWhiteSpace(searchModel.FilterText))
                {
                    if (string.IsNullOrWhiteSpace(filterString))
                    {
                        filterString = ODataFilterConstant.Filter + $"contains(Forename,'{searchModel.FilterText}') eq true";
                    }
                    else
                    {
                        filterString += $" or contains(Forename,'{searchModel.FilterText}') eq true";
                    }
                    filterString += $" or contains(Surname,'{searchModel.FilterText}') eq true";
                }
                AddPageSizeNumberAndSortingInFilterString(searchModel, ref filterString);
            }
            return(filterString);
        }
Exemplo n.º 4
0
 public async Task <AddressSearchModel> GetAddresses(AddressSearchModel model)
 {
     return(await _addressApiClient.GetAddresses(model));
 }
        public async Task <IActionResult> FindAddress([FromBody] AddressSearchModel addressSearch)
        {
            var results = await simsApp.Addresses.FindAddress(addressSearch.Search);

            return(new OkObjectResult(mapper.Map <IEnumerable <SimsAddress>, List <SimsAddressViewModel> >(results)));
        }