protected void btnUpload_Click(object sender, EventArgs e) { Article article = DocoManager.GetArticleByName(ArticleName, true); article.FileName = UploadFile(article.Category.Id); DocoManager.UpdateArticle(article, false); }
/// <summary> /// Retrieves a URL friendly string that points to an article. /// </summary> /// <param name="name">The name of the article</param> /// <returns>A user friendly Url for the article</returns> protected string GetViewArticleUrl(string name) { // If it is an uploaded document, then view the document and set the acknowledged flag // to true (via audit). Article article = DocoManager.GetArticleByName(name, false); if (article.IsUpload) { if (!article.Acknowledged) { // todo Popup to say that this will be acknowledged. AuditManager.Audit(Page.User.Identity.Name, article.Id + article.Version.ToString(CultureInfo.InvariantCulture), AuditRecord.AuditAction.Acknowledged); } string root = Server.MapPath(System.IO.Path.Combine("../Doco/", System.Web.Configuration.WebConfigurationManager.AppSettings.Get(Resource.Root))); string path = string.Format( CultureInfo.InvariantCulture, Resource.NewObjectPath, root, article.Category.Id); if (!string.IsNullOrEmpty(article.FileName)) { string url = string.Format( CultureInfo.InvariantCulture, Resource.DocoFilesLoc + Resource.FileOpen, UrlEncoding.Encode(System.IO.Path.Combine(path, article.FileName))); return(url); } else { return(string.Empty); } } else { return(Navigation.Doco_ViewArticle(name, 0).GetClientUrl(this, true) + "&cMode=pub&id=" + article.Category.Id); } }
protected void btSave_Click(object sender, EventArgs e) { try { if (txtTitle.Text.Length >= 100) { ((IFeedback)Page.Master).SetError(GetType(), "The document name must be less than 100 characters long"); return; } Category category = DocoManager.GetCategory(CategoryId); //check for uploaded or online bool isUploaded = rbListDocoType.SelectedValue.ToLower().Equals("uploaded") ? true : false; bool isAckRequired = rblAcknowledge.SelectedValue.ToLower().Equals("required") ? true : false; bool isNumbChaps = false; if (!isUploaded) { isNumbChaps = rblChapNumbs.SelectedValue.ToLower().Equals("yes") ? true : false; } if (isUploaded) { if (!fuUpload.HasFile) { ((IFeedback)Page.Master).SetError(GetType(), "You must add a file for an uploaded document"); return; } } if (SecurityHelper.CheckWriteAccess(Page.User.Identity.Name, category.Id)) { // Check whether this article name is in use, because there is a unique name restriction. Article oldArticle = DocoManager.GetArticleByName(txtTitle.Text, false); if (oldArticle != null) { ((IFeedback)Page.Master).SetError(GetType(), "An document with this name already exists. You must have a unique name for the document"); return; } string owner = Utilities.GetUserName(Page.User.Identity.Name); DocoManager.CreateArticle(category, owner, txtTitle.Text, !string.IsNullOrEmpty(fuUpload.FileName) ? fuUpload.FileName : string.Empty, txtTitle.Text, txtDescription.Text, null, isUploaded, true, isNumbChaps, isAckRequired); ((IFeedback)Page.Master).QueueFeedback( BusiBlocksConstants.Blocks.Documents.LongName, "Document", Feedback.Actions.Saved, txtTitle.Text ); } else { throw new InvalidPermissionException("insert an article"); } if (isUploaded) { string path = string.Format( CultureInfo.InvariantCulture, Resource.NewObjectPath, _root, category.Id); UploadFile(category.Id); Navigation.Doco_Default().Redirect(this); } else { // Edit the online article. Navigation.Doco_ViewArticle(txtTitle.Text, 0, category.Id, "draft").Redirect(this); } } catch (Exception ex) { throw ex; ((IFeedback)Master).SetException(GetType(), ex); } }
protected void btCancel_Click(object sender, EventArgs e) { Article article = DocoManager.GetArticleByName(ArticleName, true); Navigation.Doco_ViewCategory(article.Category.Id).Redirect(this); }
protected void Page_Load(object sender, EventArgs e) { Article article = DocoManager.GetArticleByName(ArticleName, true); if (!IsPostBack) { txtDescription.Text = article.Description; //txtEditorialComment.Text = string.Empty; txtTitle.Text = article.Title; txtOwner.Text = Utilities.GetDisplayUserName(article.Owner); txtAuthor.Text = Utilities.GetDisplayUserName(article.Author); IList <Category> viewableCategories = GetAllEditableCategories(); cmbCategory.DataSource = viewableCategories; cmbCategory.DataTextField = "Breadcrumb"; cmbCategory.DataBind(); if (article.Category == null) { cmbCategory.SelectedIndex = -1; } else { var index = from x in viewableCategories where x.Id.Equals(article.Category.Id) select viewableCategories.IndexOf(x); if (index.Any()) { cmbCategory.SelectedIndex = index.First(); } } if (article.NumberedChaps) { rblNumberedChapters.Items[0].Selected = true; } else { rblNumberedChapters.Items[1].Selected = true; } if (article.RequiresAck) { rblAcknowledge.Items[1].Selected = true; } else { rblAcknowledge.Items[0].Selected = true; } } if (article.IsUpload) { rbListDocoType.Items[1].Selected = true; rowUploadFile.Visible = true; rowNumberedChapters.Visible = false; lnkFilename.Text = article.FileName; lnkFilename.NavigateUrl = GetViewArticleUrl(article.Id); } else { rbListDocoType.Items[0].Selected = true; } pmm.LoadPermissionsView(article.Category.Id, article.Category.DisplayName); }
protected void btSave_Click(object sender, EventArgs e) { try { if (txtTitle.Text.Length >= 100) { ((IFeedback)Page.Master).SetError(GetType(), "The announcement title must be less than 100 characters long"); return; } Article article = DocoManager.GetArticleByName(ArticleName, true); //Check permissions if (BusiBlocks.SecurityHelper.CheckWriteAccess(Page.User.Identity.Name, article.Category.Id) == false) { throw new BusiBlocks.InvalidPermissionException("edit the article"); } var xhtml = new BusiBlocks.XHTMLText(); Exception validateError; if (xhtml.IsValid(article.Category.XHtmlMode, out validateError) == false) { throw new BusiBlocks.TextNotValidException(validateError); } article.TOC = null; article.Description = txtDescription.Text; article.Title = txtTitle.Text; article.UpdateUser = Utilities.GetUserName(Page.User.Identity.Name); article.Author = txtAuthor.Text; article.NumberedChaps = rblNumberedChapters.SelectedValue.ToLower().Equals("yes") ? true : false; article.RequiresAck = rblAcknowledge.SelectedValue.ToLower().Equals("required") ? true : false; //if (!string.IsNullOrEmpty(txtEditorialComment.Text)) // article.Body += txtEditorialComment.Text + " - <b>(" + DateTime.Now + ")</b><br/>"; // currently using article.body as editorial comments. IList <Category> categories = GetAllEditableCategories(); Category selectedCategory = categories[cmbCategory.SelectedIndex]; if (!selectedCategory.Id.Equals(article.Category.Id)) { Category newCategory = categories[cmbCategory.SelectedIndex]; // Need to also physically move the document into the new category if it is an uploaded document. if (article.IsUpload) { // Create the path for the new file. string root = Path.Combine(Path.Combine(Server.MapPath("~"), "Doco"), "Files"); string oldCategoryPath = Path.Combine(root, article.Category.Id); string newCategoryPath = Path.Combine(root, newCategory.Id); string oldPath = Path.Combine(oldCategoryPath, article.FileName); string newPath = Path.Combine(newCategoryPath, article.FileName); if (!Directory.Exists(newCategoryPath)) { Directory.CreateDirectory(newCategoryPath); } File.Move(oldPath, newPath); } article.Category = newCategory; } DocoManager.UpdateArticle(article, false); ((IFeedback)Page.Master).QueueFeedback( BusiBlocksConstants.Blocks.Documents.LongName, "Document", Feedback.Actions.Saved, article.Name ); Navigation.Doco_Default().Redirect(this); } catch (Exception ex) { throw ex; ((IFeedback)Master).SetException(GetType(), ex); } }