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)
                    };
                }
            }
        }
        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)
                    });
                }
            }
        }