Esempio n. 1
0
        private bool SavePost()
        {
            if (!FormValidation())
            {
                return(false);
            }

            //Only exports part of the generated HTML document by RichEditControlDescription.HTMLText
            var options = new HtmlDocumentExporterOptions();

            options.ExportRootTag           = ExportRootTag.Body;
            options.CssPropertiesExportType = CssPropertiesExportType.Inline;
            options.DefaultCharacterPropertiesExportToCss = false;
            var    exporter             = new HtmlExporter(RichEditControlDescription.Model, options);
            string formattedDescription = exporter.Export();

            if (_post == null)
            {
                _post = new Post(Environment.UserName, TitleTextBox.Text, formattedDescription);
            }
            else
            {
                _post = new Post(_post.Id, _post.Author, TitleTextBox.Text, formattedDescription, _post.LastModifiedTime);
            }

            try
            {
                try
                {
                    _dataConnection.AddOrUpdatePost(_post);
                    Close();
                }
                catch (ModifiedByOtherUserException ex)
                {
                    if (MessageBox.Show(this,
                                        "The post was modified by some other user. Do you want to overwrite those changes?",
                                        this.Text,
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                    {
                        return(false);
                    }

                    _dataConnection.AddOrUpdatePost(_post, true);
                    Close();
                }
                catch (TitleAlreadyPresentInDBException ex)
                {
                    MessageBox.Show(this, ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, $"Fallimento nell'inserimento del post: {ex.Message}", this.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            return(true);
        }