public async Task <IEnumerable <Database.Entities.Address> > GetAddresses(AddressParams addressParams)
        {
            Expression <Func <Database.Entities.Address, bool> > @where = n => true;

            if (addressParams.IsConfirmed.HasValue)
            {
                @where = n => n.IsConfirmed == addressParams.IsConfirmed.Value;
            }

            return(await _context.Addresses.Where(@where).ToListAsync());
        }
        public async Task <IActionResult> GetAddresses([FromQuery] AddressParams addressParams)
        {
            var addresses = await _addressRepository.GetAddresses(addressParams);

            var addressesToReturn = _mapper.Map <IEnumerable <AddressForListDto> >(addresses);

            Response.AddPagination(addresses.CurrentPage, addresses.PageSize,
                                   addresses.TotalCount, addresses.TotalPages);

            return(Ok(addressesToReturn));
        }
Beispiel #3
0
        public async Task <PagedList <Address> > SearchAddresses(AddressParams addressParams)
        {
            var addresses = dataContext.Address.Include(a => a.Account).Include(a => a.Country).Include(a => a.ContactAddresses).ThenInclude(c => c.Contact).AsQueryable();

            if (addressParams.Id > 0)
            {
                addresses = addresses.Where(a => a.Id == addressParams.Id);
                return(await PagedList <Address> .CreateAsync(addresses, addressParams.PageNumber, addressParams.PageSize));
            }

            if (!String.IsNullOrEmpty(addressParams.AddressTitle))
            {
                addresses = addresses.Where(a => a.AddressTitle.Contains(addressParams.AddressTitle));
            }

            if (!String.IsNullOrEmpty(addressParams.AddressLine))
            {
                addresses = addresses.Where(a => a.AddressLine.Contains(addressParams.AddressLine));
            }

            if (!String.IsNullOrEmpty(addressParams.State))
            {
                addresses = addresses.Where(a => a.State.Contains(addressParams.State));
            }

            if (!String.IsNullOrEmpty(addressParams.PostalCode))
            {
                addresses = addresses.Where(a => a.PostalCode.Contains(addressParams.PostalCode));
            }

            if (addressParams.AccountId != null && addressParams.AccountId > 0)
            {
                addresses = addresses.Where(a => a.AccountId == addressParams.AccountId);
            }

            if (addressParams.CountryId > 0)
            {
                addresses = addresses.Where(a => a.CountryId == addressParams.CountryId);
            }

            if (addressParams.ContactId > 0)
            {
                addresses = addresses.Include(a => a.ContactAddresses).ThenInclude(ca => ca.ContactId == addressParams.ContactId);
            }

            if (addressParams.IsMain != null)
            {
                addresses = addresses.Where(a => a.IsMain == addressParams.IsMain);
            }

            return(await PagedList <Address> .CreateAsync(addresses, addressParams.PageNumber, addressParams.PageSize));
        }
        public async Task <IActionResult> GetAddresses([FromQuery] AddressParams addressParams)
        {
            try
            {
                var addresses = await _repo.GetAddresses(addressParams);

                return(Ok(addresses));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);

                return(StatusCode((int)HttpStatusCode.InternalServerError, "Error!"));
            }
        }
        public async Task <PagedList <Address> > GetAddresses(AddressParams addressParams)
        {
            var addresses = Context.Addresses
                            .AsQueryable().AsNoTracking();

            if (!string.IsNullOrEmpty(addressParams.SearchTerm))
            {
                addresses = addresses.Where(u => u.StreetAddress.Contains(addressParams.SearchTerm));
            }

            if (!string.IsNullOrEmpty(addressParams.City))
            {
                addresses = addresses.Where(u => u.City == addressParams.City);
            }

            if (!string.IsNullOrEmpty(addressParams.Postcode))
            {
                addresses = addresses.Where(u => u.Postcode == addressParams.Postcode);
            }

            if (!string.IsNullOrEmpty(addressParams.Country))
            {
                addresses = addresses.Where(u => u.Country == addressParams.Country);
            }

            if (!string.IsNullOrEmpty(addressParams.State))
            {
                addresses = addresses.Where(u => u.State == addressParams.State);
            }

            var columnsMap = new Dictionary <string, Expression <Func <Address, object> > >()
            {
                ["StreetAddress"]     = a => a.StreetAddress,
                ["Country"]           = a => a.Country,
                ["State"]             = a => a.State,
                ["City"]              = a => a.City,
                ["IsBillingAddress"]  = a => a.IsBillingAddress,
                ["IsShippingAddress"] = a => a.IsShippingAddress
            };

            addresses = addresses.ApplyOrdering(addressParams, columnsMap);

            return(await PagedList <Address> .CreateAsync(addresses, addressParams.PageNumber, addressParams.PageSize));
        }
Beispiel #6
0
        public async Task <IActionResult> SearchAccountAddress([FromQuery] AddressParams accountAddressParams)
        {
            try
            {
                var addresses = await addressManager.SearchAddresses(accountAddressParams);

                if (addresses != null)
                {
                    var addressToReturn = mapper.Map <List <AddressReturnDTO> >(addresses);

                    return(Ok(addressToReturn));
                }

                return(BadRequest());
            }
            catch (Exception)
            {
                throw;
            }
        }