public void SendLeadData(AutomationRequestModel data) { try { var leads = uow.Lead.GetLeadsToSendIntegration().Where(x => x.LeadId == data.LeadId); foreach (var item in leads) { try { var res = uow.Lead.SendViaApi(item); if (res.Code == System.Net.HttpStatusCode.Unauthorized) { //uow.Integration.Delete(item.IntegrationId, Conts.Cpanel_user); } uow.IntegrationLeadSend.IU(new Entities.Model.IntegrationLeadSend() { LeadId = item.LeadId, IntegrationId = item.IntegrationId, ListId = item.ListId, ResponseMsg = res.Message, Status = res.Code == System.Net.HttpStatusCode.OK ? (int)LeadSendStatus.Success : (int)LeadSendStatus.Failed, LastSendDate = DateTime.Now }); } catch (Exception ex) { _log.Error(ex); } } } catch (Exception ex) { _log.Error(ex); } }
public async Task <IHttpActionResult> SendLead(AutomationRequestModel data) { try { _uow.Lead.SendLeadData(data); } catch (Exception ex) { _log.Error(ex); } return(Ok()); }
public async Task <IHttpActionResult> AddAutomation(AutomationRequestModel data) { try { await _uow.Lead.AddSendAutomation(data); } catch (Exception ex) { _log.Error(ex); } return(Ok()); }
public async Task AddSendAutomation(AutomationRequestModel data) { //check automation var automations = await uow.Automation.GetByPage(data.PageId); foreach (var item in automations.Where(x => x.IsEnable)) { var emailAuto = new MailToSend() { LeadId = data.LeadId, TemplateId = item.TemplateId, UserId = data.UserId, WillSendDate = DateTime.Now.AddHours(item.DelayHour).AddMinutes(item.DelayMin) }; uow.MailToSend.IU(emailAuto); var list = GetLeadsToSendAutomation(); foreach (var a in list.Where(x => x.UserId == data.UserId && x.TemplateId == item.TemplateId && x.LeadId == data.LeadId)) { var r = SendAutomation(a); } } }
public async Task <IHttpActionResult> Post(Core.Entities.RequestModel.FormDataRequest data) { try { data.IpAddress = this.ClientIP; data.IsMobile = this.Request.IsMobileBrowser(); var lead = await _uow.Lead.Add(data); var domain = MBN.Utils.WebUtils.AppSettings("BUIlDER_DOMAIN", "app.punnel.com"); if (lead.Link.Contains(domain)) { return(Ok()); } //_uow.Lead.GetMoreInfo(lead.Id); new Core.BLL.Queue.LeadSubcribleQueue(lead.Id).Execute(); var aModel = new AutomationRequestModel() { LeadId = lead.Id, PageId = lead.LandingPageId, UserId = lead.UserId }; var stringContent = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(aModel), UnicodeEncoding.UTF8, "application/json"); var client = new HttpClient(); client.PostAsync("https://api.punnel.com/api/automation/add", stringContent); client.PostAsync("https://api.punnel.com/api/automation/send-lead", stringContent); LeadNotifyResponse res = new LeadNotifyResponse() { FullName = lead.FullName, Email = lead.Email, Phone = lead.Phone, Link = lead.Link, IpAddress = lead.IpAddress, Region = ""//lead.RegionName }; var r = _uow.Notification.IU_Alert(new Core.Entities.Notification.Alert() { ReferId = lead.Id.ToString(), UserId = lead.UserId, Title = res.Title, Content = res.Content, Type = (int)NotificationType.Subcrible, IsBroadCast = false, Link = res.Link }); try { var context = GlobalHost.ConnectionManager.GetHubContext <NotificationHub>(); context.Clients.User(lead.UserId).subcrible_receive(Newtonsoft.Json.JsonConvert.SerializeObject(r)); } catch (Exception ex) { _log.ErrorFormat("Lỗi signalR hub: {0}", ex); } //pushmobile try { _uow.Notification.PushNotification(lead.UserId, r); }catch (Exception ex) { _log.ErrorFormat("push mobile err", ex); } return(Ok()); } catch (BusinessException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { _log.Error(Newtonsoft.Json.JsonConvert.SerializeObject(data)); _log.Error(ex); return(BadRequest(ex.Message)); } }