-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |