コード例 #1
0
        public async Task <IHttpActionResult> PublishPage([FromBody] PublishRequestModel value)
        {
            try
            {
                if (this.Level == (int)ProfileLevel.Trial || this.Level == (int)ProfileLevel.Economy)
                {
                    var totalPublish = await _uow.LandingPage.CountPublishPageAsync(this.CurrentUserId);

                    if (this.Level == (int)ProfileLevel.Trial && totalPublish == 0)
                    {
                        //Set 14 ngày miễn phí cho user lần đầu xuất bản trang.
                        await _uow.UserProfile.SetExpiredDate(this.CurrentUserId, DateTime.Today.AddDays(14));
                    }
                    if (totalPublish > 3)
                    {
                        return(BadRequest(this.RequiredUpgrade_MaxPage_Err));
                    }
                }
                var res = await _uow.LandingPage.PublishDns(value, CurrentUserId);

                return(Ok(res));
            }
            catch (BusinessException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                return(BadRequest(this.General_Err));
            }
        }
コード例 #2
0
 public IHttpActionResult MakeDownloadUrl([FromBody] PublishRequestModel value)
 {
     try
     {
         Guid id = Guid.NewGuid();
         _uow.DownloadPage.IU(new Core.Entities.Model.DownloadPage()
         {
             Id            = id,
             UserId        = CurrentUserId,
             LandingPageId = value.id,
             Html          = value.html
         });
         return(Ok(id));
     }
     catch (BusinessException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch (Exception ex)
     {
         _log.Error(ex);
         return(BadRequest(this.General_Err));
     }
 }
コード例 #3
0
        public async Task <PublishPageResponseModel> PublishDns(PublishRequestModel model, string userId)
        {
            PublishPageResponseModel response = new PublishPageResponseModel();
            var m = _dbSet.FirstOrDefault(x => x.Id == model.id && x.UserId == userId);

            if (m == null)
            {
                throw new BusinessException(Messages.LandingPage_NotFound);
            }
            if (model.type > 0)
            {
                m.PublishType = model.type;
            }

            if (m.PublishIntegrationId.HasValue && m.Publish == true)
            {
                var itg = uow.Integration.Get(m.PublishIntegrationId.Value);
                if (itg != null)
                {
                    //ftp
                    if (m.Publish && m.PublishType == (int)PublishType.Ftp)
                    {
                        if (m.PublishIntegrationId == null)
                        {
                            throw new BusinessException("Vui lòng xem lại cấu hình kết nối Ftp");
                        }
                        PublishExternalRequestModel data = new PublishExternalRequestModel()
                        {
                            Html          = model.html,
                            PageId        = model.id,
                            PathUrl       = m.UrlCode,
                            IntegrationId = m.PublishIntegrationId.Value
                        };
                        await uow.UserProfile.SetUserStatusNote(m.UserId, LeadStatus.Hot, "Xuất bản Ftp");

                        return(await uow.Integration.Ftp_IU(data, userId));
                    }

                    //wordpress
                    if (m.Publish && m.PublishType == (int)PublishType.WP)
                    {
                        if (m.PublishIntegrationId == null)
                        {
                            throw new BusinessException("Vui lòng xem lại cấu hình kết nối Wordpress");
                        }
                        PublishExternalRequestModel data = new PublishExternalRequestModel()
                        {
                            Html          = model.html,
                            PageId        = model.id,
                            PathUrl       = m.UrlCode,
                            IntegrationId = m.PublishIntegrationId.Value
                        };
                        await uow.UserProfile.SetUserStatusNote(m.UserId, LeadStatus.Hot, "Xuất bản wordpress");

                        return(await uow.Integration.WP_IU(data, userId));

                        //return await uow.Integration.WP_IU(model.id, m.Name, model.html);
                    }

                    //shopify
                    if (m.Publish && m.PublishType == (int)PublishType.Shopify)
                    {
                        if (m.PublishIntegrationId == null)
                        {
                            throw new BusinessException("Vui lòng xem lại cấu hình kết nối Shopify");
                        }
                        PublishExternalRequestModel data = new PublishExternalRequestModel()
                        {
                            Html          = model.html,
                            PageId        = model.id,
                            PathUrl       = m.UrlCode,
                            IntegrationId = m.PublishIntegrationId.Value
                        };
                        await uow.UserProfile.SetUserStatusNote(m.UserId, LeadStatus.Hot, "Xuất bản shopify");

                        return(await uow.Integration.Shopify_IU(data, userId));
                    }

                    //haravan
                    if (m.Publish && m.PublishType == (int)PublishType.Haravan)
                    {
                        if (m.PublishIntegrationId == null)
                        {
                            throw new BusinessException("Vui lòng xem lại cấu hình kết nối Haravan");
                        }
                        PublishExternalRequestModel data = new PublishExternalRequestModel()
                        {
                            Html          = model.html,
                            PageId        = model.id,
                            PathUrl       = m.UrlCode,
                            IntegrationId = m.PublishIntegrationId.Value
                        };
                        await uow.UserProfile.SetUserStatusNote(m.UserId, LeadStatus.Hot, "Xuất bản haravan");

                        return(await uow.Integration.Haravan_IU(data, userId));
                    }

                    //sapo
                    if (m.Publish && m.PublishType == (int)PublishType.Sapo)
                    {
                        if (m.PublishIntegrationId == null)
                        {
                            throw new BusinessException("Vui lòng xem lại cấu hình kết nối Sapo");
                        }
                        PublishExternalRequestModel data = new PublishExternalRequestModel()
                        {
                            Html          = model.html,
                            PageId        = model.id,
                            PathUrl       = m.UrlCode,
                            IntegrationId = m.PublishIntegrationId.Value
                        };
                        await uow.UserProfile.SetUserStatusNote(m.UserId, LeadStatus.Hot, "Xuất bản sapo");

                        return(await uow.Integration.Sapo_IU(data, userId));
                    }
                }
                else
                {
                    m.Publish    = false;
                    m.Domain     = null;
                    m.BaseDomain = PUBLISH_DOMAIN;
                    model.domain = null;
                }
            }

            bool isFirstPublish = (m.Publish == false || string.IsNullOrEmpty(model.domain));

            var hasBaseDomain = (string.IsNullOrEmpty(m.BaseDomain) == false);

            model.domain = string.IsNullOrEmpty(model.domain) ? PUBLISH_DOMAIN : model.domain;
            model.domain = model.domain.Replace("www.", "");
            if (IsValidUri("http://" + model.domain) == false)
            {
                throw new BusinessException("Tên miền không hợp lệ!");
            }

            Uri u = new Uri("http://" + model.domain);


            bool   isHostChanged = (u.Host != m.BaseDomain);
            string old_domain    = m.BaseDomain;
            string old_UrlCode   = m.UrlCode;

            m.BaseDomain = u.Host;
            string path_name = u.LocalPath.Replace("/", "");

            if (string.IsNullOrEmpty(path_name) && IsSystemPublishDomain(m.BaseDomain))
            {
                if (string.IsNullOrEmpty(m.Name) == true)
                {
                    m.Name = "Tiêu đề trang";
                }
                m.UrlCode = MakeUrlCode(m.BaseDomain, m.Name);
            }
            else
            {
                if (uow.Domain.IsNotOwner(m.BaseDomain, userId) == true && IsSystemPublishDomain(m.BaseDomain) == false)
                {
                    throw new BusinessException(string.Format("{0} đã được sử dụng!", m.BaseDomain));
                }

                var exists = _dbSet.AsNoTracking().Any(x => x.Deleted == false && x.BaseDomain == m.BaseDomain && x.UrlCode == path_name && x.UserId == userId && x.Id != model.id);
                if (exists)
                {
                    throw new BusinessException(string.Format("{0} đã được sử dụng cho landing page khác", model.domain));
                }
                m.UrlCode = path_name;
            }

            var res = new Core.BLL.FileServices.FileBuilder(m.BaseDomain, m.UrlCode, model.html).Create(m.Id.ToString());

            if (model.domain != m.Domain && !string.IsNullOrEmpty(old_domain))
            {
                new Core.BLL.FileServices.FileBuilder(old_domain, old_UrlCode, "").Remove();
            }

            string urlFolderPath = u.Host;

            //Nếu user cấu hình domain mới => kiểm tra IIS
            bool hasTracking = true;

            if (!string.IsNullOrEmpty(m.BaseDomain) && isHostChanged && IsSystemPublishDomain(m.BaseDomain) == false)
            {
                if (isHostChanged)
                {
                    //Kiem tra domain da tro ve DNS server?
                    uow.Domain.Verify(m.BaseDomain, userId);
                    //Tracking với domain ngoài
                    hasTracking = false;
                }
                var pagesInDomain = await GetByBaseDomain(old_domain);

                var iisService = new Services.IISService();
                if (pagesInDomain.Count <= 1 && IsSystemPublishDomain(old_domain) == false)
                {
                    var path = await iisService.ChangeWebsite(old_domain, m.BaseDomain);
                }
                else
                {
                    var path = await iisService.AddWebsite(m.BaseDomain);
                }
                // create Web on IIS
                //if (path != "") res = path;
            }

            //var iisService1 = new Services.IISService();
            //iisService1.ChangeWebsite(m.BaseDomain);

            m.PublishType = (int)PublishType.Dns;//IsSystemPublishDomain(m.BaseDomain) ? (int)PublishType.Demo : (int)PublishType.Domain;
            m.Domain      = res;
            if (!string.IsNullOrEmpty(model.source))
            {
                m.Source = model.source;
            }
            m.Publish     = true;
            m.PublishDate = DateTime.Now;
            m.UpdatedDate = DateTime.Now;
            await this.CommitAsync();

            this.RemoveCache(m.Id, "p");
            if (isFirstPublish || hasTracking == false)
            {
                try
                {
                    await uow.UserProfile.SetUserStatusNote(m.UserId, LeadStatus.Hot, "Đã xuất bản domain");

                    //uow.TaskQueue.AddTask(new TaskQueue()
                    //{
                    //    Data = m.Id.ToString(),
                    //    Type = (int)Entities.TaskQueueType.UpdatePageContent,
                    //    CreatedDate = DateTime.Now,
                    //    UpdatedDate=DateTime.Now
                    //});
                }catch (Exception ex)
                {
                }
            }
            else if (IsSystemPublishDomain(m.BaseDomain) && isHostChanged)
            {
                try
                {
                    await uow.UserProfile.SetUserStatusNote(m.UserId, LeadStatus.Warm, "Đã xuất bản trang");
                }
                catch (Exception ex)
                {
                }
            }



            if (hasTracking == false)
            {
                uow.PublishPage.IU(new PublishPage()
                {
                    Id          = m.Id,
                    UrlPath     = urlFolderPath,
                    HasTracking = hasTracking,
                    CreatedDate = DateTime.Now,
                    UpdatedDate = DateTime.Now
                });
            }

            response.FullUrl              = res;
            response.PathUrl              = m.UrlCode;
            response.BaseDomain           = m.BaseDomain;
            response.Type                 = m.PublishType;
            response.PublishIntegrationId = m.PublishIntegrationId;
            return(response);
        }