public async Task <JsonResult> GetAllContactAsync([FromBody] ContactQueryModel query)
        {
            var contactList = await _contactRepository.GetAll(query);

            if (contactList == null || contactList.Count == 0)
            {
                return(new JsonResult("Contacts not found"));
            }
            var contactViewModelList = new List <ContactViewModel>();

            foreach (Contact c in contactList)
            {
                contactViewModelList.Add(PopulateContactViewModel(c));
            }
            return(new JsonResult(contactViewModelList));
        }
Beispiel #2
0
        public Task <List <Contact> > GetAll(ContactQueryModel query)
        {
            var contacts = _contactDbContext.ContactItems.Include("Address");

            if (query.Id != null)
            {
                contacts = contacts.Where(x => x.Id == query.Id);
            }
            if (query.Birthdate != null)
            {
                contacts = contacts.Where(x => x.Birthdate == query.Birthdate);
            }
            if (query.AddressId != null)
            {
                contacts = contacts.Where(x => x.Address.AddressId == query.AddressId);
            }
            if (!String.IsNullOrEmpty(query.Name))
            {
                contacts = contacts.Where(x => x.Name == query.Name);
            }
            if (!String.IsNullOrEmpty(query.Company))
            {
                contacts = contacts.Where(x => x.Company == query.Company);
            }
            if (!String.IsNullOrEmpty(query.ProfileImageUrl))
            {
                contacts = contacts.Where(x => x.ProfileImageUrl == query.ProfileImageUrl);
            }
            if (!String.IsNullOrEmpty(query.Email))
            {
                contacts = contacts.Where(x => x.Email == query.Email);
            }
            if (!String.IsNullOrEmpty(query.WorkPhoneNumber))
            {
                contacts = contacts.Where(x => x.WorkPhoneNumber == query.WorkPhoneNumber);
            }
            if (!String.IsNullOrEmpty(query.PersonalPhoneNumber))
            {
                contacts = contacts.Where(x => x.PersonalPhoneNumber == query.PersonalPhoneNumber);
            }
            if (!String.IsNullOrEmpty(query.StreetAddress))
            {
                contacts = contacts.Where(x => x.Address.StreetAddress == query.StreetAddress);
            }
            if (!String.IsNullOrEmpty(query.City))
            {
                contacts = contacts.Where(x => x.Address.City == query.City);
            }
            if (!String.IsNullOrEmpty(query.State))
            {
                contacts = contacts.Where(x => x.Address.State == query.State);
            }
            if (!String.IsNullOrEmpty(query.Country))
            {
                contacts = contacts.Where(x => x.Address.Country == query.Country);
            }
            if (!String.IsNullOrEmpty(query.ZipCode))
            {
                contacts = contacts.Where(x => x.Address.ZipCode == query.ZipCode);
            }

            return(contacts.ToListAsync());
        }