Пример #1
0
        public List <CampainResponse> GetResponse_GetCampains(string userId, string accId)
        {
            List <CampainResponse> result = new List <CampainResponse>();

            var apiSite = _dbSet.AsNoTracking().FirstOrDefault(x => x.UserId == userId && x.AccId == accId);

            if (apiSite == null)
            {
                return(result);
            }
            string apiKey = apiSite.ApiKey;

            GetResponseTask task = new GetResponseTask(apiKey);
            var             res  = task.GetCampaigns();

            if (res.Code == System.Net.HttpStatusCode.OK)
            {
                result = (List <CampainResponse>)res.Data;
            }
            else
            {
                throw new BusinessException(res.Message);
            }
            return(result);
        }
Пример #2
0
        public Integration GetResponse_Auth(string apiKey, string userId)
        {
            Integration     result = new Integration();
            GetResponseTask task   = new GetResponseTask(apiKey);
            var             res    = task.Auth();

            if (res.Code == System.Net.HttpStatusCode.OK)
            {
                var resultAuth = (AccountResponse)res.Data;
                //save info
                var info = new Integration()
                {
                    Id                = Guid.NewGuid(),
                    SiteId            = (int)IntegrationType.GetResponse,
                    AccId             = resultAuth.accountId,
                    Email             = resultAuth.email,
                    Phone             = resultAuth.phone,
                    ApiKey            = apiKey,
                    UserId            = userId,
                    LastConnectedDate = DateTime.Now
                };
                IU(info, userId);
                result = info;
            }
            else
            {
                throw new BusinessException(res.Message);
            }
            return(result);
        }
Пример #3
0
        public async Task <ApiResponse> Refresh(Guid id, string userId)
        {
            ApiResponse res  = new ApiResponse();
            var         site = _dbSet.FirstOrDefault(x => x.Id == id && x.UserId == userId);

            if (site != null)
            {
                switch (site.SiteId)
                {
                case (int)IntegrationType.GetResponse:
                    res = new GetResponseTask(site.ApiKey).Auth();
                    break;

                case (int)IntegrationType.MailChimp:
                    res = new MailChimpTask(site.ApiKey).Auth();
                    break;

                case (int)IntegrationType.Autopilot:
                    res = new AutopilotTask(site.ApiKey).Auth();
                    break;

                case (int)IntegrationType.ActiveCampain:
                    res = new IntegrationServices.ActiveCampain.ActiveCampainTask(site.AccId, site.ApiKey).Auth();
                    break;

                case (int)IntegrationType.InfusionSoft:
                    res = new IntegrationServices.InfusionSoft.InfusionSoftTask(site.ApiKey, site.Password).GetCampaigns();
                    if (res.Code == System.Net.HttpStatusCode.Unauthorized)
                    {
                        var newToken = new IntegrationServices.InfusionSoft.InfusionSoftTask(site.ApiKey, site.Password).Refresh();
                        if (newToken != null && !string.IsNullOrEmpty(newToken.access_token))
                        {
                            site.ApiKey = newToken.access_token;
                            this.Commit();
                            res.Code = System.Net.HttpStatusCode.OK;
                        }
                    }
                    break;

                case (int)IntegrationType.Gmail:
                    res = new EmailServices.GmailPersonalSvc(site.ApiKey, site.TokenJson).Auth();
                    break;

                case (int)IntegrationType.GoogleSheet:
                    res = new EmailServices.GoogleSheetSvc(site.ApiKey, site.TokenJson).Auth();
                    break;

                case (int)IntegrationType.Wordpress:
                    res = new Utils.WordpressUtils(site.AccId, site.ApiKey).Auth();
                    if (res.Code == System.Net.HttpStatusCode.NotFound)
                    {
                        throw new BusinessException("Không kiểm tra được kết nối WP. Cấu hình này được dùng để xuất bản từ phía WP");
                    }
                    break;

                case (int)IntegrationType.Shopify:
                    res = await new ShopifyService.ShopifyService(site.AccId, site.ApiKey).CountPage();
                    break;

                case (int)IntegrationType.Haravan:
                    res = await new HaravanService.HaravanService(site.ApiKey).CountPage();
                    break;

                case (int)IntegrationType.Sapo:
                    res = await new SapoService.SapoService(site.AccId, site.ApiKey).CountPage();
                    break;

                case (int)IntegrationType.Sms:
                    string sim     = string.IsNullOrEmpty(site.AccId) == false ? "sim1" : "sim2";
                    var    profile = uow.UserProfile.Get(userId);
                    var    mobile  = profile == null ? "0968152579" : profile.Mobile;
                    var    r       = new Services.SmsService().Send(site.Phone, site.Password, sim, mobile, $"Chao {profile.FullName}. Punnel sms dang dung tot nhe");
                    if (r == true)
                    {
                        res.Code = System.Net.HttpStatusCode.OK;
                    }
                    else
                    {
                        res.Code    = System.Net.HttpStatusCode.BadRequest;
                        res.Message = "Thiết thị không thể gửi tin nhắn sms. Vui lòng kiểm tra lại thiết bị & ứng dụng SMS đã cài đặt";
                    }
                    break;
                }
                if (res.Code != System.Net.HttpStatusCode.OK)
                {
                    site.IsExpired = true;
                    this.Commit();
                }
                else
                {
                    site.IsExpired = false;
                    this.Commit();
                }
            }
            return(res);
        }