public Dtos.GetCustomersOutput GetCustomers(Dtos.GetCustomerInput input) { if (input.CustomerId != null) { //TODO: Get unique CreditsHero requests' emails for passed in email. var customers = _customerRepository.GetCustomersByUserId(input.CustomerId.Value); return(new Dtos.GetCustomersOutput { Customers = Mapper.Map <List <Dtos.CustomerDto> >(customers) }); } else { if (input.CompanyId.HasValue) { //TODO: Get list of unique CreditsHero requests' emails. CreditsHero.Customers.Dtos.GetCustomersInput inputCustomer = new CreditsHero.Customers.Dtos.GetCustomersInput() { CompanyId = input.CompanyId }; CreditsHero.Customers.Dtos.GetCustomersOutput results = new CreditsHero.Customers.Dtos.GetCustomersOutput(); var customersCreditsHero = (GetCustomersOutput)_creditsHeroConnect.CallCreditsHeroService <GetCustomersOutput>( results, inputCustomer, "api/services/app/Customer/GetCustomers"); var customerUsers = _userManager.Users.Where(u => results.Customers.Any(a => a.Email == u.EmailAddress)); //results.Customers.Where(c => _userManager.Users.Contains(c.Email)); Dtos.GetCustomersOutput customerList = new Dtos.GetCustomersOutput(); foreach (var item in results.Customers) { Dtos.CustomerDto customer = new Dtos.CustomerDto(); customer.CellPhone = item.SmsNumber; customer.Email = item.Email; customer.FullName = item.FullName; customerList.Customers.Add(customer); } return(customerList); } } return(null); }
public Dtos.GetMembersOutput GetMembers(Dtos.GetMemberInput input) { if (input.MemberId != null) { var members = _memberRepository.GetMembersWithCompany(input.MemberId.Value); return(new Dtos.GetMembersOutput { Members = Mapper.Map <List <Dtos.MemberDto> >(members) }); } else { if (input.CompanyId.HasValue) { CreditsHero.Subscribers.Dtos.GetSubscribersInput inputSubscriber = new GetSubscribersInput() { CompanyId = input.CompanyId }; CreditsHero.Subscribers.Dtos.GetSubscribersOutput results = new GetSubscribersOutput(); var membersCreditsHero = (GetSubscribersOutput)_creditsHeroConnect.CallCreditsHeroService <GetSubscribersOutput>(results, inputSubscriber, "api/services/app/Subscriber/GetSubscribers"); var membersLocal = _memberRepository.GetMembersWithCompany(); Dtos.GetMembersOutput members = new Dtos.GetMembersOutput(); members.Members = new List <Dtos.MemberDto>(); foreach (var item in membersCreditsHero.Subscribers) { SubscribersDto subscriberExt = new SubscribersDto() { Email = item.Email, FullName = item.FullName, Id = item.Id, SmsNumber = item.SmsNumber, SubscriberId = item.SubscriberId, TotalCredits = item.TotalCredits, TotalSpend = item.TotalSpend }; var member = membersLocal.Find(c => c.Email == item.Email); if (member != null) { Dtos.MemberDto subscriber = new Dtos.MemberDto() { SubscriberExt = subscriberExt, FullName = member != null ? member.FullName : "", Id = member != null ? member.Id : 0, CellPhone = member != null ? member.CellPhone : "", Company = member.Company != null?Mapper.Map <Companies.Dtos.CompanyDto>(member.Company) : new Companies.Dtos.CompanyDto(), CompanyRefId = member != null ? member.CompanyRefId : 0, Email = member != null ? member.Email : "", Fax = member != null ? member.Fax : "", JobTitle = member != null ? member.JobTitle : "", Phone = member != null ? member.Phone : "", UserRefId = member != null ? member.UserRefId : 0 }; members.Members.Add(subscriber); } } return(members); } else { var members = _memberRepository.GetMembersWithCompany(); return(new Dtos.GetMembersOutput { Members = Mapper.Map <List <Dtos.MemberDto> >(members) }); } } }