예제 #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);
        }
예제 #2
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();
                }
            }
        }