public void PushNotificationFromLead(int leadId)
        {
            var lead = _uow.Lead.Get(leadId);
            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
            });

            this.PushNotification(lead.UserId, r);
        }
Example #2
0
        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));
            }
        }