public async Task <TransactionResult <IEnumerable <MyVoter> > > MyVoters(MyVotersRequest request) { var result = new TransactionResult <IEnumerable <MyVoter> >(); if (request != null) { try { var myVoters = await((IVoterDao)baseDao).MyVoters(request); result.IsSuccess = true; if (myVoters != null) { result.Data = myVoters; } else { result.Data = new List <MyVoter>(); result.Message = "No data to display."; } } catch (Exception ex) { result.IsSuccess = false; result.Errors.Add(ex.Message); } } else { result.IsSuccess = false; result.Errors.Add("request is invalid."); } return(result); }
public async Task <IEnumerable <MyVoter> > MyVoters(MyVotersRequest request) { var myVoters = new List <MyVoter>(); #region Select Query string sql = @" IF(@PrecinctId <=0) SET @PrecinctId = NULL SELECT av.[VoterId] ,av.[AccountId] ,av.[PrimaryPhoneNumber] ,av.[SecondaryPhoneNumebr] ,av.[Email] ,av.[Contactable] ,av.[FavContactMethod] ,av.[Heritage] FROM [dbo].[AccountVoters] av INNER JOIN [dbo].[Account] a ON a.AccountId = av.AccountId INNER JOIN [dbo].[Voter] v ON v.Id = av.VoterId WHERE a.IsActive = 1 AND av.AccountId = @AccountId AND (v.PrecinctId = @PrecinctId OR @PrecinctId IS NULL) AND ((v.LastName LIKE @LastName + '%' OR NULLIF(@LastName,'') IS NULL) OR (v.FirstName LIKE @FirstName + '%' OR NULLIF(@FirstName,'') IS NULL) OR (v.City LIKE @City + '%' OR NULLIF(@City,'') IS NULL) OR (v.State LIKE @State + '%' OR NULLIF(@State,'') IS NULL) OR (v.Zip LIKE @zipCode + '%' OR NULLIF(@zipCode,'') IS NULL))" ; #endregion using (var conn = new SqlConnection(this.ConnectionString)) { await conn.OpenAsync(); var results = await conn.QueryAsync <MyVoterMapObject>(sql, new { AccountId = request.AccountId, City = request.City, FirstName = request.FirstName, LastName = request.LastName, PrecinctId = request.PrecinctId, State = request.State, ZipCode = request.ZipCode }); if (results != null) { foreach (var myVoter in results) { myVoters. Add( new MyVoter() { AccountId = myVoter.AccountId, Comments = await Comments(myVoter.VoterId), IsContactable = myVoter.Contactable, Voter = await Get(myVoter.VoterId), Details = new MyVoterDetails() { ContactableMethod = new DropDownDataField() { Value = new NameValueCodeItem() { Code = myVoter.FavContactMethod } }, Email = new DataField() { Value = myVoter.Email }, Heritage = new DataField() { Value = myVoter.Heritage }, PrimaryPhone = new DTO.Common.DataField() { Value = myVoter.PrimaryPhoneNumber }, SecondaryPhone = new DTO.Common.DataField() { Value = myVoter.SecondaryPhoneNumebr } } } ); } } } return(myVoters); }