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); }
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); }