/// <summary> /// Receives search criteria parameters (key/value pair) and returns a list of matching Subscribers /// </summary> /// <param name="input"></param> /// <returns></returns> public Dtos.GetQuotesResults SendQuote(Dtos.GetQuotesInput input) { Dtos.GetQuotesResults returnResults = new Dtos.GetQuotesResults(); try { Logger.ErrorFormat("CH000:START"); //Get get Subscriber details var subscriber = _subscriberRepository.Get(input.SubscriberRefId); //Get the Request details var request = _requestRepository.Get(input.RequestRefId); //Save Quote var quote = new Quote { Cost = input.Cost, Message = input.Message, RequestRefId = request.Id, SubscriberRefId = subscriber.Id }; Logger.ErrorFormat("CH000:START2"); //Saving entity with standard Insert method of repositories. int quotesId = _quoteRepository.InsertAndGetId(quote); //Update Subscriber Credits var subscriberCredits = new SubscriberCredits() { SubscriberRefId = input.SubscriberRefId, Credits = input.TotalCredits * -1 }; Logger.ErrorFormat("CH000:START3"); int subscriberCreditsResponse = _subscriberCreditsRepository.InsertAndGetId(subscriberCredits); //Get Company Configuration Logger.ErrorFormat("CH000:START4"); var companyConfig = _companyConfigRepository.GetCompanyConfigurations(input.CompanyId); string emailFrom = companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero:EmailReply"])).Value != null ? companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero:EmailReply"])).Value : "*****@*****.**"; string emailSubject = companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero:EmailSubject"])).Value != null ? companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero:EmailSubject"])).Value : "Vendor Quote"; Logger.ErrorFormat("CH000:START5"); //Send text message (This is a quote message FROM subscriber TO customer) Logger.ErrorFormat("CH000:START5j-_notificationRepoIsNull{0}, _companyConfigRep{0}", (_notificationRepository== null).ToString(), (_companyConfigRepository== null).ToString()); NotificationAppService notificationService = new NotificationAppService(_notificationRepository, _companyConfigRepository); Logger.ErrorFormat("CH000:START5d"); Logger.ErrorFormat("CH000:START5d-SubscriberID{0}, RequestID{1}", subscriber.Id.ToString(), request.Id.ToString()); Messaging.Dtos.NotificationInput notificationInput = new Dtos.NotificationInput(); Logger.ErrorFormat("CH000:START5e"); notificationInput.CompanyId = input.CompanyId; Logger.ErrorFormat("CH000:START5f"); notificationInput.EmailFrom = emailFrom; Logger.ErrorFormat("CH000:START5g"); notificationInput.EmailSubject = emailSubject; Logger.ErrorFormat("CH000:START5h"); notificationInput.EmailMessage = String.Format("Hello {0}: {1} has submitted a quote. Click here to view the quote.", request.FullName, subscriber.FullName); Logger.ErrorFormat("CH000:START5i"); notificationInput.EmailTo = request.SmsNumber; Logger.ErrorFormat("CH000:START5j"); Logger.ErrorFormat("CH000:START5j-notificationServiceIsNull{0}", (notificationService == null).ToString()); notificationService.SendNotification(notificationInput); Logger.ErrorFormat("CH000:START5k"); Logger.ErrorFormat("CH000:START6"); //Send send email message (This is a email message FROM Subscriber TO customer) //NotificationAppService notificationService = new NotificationAppService(_notificationRepository); notificationService.SendEmailNotification(new Messaging.Dtos.NotificationInput() { CompanyId = input.CompanyId, EmailFrom = emailFrom, EmailSubject = emailSubject, EmailMessage = String.Format("Hello {0}: {1} has submitted a quote. Click here to view the quote.", request.FullName, subscriber.FullName), EmailTo = request.Email }); Logger.ErrorFormat("CH000:START7"); returnResults = new Dtos.GetQuotesResults() { QuoteId = quotesId, ResponseMessage = "Quote successfully sent." }; return returnResults; } catch (System.Exception exc) { Logger.ErrorFormat("CH000:STARTZ{0}EXCSOURCE={1}EXCDATA={2}EXCINNEREXCEPTION{3}", exc.Message, exc.Source, exc.Data, exc.InnerException.Message); returnResults.ResponseMessage = exc.InnerException.Message; return returnResults; } }
public Dtos.RequestsDto CreateRequests(Dtos.CreateRequestsInput input) { int subscriberCount = 0; //We can use Logger, it's defined in ApplicationService class. //ERROR: Logger.Info("Creating a task for input: " + input); var companyConfig = _companyConfigRepository.GetCompanyConfigurations(input.CompanyId); //Creating a new Task entity with given input's properties var Requests = new Request { FullName = input.FullName, SmsNumber = input.SmsNumber, Email = input.Email, Comment = input.Comment, InquiryRefId = input.InquiryId }; //Saving entity with standard Insert method of repositories. int RequestsId = _requestsRepository.InsertAndGetId(Requests); Requests.Id = RequestsId; //Get Criteria/CriteriaValues for Company try { var criteriaValues = _criteriaValuesRepository.GetAllCriteriaValues(input.CompanyId); var inquiryCriteriavalues = _inquiryExtRepository.GetAllCriteriaValues(input.InquiryId); List<CriteriaValues> searchResults = new List<CriteriaValues>(); List<SubscribersDto> searchSubscribers = new List<SubscribersDto>(); List<CriteriaValues> criteriaValueMatch = new List<CriteriaValues>(); List<KeyValuePair<string, string>> inquiryCriteriaValues = new List<KeyValuePair<string, string>>(); //Get the Inquiry CriteriaValues var _inquiryCriteriaValues = _inquiryExtRepository.GetAllCriteriaValues(input.InquiryId); foreach (InquiryExt inquiry in _inquiryCriteriaValues) { //criteriaValueMatch = criteriaValues.Where(c => c.Criteria.Name == item.Key && c.Name == item.Value).ToList<CriteriaValues>(); criteriaValueMatch.Add(criteriaValues.Where(c => c.Criteria.Name == inquiry.Criteria.Name && c.Name == inquiry.CriteriaValue.Name).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) { foreach (CriteriaValues item in searchResults) { searchSubscribers = new List<SubscribersDto>(); if (item != null) { //Get a list of Subscribers associated to the criteriaValues (in SubscriptionCriteria) var subscriberCritera = _subscriberCriteriaRepository.GetMatchingSubscribers( item.Name, input.CompanyId, input.Latitude, input.Longitude, 0.0M); 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, _companyConfigRepository); if (subscriber.SmsNumber != null) { notificationService.SendNotification(new Messaging.Dtos.NotificationInput() { CompanyId = input.CompanyId, NotificationType = input.NotificationType, EmailFrom = input.ReplyToEmail, //"*****@*****.**", SubscriberCriteria = subscriberItem, InquiryExt = _inquiryCriteriaValues, Request = input, EmailMessage = String.Format("Need {0}", subscriberItem.CriteriaValues.Name), EmailSubject = String.Format("Hello {0}: {1} needs the following: {2}", subscriber.FullName, Requests.FullName, subscriberItem.CriteriaValues.Name), EmailTo = subscriber.SmsNumber }); } //Send send email message //NotificationAppService notificationService = new NotificationAppService(_notificationRepository); if (subscriber.Email != null) { string isActive = companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_SendGrid:IsActive"])).Value != null ? companyConfig.Find(cc => cc.Name.Equals(System.Configuration.ConfigurationSettings.AppSettings["creditsHero_SendGrid:IsActive"])).Value : "false"; if (isActive == "true") { notificationService.SendEmailNotification(new Messaging.Dtos.NotificationInput() { CompanyId = input.CompanyId, NotificationType = input.NotificationType, EmailFrom = input.ReplyToEmail, SubscriberCriteria = subscriberItem, InquiryExt = _inquiryCriteriaValues, Request = input, EmailMessage = String.Format("Need {0}", subscriberItem.CriteriaValues.Name), EmailSubject = String.Format("Hello {0}: {1} needs the following: {2}", subscriber.FullName, Requests.FullName, subscriberItem.CriteriaValues.Name), EmailTo = subscriber.Email }); } } subscriberCount++; } } //KeyValuePair<string, List<SubscribersDto>> resultsCriteria = // new KeyValuePair<string, List<SubscribersDto>>(item.Name, searchSubscribers); //returnResults.Results.Add(resultsCriteria); } } } } catch (System.Exception exc) { return new Dtos.RequestsDto { FullName = exc.InnerException.Message, SmsNumber = input.SmsNumber, Email = input.Email, Id = RequestsId, SubscriberCount = -1 }; } return new Dtos.RequestsDto { FullName = input.FullName, SmsNumber = input.SmsNumber, Email = input.Email, Id = RequestsId, SubscriberCount = subscriberCount }; }