Skip to content

Commit

Permalink
Added contact page type example
Browse files Browse the repository at this point in the history
  • Loading branch information
fschultz committed Jan 15, 2017
1 parent 838bfd9 commit d8bdc25
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 1 deletion.
Binary file modified App_Data/kalikocms.db3
Binary file not shown.
13 changes: 13 additions & 0 deletions Business/ViewModelBuilders/ContactPageViewModelBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace DemoSite.Business.ViewModelBuilders {
using Models.Pages;
using Models.ViewModels;

public class ContactPageViewModelBuilder {
public static ContactPageViewModel Create(ContactPage currentPage) {
var model = new ContactPageViewModel(currentPage);
PageViewModelBuilder.SetBaseProperties(model);

return model;
}
}
}
28 changes: 28 additions & 0 deletions Controllers/ContactPageController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace DemoSite.Controllers {
using System.Web.Mvc;
using Business.ViewModelBuilders;
using KalikoCMS.Mvc.Framework;
using Models.Pages;
using Models.ViewModels;

public class ContactPageController : PageController<ContactPage> {
public override ActionResult Index(ContactPage currentPage) {
var model = ContactPageViewModelBuilder.Create(currentPage);
return View(model);
}

public ActionResult SendMessage(ContactPage currentPage, ContactPageFormData formData) {
var model = ContactPageViewModelBuilder.Create(currentPage);

if (ModelState.IsValid) {
// Do your magic here to send the message as you see fit, for instance using https://sendgrid.com

// Then display the "thank you"-message
return View("ThankYou", model);
}

model.FormData = formData;
return View("Index", model);
}
}
}
6 changes: 6 additions & 0 deletions DemoSite.Mvc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,15 @@
<Compile Include="App_Start\Startup.Auth.cs" />
<Compile Include="Business\FakeStore\FakeProductDatabase.cs" />
<Compile Include="Business\FakeStore\Product.cs" />
<Compile Include="Business\ViewModelBuilders\ContactPageViewModelBuilder.cs" />
<Compile Include="Business\ViewModelBuilders\SearchPageViewModelBuilder.cs" />
<Compile Include="Business\ViewModelBuilders\StartPageViewModelBuilder.cs" />
<Compile Include="Business\ViewModelBuilders\NewsListPageViewModelBuilder.cs" />
<Compile Include="Business\ViewModelBuilders\ProductListPageViewModelBuilder.cs" />
<Compile Include="Business\ViewModelBuilders\PageViewModelBuilder.cs" />
<Compile Include="Business\ViewModelBuilders\NewsPageViewModelBuilder.cs" />
<Compile Include="Controllers\ArticlePageController.cs" />
<Compile Include="Controllers\ContactPageController.cs" />
<Compile Include="Controllers\NewsListPageController.cs" />
<Compile Include="Controllers\NewsPageController.cs" />
<Compile Include="Controllers\ProductListPageController.cs" />
Expand All @@ -384,12 +386,14 @@
</Compile>
<Compile Include="Models\DemoSite.cs" />
<Compile Include="Models\Pages\ArticlePage.cs" />
<Compile Include="Models\Pages\ContactPage.cs" />
<Compile Include="Models\Pages\NewsListPage.cs" />
<Compile Include="Models\Pages\NewsPage.cs" />
<Compile Include="Models\Pages\ProductListPage.cs" />
<Compile Include="Models\Pages\SearchPage.cs" />
<Compile Include="Models\Pages\StartPage.cs" />
<Compile Include="Models\TabGroups.cs" />
<Compile Include="Models\ViewModels\ContactPageViewModel.cs" />
<Compile Include="Models\ViewModels\SearchPageViewModel.cs" />
<Compile Include="Models\ViewModels\StartPageViewModel.cs" />
<Compile Include="Models\ViewModels\ProductListPageViewModel.cs" />
Expand Down Expand Up @@ -449,6 +453,8 @@
<Content Include="Admin\Assets\fonts\hind\hind-bold-webfont.woff" />
<Content Include="Admin\Assets\fonts\hind\hind-bold-webfont.ttf" />
<Content Include="Admin\Assets\fonts\hind\hind-bold-webfont.eot" />
<Content Include="Views\ContactPage\Index.cshtml" />
<Content Include="Views\ContactPage\ThankYou.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
Expand Down
2 changes: 1 addition & 1 deletion Models/DemoSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using KalikoCMS.PropertyType;
using Pages;

[SiteSettings(AllowedTypes = new[] { typeof(NewsListPage), typeof(StartPage), typeof(ProductListPage), typeof(ArticlePage), typeof(SearchPage) })]
[SiteSettings(AllowedTypes = new[] { typeof(NewsListPage), typeof(StartPage), typeof(ProductListPage), typeof(ArticlePage), typeof(SearchPage), typeof(ContactPage) })]
public class DemoSite : CmsSite {
[Property("Company name")]
public virtual StringProperty CompanyName { get; set; }
Expand Down
21 changes: 21 additions & 0 deletions Models/Pages/ContactPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace DemoSite.Models.Pages {
using KalikoCMS.Attributes;
using KalikoCMS.Core;
using KalikoCMS.PropertyType;

// This is a sample contact form and shows how to post to a secondary action in your page controller
[PageType("ContactPage", "Contact page", PageTypeDescription = "Used for contact form", PreviewImage = "/Assets/Images/contactpage.png")]
public class ContactPage : CmsPage {
[Property("Headline")]
public virtual StringProperty Headline { get; set; }

[Property("Main body")]
public virtual HtmlProperty MainBody { get; set; }

[Property("Thank you-message")]
public virtual HtmlProperty ThankYouMessage { get; set; }

[Property("Where to send the mail")]
public virtual StringProperty MailToAddress { get; set; }
}
}
39 changes: 39 additions & 0 deletions Models/ViewModels/ContactPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace DemoSite.Models.ViewModels {
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using KalikoCMS;
using KalikoCMS.Core;
using Pages;

public class ContactPageViewModel : IPageViewModel<ContactPage> {
public ContactPageViewModel(ContactPage currentPage) {
CurrentPage = currentPage;
CurrentSite = SiteFactory.CurrentSite<DemoSite>();
FormData = new ContactPageFormData();
}

public ContactPage CurrentPage { get; private set; }
public DemoSite CurrentSite { get; private set; }
public IEnumerable<CmsPage> TopMenu { get; set; }
public ContactPageFormData FormData { get; set; }
}

public class ContactPageFormData {
[Required]
[Display(Name = "Name")]
public string Name { get; set; }

[Required]
[EmailAddress]
[Display(Name = "E-mail")]
public string EmailAddress { get; set; }

[Required]
[Display(Name = "Subject")]
public string Subject { get; set; }

[Required]
[Display(Name = "Message")]
public string Message { get; set; }
}
}
39 changes: 39 additions & 0 deletions Views/ContactPage/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@using KalikoCMS
@using KalikoCMS.Mvc.Extensions
@model DemoSite.Models.ViewModels.ContactPageViewModel

@{
Layout = "~/Views/Shared/_Layout.cshtml";
}

@Html.Partial("~/Views/Partials/BreadCrumbsView.cshtml", Model)

<div class="row">
<div class="left-menu col-lg-3">
@Html.MenuTreeFor(Model.CurrentPage, PageFactory.GetPage(Model.CurrentPage.RootId), new { @class = "nav nav-pills nav-stacked", selectedItemClass = "active" })
</div>
<div class="col-lg-6">
<h1>@Model.CurrentPage.Headline</h1>
@Model.CurrentPage.MainBody
@using (Html.BeginForm("sendmessage", Model.CurrentPage.PageUrl.ToString().Trim('/'), FormMethod.Post)) {
@Html.ValidationSummary()
<div class="form-group">
@Html.LabelFor(x => x.FormData.Name) *
@Html.TextBoxFor(x => x.FormData.Name, new { @class = "form-control", placeholder = "Name" })
</div>
<div class="form-group">
@Html.LabelFor(x => x.FormData.EmailAddress) *
@Html.TextBoxFor(x => x.FormData.EmailAddress, new { @class = "form-control", placeholder = "E-mail" })
</div>
<div class="form-group">
@Html.LabelFor(x => x.FormData.Subject) *
@Html.TextBoxFor(x => x.FormData.Subject, new { @class = "form-control", placeholder = "Subject" })
</div>
<div class="form-group">
@Html.LabelFor(x => x.FormData.Message) *
@Html.TextAreaFor(x => x.FormData.Message, new {@class = "form-control", placeholder = "Message"})
</div>
<button type="submit" class="btn btn-default">Submit</button>
}
</div>
</div>
20 changes: 20 additions & 0 deletions Views/ContactPage/ThankYou.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@using KalikoCMS
@using KalikoCMS.Mvc.Extensions
@model DemoSite.Models.ViewModels.ContactPageViewModel

@{
Layout = "~/Views/Shared/_Layout.cshtml";
}

@Html.Partial("~/Views/Partials/BreadCrumbsView.cshtml", Model)

<div class="row">
<div class="left-menu col-lg-3">
@Html.MenuTreeFor(Model.CurrentPage, PageFactory.GetPage(Model.CurrentPage.RootId), new { @class = "nav nav-pills nav-stacked", selectedItemClass = "active" })
</div>
<div class="col-lg-6">
<h1>@Model.CurrentPage.Headline</h1>
@Model.CurrentPage.ThankYouMessage
<p><a href="@Model.CurrentPage.PageUrl">Send another message</a></p>
</div>
</div>

0 comments on commit d8bdc25

Please sign in to comment.