Exemple #1
0
    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);
        }
    }