예제 #1
0
        public IActionResult Deploy([FromODataUri] string owner)
        {
            // User
            string usrName = "";

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            if (!string.IsNullOrEmpty(owner))
            {
                if (String.CompareOrdinal(owner, usrName) != 0)
                {
                    throw new UnauthorizedAccessException();
                }
            }

            var setting = _context.BlogUserSettings.SingleOrDefault(p => p.Owner == usrName);

            if (setting == null)
            {
                throw new NotFoundException("Owner not found");
            }

            var errstr = "";

            try
            {
                BlogDeployUtility.UpdatePostSetting(setting);
            }
            catch (Exception exp)
            {
                errstr = exp.Message;
            }

            // Return
            if (!string.IsNullOrEmpty(errstr))
            {
                throw new Exception(errstr);
            }

            return(Ok(""));
            //if (string.IsNullOrEmpty(errstr))
            //{

            //    return Ok();
            //}

            //throw new Exception(errstr);
        }
예제 #2
0
        public IActionResult ClearDeploy(int key)
        {
            // User
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check setting
            var setting = _context.BlogUserSettings.SingleOrDefault(p => p.Owner == usrName);

            if (setting == null)
            {
                throw new BadRequestException(" User has no setting ");
            }

            var errstr = "";

            try
            {
                BlogDeployUtility.RevokePostDeliver(setting.DeployFolder, key);
            }
            catch (Exception exp)
            {
                errstr = exp.Message;
            }

            // Return
            if (!string.IsNullOrEmpty(errstr))
            {
                throw new Exception(errstr);
            }

            return(Ok(""));
            //throw new Exception(errstr);
        }
예제 #3
0
        public IActionResult Deploy(int key)
        {
            var cc = _context.BlogPosts.Find(key);

            if (cc == null)
            {
                throw new NotFoundException("HIHAPI: Record not found");
            }

            // User
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
                if (String.CompareOrdinal(cc.Owner, usrName) != 0)
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check setting
            var setting = _context.BlogUserSettings.SingleOrDefault(p => p.Owner == usrName);

            if (setting == null)
            {
                throw new BadRequestException(" User has no setting ");
            }

            // Collections
            cc.BlogPostCollections = _context.BlogPostCollections.Where(p => p.PostID == cc.ID).ToList();
            // Tags
            cc.BlogPostTags = _context.BlogPostTags.Where(p => p.PostID == cc.ID).ToList();

            var errstr = "";

            try
            {
                if (cc.Status == BlogPost.BlogPostStatus_PublishAsPublic)
                {
                    BlogDeployUtility.DeployPost(setting.DeployFolder, cc, _context.BlogCollections.Where(p => p.Owner == usrName).ToList());
                }
                else
                {
                    BlogDeployUtility.RevokePostDeliver(setting.DeployFolder, cc.ID);
                }
            }
            catch (Exception exp)
            {
                errstr = exp.Message;
            }

            if (!string.IsNullOrEmpty(errstr))
            {
                throw new Exception(errstr);
            }

            return(Ok(""));

            //if (string.IsNullOrEmpty(errstr))
            //{
            //    return Ok();
            //}

            //throw new Exception(errstr);
        }