Exemple #1
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void BtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                // create and save unpublished testimonial
                var context        = TestimonialsContext.Get();
                var newTestimonial = new Testimonial();
                newTestimonial.Name      = Name.Text;
                newTestimonial.UrlName   = Regex.Replace(Name.Text.ToLower(), UrlNameCharsToReplace, UrlNameReplaceString);
                newTestimonial.Summary   = Summary.Text;
                newTestimonial.Text      = Text.Value.ToString();
                newTestimonial.Rating    = Rating.Value;
                newTestimonial.Published = this.AutoPublish;
                context.Add(newTestimonial);

                context.SaveChanges();

                if (this.AutoPublish)
                {
                    Status.Text = "<p><strong>Your testimonial has been submitted successfully!</p>";
                }
                else
                {
                    Status.Text = "<p><strong>Your testimonial has been submitted successfully! Please allow 24 hours for review by the administration.</p>";
                }

                // reset form
                Name.Text    = string.Empty;
                Summary.Text = string.Empty;
                Text.Value   = string.Empty;
                Rating.Value = 0;
            }
            catch (Exception)
            {
                Status.Text = "<p><em>An error occurred while submitting your testimonial. Please try again.</p>";
            }
        }
Exemple #2
0
        private void CreateSampleWorker(object[] args)
        {
            SampleUtilities.CreateUsersAndRoles();
            SampleUtilities.RegisterTheme(SamplesThemeName, SamplesThemePath);
            SampleUtilities.RegisterTemplate(new Guid(SamplesTemplateId), SamplesTemplateName, SamplesTemplateName, SamplesTemplatePath, SamplesThemeName);

            // Create Testimonials home page
            var result = SampleUtilities.CreatePage(new Guid(HomePageID), "Home", true);

            if (result)
            {
                SampleUtilities.SetTemplateToPage(new Guid(HomePageID), new Guid(SamplesTemplateId));

                // add welcome and instructions to page
                var generalInformationBlock = new ContentBlock();
                generalInformationBlock.Html = @"<h1>Testimonials Intra-Site Module Example</h1><p>This is the home page for the Testimonials Intra-Site module. Below is the Testimonials View Widget. It has a property to set a <a href=""testimonials"">separate page</a> for the details view.</p><p>On <a href=""testimonials"">the testimonials page</a> is a separate Testimonials View Widget that uses its own page as the details page.</p><p>This allows you to have multiple instances of the same content lists, all pointing to the same details page.</p>";

                SampleUtilities.AddControlToPage(new Guid(HomePageID), generalInformationBlock, "Content", "Content block");

                // create Testimonials View
                var mgr  = PageManager.GetManager();
                var ctrl = mgr.CreateControl <PageControl>("~/Modules/Testimonials/TestimonialsView.ascx", "Content");
                ctrl.Caption = "TestimonialsView";

                // set details page to Testimonials Page
                var prop = ctrl.Properties.FirstOrDefault(p => p.Name == "DetailsPageID");
                if (prop == null)
                {
                    prop      = new ControlProperty();
                    prop.Id   = Guid.NewGuid();
                    prop.Name = "DetailsPageID";
                    ctrl.Properties.Add(prop);
                }

                // the ID is needed for the control to be duplicated
                var idProp = ctrl.Properties.FirstOrDefault(p => p.Name == "ID");
                if (idProp == null)
                {
                    idProp      = new ControlProperty();
                    idProp.Id   = Guid.NewGuid();
                    idProp.Name = "ID";
                    ctrl.Properties.Add(idProp);
                }

                prop.Value   = TestimonialsPageID;
                idProp.Value = "TestimonialsView";

                SampleUtilities.AddControlToPage(new Guid(HomePageID), ctrl, "Content");
            }

            // Create Testimonials list/details page
            result = SampleUtilities.CreatePage(new Guid(TestimonialsPageID), "Testimonials", false);
            if (result)
            {
                SampleUtilities.SetTemplateToPage(new Guid(TestimonialsPageID), new Guid(SamplesTemplateId));
                SampleUtilities.AddControlToPage(new Guid(TestimonialsPageID), "~/Modules/Testimonials/TestimonialsView.ascx", "Content", "TestimonialsView");
            }

            // "Submit Testimonial" page
            result = SampleUtilities.CreatePage(new Guid(SubmitTestimonialPageID), "Submit", false);
            if (result)
            {
                SampleUtilities.SetTemplateToPage(new Guid(SubmitTestimonialPageID), new Guid(SamplesTemplateId));
                SampleUtilities.AddControlToPage(new Guid(SubmitTestimonialPageID), "~/Modules/Testimonials/SubmitTestimonial.ascx", "Content", "SubmitTestimonial");
            }

            // create sample testimonials
            var context = TestimonialsContext.Get();

            if (context.Testimonials.Count() > 0)
            {
                return;
            }

            context.Add(new Testimonial()
            {
                Name       = "John Doe",
                Rating     = 5,
                Summary    = "What a great product!",
                Text       = TESIMONIAL_TEXT,
                DatePosted = DateTime.Now,
                Published  = true,
                UrlName    = "john-doe"
            });
            context.Add(new Testimonial()
            {
                Name       = "Jane Doe",
                Rating     = 4,
                Summary    = "A solid product, almost perfect!",
                Text       = TESIMONIAL_TEXT,
                DatePosted = DateTime.Now,
                Published  = true,
                UrlName    = "jane-doe"
            });
            context.Add(new Testimonial()
            {
                Name       = "Jim Doe",
                Rating     = 3,
                Summary    = "Not bad; worth my time but could use a few more features.",
                Text       = TESIMONIAL_TEXT,
                DatePosted = DateTime.Now,
                Published  = true,
                UrlName    = "jim-doe"
            });
            context.SaveChanges();
        }