Exemplo n.º 1
0
        /// <summary>
        /// Constructs testimonial comment collection for calls to stored procedures that contain user defined table types.
        /// </summary>
        /// <param name="settings">Testimonial settings.</param>
        /// <returns>A populated testimonial comment collection.</returns>
        private TestimonialCommentCollection GetTestimonialCommentCollection(TestimonialSettings settings)
        {
            TestimonialCommentCollection testimonialCommentCollection = new TestimonialCommentCollection();

            foreach (TestimonialComment comment in settings.Comments)
            {
                testimonialCommentCollection.Add(comment);
            }
            return(testimonialCommentCollection);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates an element's details.
        /// </summary>
        /// <param name="settings">Updated element settings.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        public void Update(IElementSettings settings, IUnitOfWork unitOfWork = null)
        {
            // Ensure sort orders are correct
            TestimonialSettings testimonialSettings = (TestimonialSettings)settings;

            for (int index = 0; index < testimonialSettings.Comments.Count; index++)
            {
                TestimonialComment testimonialComment = testimonialSettings.Comments[index];
                testimonialComment.SortOrder   = index;
                testimonialComment.AuthorTitle = string.IsNullOrWhiteSpace(testimonialComment.AuthorTitle) ? string.Empty : testimonialComment.AuthorTitle.Trim();
                testimonialComment.CommentDate = string.IsNullOrWhiteSpace(testimonialComment.CommentDate) ? string.Empty : testimonialComment.CommentDate.Trim();
            }

            // Do the update
            _testimonialRepository.Update((TestimonialSettings)settings, unitOfWork);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves form for testimonial update.
        /// </summary>
        /// <param name="context">Form context.</param>
        /// <returns>Form object.</returns>
        private Form GetTestimonialForm(string context)
        {
            // Get tenant identifier
            long tenantId = _authenticationService.TenantId;

            // Get page and element identifiers
            string[] parts     = context.Split('|');
            long     pageId    = Convert.ToInt64(parts[0]);
            long     elementId = Convert.ToInt64(parts[1]);

            // Get current settings
            Guid elementTypeId           = FormId;
            TestimonialSettings settings = (TestimonialSettings)New(_authenticationService.TenantId);

            settings.ElementId = elementId;
            Read(settings);

            // Construct form
            Form form = new Form {
                Fields = new Dictionary <string, IFormField>(), Id = FormId.ToString(), Context = context, SubmitLabel = ElementResource.TestimonialUpdateButtonLabel
            };

            form.Fields.Add("displayName", new TextField
            {
                Name                  = "displayName",
                Label                 = ElementResource.TestimonialDisplayNameLabel,
                MaxLength             = TestimonialLengths.DisplayNameMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.TestimonialDisplayNameMaxLengthMessage, "displayName", TestimonialLengths.DisplayNameMaxLength)
            });
            form.Fields.Add("preamble", new MultiLineTextField
            {
                Name  = "preamble",
                Label = ElementResource.TestimonialPreambleLabel,
                Rows  = 4
            });

            // Create sub forms
            form.SubForms = new Dictionary <string, Form>();
            form.SubForms.Add("testimonialComment", GetTestimonialCommentForm(context));

            // Set testimonial settings as form data
            form.Data = JsonConvert.SerializeObject(settings);

            // Return form
            return(form);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Performs update of testimonial given submitted form data.
        /// </summary>
        /// <param name="form">Form containing updated testimonial data.</param>
        /// <returns>Result of form post.</returns>
        private FormResult UpdateTestimonial(Form form)
        {
            // Get master page details
            string[]            parts     = form.Context.Split('|');
            long                tenantId  = _authenticationService.TenantId;
            long                pageId    = Convert.ToInt64(parts[0]);
            long                elementId = Convert.ToInt64(parts[1]);
            TestimonialSettings settings  = JsonConvert.DeserializeObject <TestimonialSettings>(form.Data);

            settings.TenantId  = tenantId;
            settings.ElementId = elementId;

            // Do the update
            Update(settings);

            // Return form result with no errors
            return(_formHelperService.GetFormResult());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Populates element settings.
        /// </summary>
        /// <param name="settings">Element settings to be populated.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        public void Read(TestimonialSettings settings, IUnitOfWork unitOfWork = null)
        {
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                dbm.SetSQL(_sqlManager.GetSql("Sql.ReadTestimonial.sql"));
                dbm.AddParameter("@TenantId", FieldType.BigInt, settings.TenantId);
                dbm.AddParameter("@ElementId", FieldType.BigInt, settings.ElementId);
                dbm.ExecuteReader();
                dbm.Read();
                settings.DisplayName = (string)dbm.DataReaderValue("DisplayName");
                settings.Preamble    = (string)dbm.DataReaderValue("Preamble");
                settings.Comments    = new List <TestimonialComment>();
                dbm.Read();
                while (dbm.Read())
                {
                    settings.Comments.Add(new TestimonialComment
                    {
                        TenantId             = (long)dbm.DataReaderValue("TenantId"),
                        ElementId            = (long)dbm.DataReaderValue("ElementId"),
                        TestimonialCommentId = (long)dbm.DataReaderValue("TestimonialCommentId"),
                        SortOrder            = (int)dbm.DataReaderValue("SortOrder"),
                        Comment     = (string)dbm.DataReaderValue("Comment"),
                        Author      = (string)dbm.DataReaderValue("Author"),
                        AuthorTitle = (string)dbm.DataReaderValue("AuthorTitle"),
                        CommentDate = (string)dbm.DataReaderValue("CommentDate")
                    });
                }
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a testimonial element.
        /// </summary>
        /// <param name="settings">New element settings.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        public void Create(TestimonialSettings settings, IUnitOfWork unitOfWork = null)
        {
            TestimonialCommentCollection testimonialCommentCollection = GetTestimonialCommentCollection(settings);
            IUnitOfWork localUnitOfWork = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null;

            try
            {
                IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork ?? localUnitOfWork);
                dbm.SetSQL(_sqlManager.GetSql("Sql.CreateTestimonial.sql"));
                dbm.AddParameter("@TenantId", FieldType.BigInt, settings.TenantId);
                dbm.AddParameter("@ElementId", FieldType.BigInt, settings.ElementId);
                dbm.AddParameter("@DisplayName", FieldType.NVarChar, 256, settings.DisplayName);
                dbm.AddParameter("@Preamble", FieldType.NVarChar, -1, settings.Preamble);
                dbm.AddTypedParameter("@TestimonialComments", FieldType.Structured, testimonialCommentCollection.Count == 0 ? null : testimonialCommentCollection, "element.TestimonialCommentTableType");
                dbm.ExecuteNonQuery();
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Commit();
                }
            }
            catch
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw;
            }
            finally
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Dispose();
                }
            }
        }