private CheckHeaderRequestModel _checkHeaderRequest(IHeaderDictionary headers)
        {
            var result = new CheckHeaderRequestModel();

            if (!headers.ContainsKey("domain"))
            {
                result.statusCode = StatusCodes.Status400BadRequest;
                result.success    = false;
                result.message    = "Thiếu domain";

                return(result);
            }

            var configuration = new ConfigurationBuilder()
                                .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
                                .AddJsonFile("appsettings.json")
                                .Build();

            var domain        = headers.Where(x => x.Key == "domain").Select(x => x.Value).FirstOrDefault();
            var domainSetting = configuration.GetSection(domain).Get <DomainSettingModel>();

            var ANNconfig = configuration.GetSection("ANNconfig").Get <ANNConfigModel>();

            if (String.IsNullOrEmpty(domain))
            {
                result.statusCode = StatusCodes.Status400BadRequest;
                result.success    = false;
                result.message    = "Domain không được rỗng";

                return(result);
            }
            if (domainSetting == null)
            {
                result.statusCode = StatusCodes.Status500InternalServerError;
                result.success    = false;
                result.message    = String.Format("{0} chưa được cài đặt", domain);

                return(result);
            }

            RestAPI restAPI = new RestAPI(String.Format("https://{0}/wp-json/jwt-auth/v1/token", domain), domainSetting.username, domainSetting.password);

            //RestAPI restAPI = new RestAPI(String.Format("https://{0}/wp-json/wp/v2/", domain), domainSetting.wordpress_key, domainSetting.wordpress_secret, false);
            //restAPI.oauth_token = domainSetting.wordpress_oauth_token;
            //restAPI.oauth_token_secret = domainSetting.wordpress_oauth_token_secret;

            WPObject wpObject = new WPObject(restAPI);

            result.domain   = domain;
            result.success  = true;
            result.message  = String.Empty;
            result.rootPath = ANNconfig.root_path;
            result.wp       = new Models.Wordpress()
            {
                restAPI  = restAPI,
                wpObject = wpObject
            };
            return(result);
        }
        private async Task <Posts> _handleWPPost(PostClone postClone, WPObject wpObject, string domain, string rootFolder)
        {
            #region Category List
            var categories     = new List <int>();
            var wpPostCategory = await wpObject.Categories.GetAll(new Dictionary <string, string>() {
                { "per_page", "100" }
            });

            if (wpPostCategory.Count > 0)
            {
                int wpPostCategoryID = Convert.ToInt32(wpPostCategory.Where(x => x.name == postClone.CategoryName).Select(x => x.id).FirstOrDefault());
                if (wpPostCategoryID > 0)
                {
                    categories.Add(wpPostCategoryID);
                }
                else
                {
                    Categories newCategory = new Categories()
                    {
                        name        = postClone.CategoryName,
                        description = postClone.CategoryName,
                        parent      = 0,
                    };
                    var createCategory = await wpObject.Categories.Add(newCategory);

                    categories.Add(Convert.ToInt32(createCategory.id));
                }
            }
            #endregion

            #region Thumbnail
            int   featured_media  = 0;
            Media wpPostThumbnail = new Media();
            if (!String.IsNullOrEmpty(postClone.Thumbnail))
            {
                string thumbnailFileName = Path.GetFileName(postClone.Thumbnail);
                string filePath          = rootFolder + postClone.Thumbnail.Replace("/", @"\");
                if (System.IO.File.Exists(filePath))
                {
                    wpPostThumbnail = await wpObject.Media.Add(thumbnailFileName, filePath);

                    featured_media = (int)wpPostThumbnail.id;
                }
            }
            #endregion

            #region Content
            string content = postClone.Content;

            // Video
            string videoHTML = "";
            var    videoList = _service.getVideoByPostID(postClone.PostPublicID);
            if (videoList.Count > 0)
            {
                foreach (var item in videoList)
                {
                    videoHTML += String.Format("<iframe width='560' height='315' src='https://www.youtube.com/embed/{0}?controls=0' title='{1}' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe><br>", item.VideoId, postClone.Title);
                }
                content = videoHTML + content;
            }

            // Image
            if (!String.IsNullOrEmpty(wpPostThumbnail.source_url))
            {
                content = String.Format("<p><img src='{0}' alt='{1}' /></p>", wpPostThumbnail.source_url, postClone.Title) + content;
            }

            var postImage = _service.getPostImageByPostID(postClone.PostPublicID);
            if (postImage.Count > 0)
            {
                foreach (var item in postImage)
                {
                    string imageFileName = Path.GetFileName(item.Image);
                    string filePath      = rootFolder + item.Image.Replace("/", @"\");
                    if (System.IO.File.Exists(filePath))
                    {
                        var wpPostImage = await wpObject.Media.Add(imageFileName, filePath);

                        content += String.Format("<p><img src='/wp-content/uploads/{0}' alt='{1}' /></p>", System.IO.Path.GetFileName(wpPostImage.source_url), postClone.Title);
                    }
                }
            }
            #endregion

            return(new Posts()
            {
                title = postClone.Title,
                content = content,
                excerpt = postClone.Summary,
                featured_media = featured_media,
                categories = categories,
                status = "publish"
            });
        }