public RequestMessageFormat <HouseMemberDTO> GetById(int id)
        {
            RequestMessageFormat <HouseMemberDTO> response = new RequestMessageFormat <HouseMemberDTO>();

            try
            {
                HouseMember    houseMember    = this.HouseMemberRepository.FindById(id);
                HouseMemberDTO houseMemberDTO = this.AutoMapperConfigurations.HouseMemberToHouseMemberDTO(houseMember);
                if (houseMember == null)
                {
                    response.Data    = null;
                    response.Success = false;
                    response.Message = "House Member Not Found";
                    return(response);
                }
                else
                {
                    response.Data    = houseMemberDTO;
                    response.Success = true;
                    response.Message = "Data fetched successfully";
                    return(response);
                }
            }
            catch (Exception)
            {
                response.Message = "Some Error Occurred while deleting data. Please try again";
                response.Success = false;
                response.Data    = null;
                return(response);
            }
        }
示例#2
0
        public async Task <HouseMember> AddAddressCoordinates(HouseMember houseMember, string address, string city, string state, string zipCode)
        {
            HttpClient client  = new HttpClient();
            var        url     = $"https://geocoding.geo.census.gov/geocoder/locations/address?street={address}&city={city}&state={state}&zip={zipCode}&benchmark=Public_AR_Census2010&format=json";
            var        results = await client.GetAsync(url);

            var stringResults = await results.Content.ReadAsStringAsync();

            var addressCoordinates = JsonConvert.DeserializeObject <AddressCoordinatesApiModel>(stringResults);

            houseMember.CoordinateX = addressCoordinates.Result.AddressMatches[0].Coordinates.X;
            houseMember.CoordinateY = addressCoordinates.Result.AddressMatches[0].Coordinates.Y;

            return(houseMember);
        }
        public HouseMember ConvertToHouseMemeberObject(HouseMemberResult ProPublicaHouseMember, GoogleApiRepresentatives GoogleRepresentatives)
        {
            HouseMember HouseMember       = new HouseMember();
            var         GoogleHouseMember = GoogleRepresentatives.Officials[4];

            HouseMember.MemberId         = ProPublicaHouseMember.Id;
            HouseMember.FirstName        = ProPublicaHouseMember.FirstName;
            HouseMember.MiddleName       = ProPublicaHouseMember.MiddleName;
            HouseMember.LastName         = ProPublicaHouseMember.LastName;
            HouseMember.District         = ProPublicaHouseMember.District;
            HouseMember.State            = GoogleRepresentatives.NormalizedInput.State;
            HouseMember.NextElectionYear = ProPublicaHouseMember.NextElection;
            HouseMember.OfficeAddress    = new Address(GoogleHouseMember.Address[0].Line1,
                                                       GoogleHouseMember.Address[0].City,
                                                       GoogleHouseMember.Address[0].State,
                                                       GoogleHouseMember.Address[0].Zip);
            HouseMember.Phone   = GoogleHouseMember.Phones[0];
            HouseMember.WebSite = GoogleHouseMember.Urls[0];
            if (GoogleHouseMember.Emails != null)
            {
                HouseMember.Email = GoogleHouseMember.Emails[0];
            }
            if (GoogleHouseMember.Channels != null)
            {
                foreach (Channel channel in GoogleHouseMember.Channels)
                {
                    switch (channel.Type)
                    {
                    case "Facebook":
                        HouseMember.Facebook = channel.Id;
                        break;

                    case "Twitter":
                        HouseMember.Twitter = channel.Id;
                        break;

                    case "YouTube":
                        HouseMember.YouTube = channel.Id;
                        break;
                    }
                }
            }

            return(HouseMember);
        }
示例#4
0
 public void SaveHouseMember(HouseMember member)
 {
     try
     {
         if (member.Id <= 0)
         {
             _context.HouseMembers.Add(member);
         }
         else
         {
             _context.Entry(member).State = EntityState.Modified;
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
        public RequestMessageFormat <HouseMemberDTO> Add(HouseMemberDTO houseMemberDTO)
        {
            RequestMessageFormat <HouseMemberDTO> response = new RequestMessageFormat <HouseMemberDTO>();

            try
            {
                houseMemberDTO.CreatedOn  = DateTime.Now;
                houseMemberDTO.ModifiedOn = DateTime.Now;


                if (this.CheckEmptyData(houseMemberDTO))
                {
                    response.Message = "Entered Invalid Data";
                    response.Data    = null;
                    response.Success = false;
                    return(response);
                }

                HouseMember houseMember = this.AutoMapperConfigurations.HouseMemberDTOToHouseMember(houseMemberDTO);


                bool isAdded = this.HouseMemberRepository.Add(houseMember);



                if (isAdded)
                {
                    response.Message  = "Added Successfully";
                    houseMemberDTO.ID = houseMember.ID;

                    response.Data    = houseMemberDTO;
                    response.Success = true;
                    return(response);
                }
            }
            catch (Exception)
            {
                response.Message = "Some Error Occurred while adding data please try again";
                response.Data    = null;
                response.Success = false;
                return(response);
            }
            return(response);
        }
        public RequestMessageFormat <HouseMemberDTO> Delete(int id)
        {
            RequestMessageFormat <HouseMemberDTO> response = new RequestMessageFormat <HouseMemberDTO>();

            try
            {
                HouseMember houseMember = this.HouseMemberRepository.FindById(id);


                if (houseMember == null)
                {
                    response.Message = "HouseMember Not Exist";
                    response.Success = false;
                    response.Data    = null;
                    return(response);
                }
                else
                {
                    bool isDeleted = this.HouseMemberRepository.Delete(houseMember);



                    if (isDeleted)
                    {
                        response.Message = "Deleted Successfully";
                        response.Success = true;
                        response.Data    = null;
                        return(response);
                    }
                }
            }catch (Exception)
            {
                response.Message = "Some Error Occurred while deleting data. Please try again";
                response.Success = false;
                response.Data    = null;
                return(response);
            }

            return(response);
        }
示例#7
0
        public async Task <HouseMember> FetchVotingHistory(HouseMember houseMember)
        {
            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Add("X-API-Key", "hxY9fxmPmO7Ev1UT6KUlbYaPVKM5v619B2DWRjIY");

            var propublicaVotingHistoryUrl = $"https://api.propublica.org/congress/v1/members/{houseMember.MemberId}/votes.json";
            var results = await client.GetAsync(propublicaVotingHistoryUrl);

            var stringResults = await results.Content.ReadAsStringAsync();

            var propublicaVotingHistory = JsonConvert.DeserializeObject <PropublicaRepBillVotingPosition>(stringResults);
            var dictionary = new Dictionary <string, BillVotingInformation>();

            foreach (Vote votingInfo in propublicaVotingHistory.Results[0].Votes)
            {
                if (votingInfo.Bill.BillId != null)
                {
                    var billVotingInformation = new BillVotingInformation
                    {
                        BillId             = votingInfo.Bill.BillId,
                        BillNumber         = votingInfo.Bill.Number,
                        BillSlug           = votingInfo.Bill.BillId.Split('-')[0],
                        Description        = votingInfo.Description,
                        BillVotingPosition = votingInfo.Position,
                        DateOfVote         = votingInfo.Date
                    };

                    if (dictionary.ContainsKey(votingInfo.Bill.BillId) == false)
                    {
                        dictionary.Add(votingInfo.Bill.BillId, billVotingInformation);
                    }
                }
            }

            houseMember.BillVotingHistory.AddRange(dictionary.Values);

            return(houseMember);
        }
示例#8
0
 public DistrictRepresentatives(HouseMember houseMember)
 {
     this.houseMember = houseMember;
 }
示例#9
0
 public HouseMemberDTO HouseMemberToHouseMemberDTO(HouseMember houseMember)
 {
     return(Mapper.Map <HouseMemberDTO>(houseMember));
 }