public GetInquiryResults MakeInquiry(GetInquiryInput input) { GetInquiryResults results = new GetInquiryResults(); return (GetInquiryResults)_creditsHeroConnect.CallCreditsHeroService<GetInquiryResults>(results, input, "api/services/app/Inquiry/MakeInquiry"); }
public Dtos.GetInquiryResults MakeInquiry(Dtos.GetInquiryInput input) { List<CriteriaValues> searchResults = new List<CriteriaValues>(); Dtos.GetInquiryResults returnResults = new Dtos.GetInquiryResults(); List<SubscribersDto> searchSubscribers = new List<SubscribersDto>(); try { var criteriaValues = _criteriaValuesRepository.GetAllCriteriaValues(input.CompanyId); List<CriteriaValues> criteriaValueMatch = new List<CriteriaValues>(); foreach (KeyValuePair<string, string> item in input.QueryRequest) { //criteriaValueMatch = criteriaValues.Where(c => c.Criteria.Name == item.Key && c.Name == item.Value).ToList<CriteriaValues>(); criteriaValueMatch.Add(criteriaValues.Where(c => c.Criteria.Name == item.Key && c.Name == item.Value).FirstOrDefault<CriteriaValues>()); } //searchResults = criteriaValues.ToList<CriteriaValues>(); returnResults.Results = new List<KeyValuePair<string, List<SubscribersDto>>>(); searchResults = criteriaValueMatch; //If there is a match (criteraValues is not empty) then create an Inquiry if (searchResults.Count > 0) { //Create Inquiry container int inquiryId = _inquiryRepository.InsertAndGetId(new Inquiry(){CompanyRefId = input.CompanyId}); returnResults.InquiryId = inquiryId; foreach (CriteriaValues item in searchResults) { searchSubscribers = new List<SubscribersDto>(); if (item != null) { //Create Inquiry Criteria items per Match Value int inquiryExtId = _inquiryExtRepository.InsertAndGetId(new InquiryExt() { InquiryRefId = inquiryId, CriteriaRefId = item.CriteriaRefId, CriteriaValueRefId = item.Id }); //Get a list of Subscribers associated to the criteriaValues (in SubscriptionCriteria) var subscriberCritera = _subscriberCriteriaRepository.GetMatchingSubscribers( item.Name, input.CompanyId, input.Latitude, input.Longitude, input.SearchDistance); foreach (SubscriberCriteria subscriberItem in subscriberCritera) { SubscribersDto subscriber = new SubscribersDto { Id = subscriberItem.Subscriber.Id, Email = subscriberItem.Subscriber.Email, FullName = subscriberItem.Subscriber.FullName, SmsNumber = subscriberItem.Subscriber.SmsNumber }; if (!searchSubscribers.Exists(s => s.Id == subscriber.Id)) { searchSubscribers.Add(subscriber); ////Send text message //NotificationAppService notificationService = new NotificationAppService(_notificationRepository); //notificationService.SendNotification(new Messaging.Dtos.NotificationInput() //{ // EmailFrom = "*****@*****.**", // EmailMessage = String.Format("Need {0}", subscriberItem.CriteriaValues.Name), // EmailSubject = String.Format("Hello {0}: Customer needs the following: {1}", subscriber.FullName, subscriberItem.CriteriaValues.Name), // EmailTo = subscriber.SmsNumber //}); ////Send send email message ////NotificationAppService notificationService = new NotificationAppService(_notificationRepository); //notificationService.SendEmailNotification(new Messaging.Dtos.NotificationInput() //{ // EmailFrom = "*****@*****.**", // EmailMessage = String.Format("Need {0}", subscriberItem.CriteriaValues.Name), // EmailSubject = String.Format("Hello {0}: Customer needs the following: {1}", subscriber.FullName, subscriberItem.CriteriaValues.Name), // EmailTo = subscriber.Email //}); } } KeyValuePair<string, List<SubscribersDto>> resultsCriteria = new KeyValuePair<string, List<SubscribersDto>>(item.Name, searchSubscribers); returnResults.Results.Add(resultsCriteria); } } return returnResults; } returnResults.ResponseMessage = "There were no matching Subscribers for the Criteria."; return returnResults; } catch (System.Exception exc) { returnResults.ResponseMessage = exc.InnerException.Message; return returnResults; } }