public IHttpActionResult SendInfoForm(Core.Entities.RequestModel.FormDataRequest data) { try { data.IpAddress = this.ClientIP; _uow.Lead.Add(data); return(Ok()); } catch (BusinessException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { _log.Error(ex); return(BadRequest(this.General_Err)); } }
public async Task <Lead> Add(Core.Entities.RequestModel.FormDataRequest data) { var page = await uow.LandingPage.GetPageForSubcrible(data.id); if (page == null) { throw new BusinessException("Landing page không tồn tại"); } Lead lead = new Lead(); lead.UserId = page.UserId; lead.LandingPageId = data.id; lead.PrivateCode = DateTime.Now.GetHashCode().ToString("x").ToUpper(); lead.SubmitDate = DateTime.Now; lead.IpAddress = data.IpAddress; lead.IsMobile = data.IsMobile.Value; lead.Referer = ""; var frmAttrs = data.dataForm.ToList(); int auto_email_template = 0; List <Entities.RequestModel.FormData> extData = new List <Entities.RequestModel.FormData>(); foreach (var item in frmAttrs) { switch (item.name) { case "name": lead.FullName = item.value; break; case "email": lead.Email = item.value; break; case "phone": lead.Phone = item.value; break; //case "message": // lead.Notes = item.value; // break; case "url page": lead.Link = (item.value + "@").Replace("/@", "").Replace("@", ""); break; case "url_page": lead.Link = (item.value + "@").Replace("/@", "").Replace("@", ""); break; case "auto_rep": if (!string.IsNullOrEmpty(item.value)) { auto_email_template = int.Parse(item.value); } break; default: if (string.IsNullOrEmpty(item.value) == false) { extData.Add(item); } break; } } //_log.Warn(lead.Link); //_log.Warn(page.Domain); //Nếu đăng kí từ trang preview if (lead.Link.Contains(BUIlDER_DOMAIN)) { return(lead); } //else if (Utils.CommonUtils.GetDomainFromUrl(lead.Link) != Utils.CommonUtils.GetDomainFromUrl(page.Domain)) //{ // _log.Warn("Xin lỗi! Đăng kí không thể thực hiện từ url " + lead.Link + " , domain: " + page.Domain); // throw new BusinessException("Xin lỗi! Đăng kí chỉ thực hiện được từ địa chỉ chính thức của Landing Page này."); //} lead.JsonData = Newtonsoft.Json.JsonConvert.SerializeObject(extData); lead.BeforeUpdate(); int leadId = 0, count = 0; bool k = false; var m = _dbSet.FirstOrDefault(x => x.LandingPageId == lead.LandingPageId && x.Email == lead.Email && x.Phone == lead.Phone); if (m == null || (string.IsNullOrEmpty(lead.Email) && string.IsNullOrEmpty(lead.Phone))) { lead.SubmitDate = DateTime.Now; lead.SubmitCount = 1; count = 1; this.Add(lead); this.Commit(); leadId = lead.Id; } else { m.FullName = lead.FullName; m.FirstName = lead.FirstName; m.LastName = lead.LastName; m.Notes = lead.Notes; m.IpAddress = lead.IpAddress; m.Link = lead.Link; m.SubmitDate = DateTime.Now; m.SubmitCount++; count = m.SubmitCount; m.Status = 1; m.SystemNote = $"Khách liên hệ lần {m.SubmitCount}"; this.Commit(); leadId = m.Id; k = true; } //if (auto_email_template > 0) //{ // if (leadId == 0) // { // _log.Warn("Lead id: 0"); // } // if (uow.EmailTemplate.Exists(auto_email_template) && count<3) // { // var emailAuto = new MailToSend() // { // LeadId = leadId, // TemplateId = auto_email_template, // UserId = page.UserId, // WillSendDate = DateTime.Now // }; // uow.MailToSend.IU(emailAuto); // var list = GetLeadsToSendAutomation(); // var r = SendAutomation(list.FirstOrDefault()); // } //} //else //{ // //check automation // //var automations = await uow.Automation.GetByPage(page.Id); // //foreach(var item in automations.Where(x=>x.IsEnable)) // //{ // // var emailAuto = new MailToSend() // // { // // LeadId = leadId, // // TemplateId = item.TemplateId, // // UserId = page.UserId, // // WillSendDate = DateTime.Now.AddHours(item.DelayHour).AddMinutes(item.DelayMin) // // }; // // uow.MailToSend.IU(emailAuto); // // var list = GetLeadsToSendAutomation(); // // var r = SendAutomation(list.FirstOrDefault(x=>x.UserId==page.UserId && x.TemplateId==item.TemplateId && x.LeadId==leadId)); // //} //} var res = k == true? m: lead; return(res); }
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)); } }