diff --git a/TakeHome/App_Start/RouteConfig.cs b/TakeHome/App_Start/RouteConfig.cs index 6e720df..c6043d9 100644 --- a/TakeHome/App_Start/RouteConfig.cs +++ b/TakeHome/App_Start/RouteConfig.cs @@ -7,17 +7,17 @@ namespace TakeHome { - public class RouteConfig - { - public static void RegisterRoutes(RouteCollection routes) - { - routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); + public class RouteConfig + { + public static void RegisterRoutes(RouteCollection routes) + { + routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); - routes.MapRoute( - name: "Default", - url: "{controller}/{action}/{id}", - defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } - ); - } - } -} + routes.MapRoute( + name: "Default", + url: "{controller}/{action}/{id}", + defaults: new { controller = Constants.Controllers.Home, action = Constants.Controllers.ActionNamesHome.Index, id = UrlParameter.Optional } + ); + } + } +} \ No newline at end of file diff --git a/TakeHome/Constants.cs b/TakeHome/Constants.cs new file mode 100644 index 0000000..5b931ec --- /dev/null +++ b/TakeHome/Constants.cs @@ -0,0 +1,98 @@ +namespace TakeHome +{ + public static class Constants + { + public static class Controllers + { + public const string Feedback = "Feedback"; + public const string Home = "Home"; + + public static class ActionNamesFeedback + { + public const string Feedback = "Feedback"; + } + + public static class ActionNamesHome + { + public const string About = "About"; + + public const string Contact = "Contact"; + + public const string Index = "Index"; + } + } + + public static class Forms + { + public static class FeedBack + { + public static class Display + { + public const string Comments = "Comments"; + public const string Email = "Email"; + public const string FirstName = "First Name"; + public const string LastName = "Last Name"; + } + + public static class Errors + { + public const string _andMax = " and max "; + public const string _charactersInLength = " characters in length"; + public const string _requiredPrefix = "Please Provide '"; + public const string _requiredSuffix = "'"; + public const string _shouldBeMin = "' should be min "; + public const string LengthComments = "'" + Display.Comments + "' should have a max length of " + Validation.CommentsMaxLengthStr + " characters"; + public const string LengthEmail = "'" + Display.Email + _shouldBeMin + Validation.EmailMinLengthStr + _andMax + Validation.EmailMaxLengthStr + _charactersInLength; + public const string LengthFirstName = "'" + Display.FirstName + _shouldBeMin + Validation.FirstNameMinLengthStr + _andMax + Validation.FirstNameMaxLengthStr + _charactersInLength; + public const string LengthLastName = "'" + Display.LastName + _shouldBeMin + Validation.LastNameMinLengthStr + _andMax + Validation.LastNameMaxLengthStr + _charactersInLength; + public const string RegexEmail = "Please provide valid '" + Display.Email + "'"; + public const string RequiredEmail = _requiredPrefix + Display.Email + _requiredSuffix; + public const string RequiredFirstName = _requiredPrefix + Display.FirstName + _requiredSuffix; + public const string RequiredLastName = _requiredPrefix + Display.LastName + _requiredSuffix; + } + + public static class Validation + { + public const int CommentsMaxLengthInt = 200; + public const string CommentsMaxLengthStr = "200"; + public const int EmailMaxLengthInt = 25; + public const string EmailMaxLengthStr = "25"; + public const int EmailMinLengthInt = 3; + public const string EmailMinLengthStr = "3"; + public const int FirstNameMaxLengthInt = 25; + public const string FirstNameMaxLengthStr = "25"; + public const int FirstNameMinLengthInt = 1; + public const string FirstNameMinLengthStr = "1"; + public const int LastNameMaxLengthInt = 25; + public const string LastNameMaxLengthStr = "25"; + public const int LastNameMinLengthInt = 1; + public const string LastNameMinLengthStr = "1"; + } + } + + public static class Validation + { + public const string Email = "^[a-zA-Z0-9_\\.-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$"; + } + } + + public static class Titles + { + public const string Application = "Gregory's Submission"; + } + + public static class Views + { + public const string ThankYou = "ThankYou"; + public const string Feedback = "Feedback"; + + public static class Titles + { + public const string About = "About"; + public const string Contact = "Contact"; + public const string Feedback = "Feedback"; + public const string HomePage = "Home Page"; + } + } + } +} \ No newline at end of file diff --git a/TakeHome/Content/Site.css b/TakeHome/Content/Site.css index 6ea5d8f..07c7dbe 100644 --- a/TakeHome/Content/Site.css +++ b/TakeHome/Content/Site.css @@ -22,3 +22,7 @@ select, textarea { max-width: 280px; } + +span.field-validation-error { + color: red; +} \ No newline at end of file diff --git a/TakeHome/Controllers/FeedbackController.cs b/TakeHome/Controllers/FeedbackController.cs index f11973a..0c36e9f 100644 --- a/TakeHome/Controllers/FeedbackController.cs +++ b/TakeHome/Controllers/FeedbackController.cs @@ -1,32 +1,26 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Mvc; +using System.Web.Mvc; using TakeHome.Models; namespace TakeHome.Controllers { public class FeedbackController : Controller { - // GET: Feedback - - public ActionResult Index() - { - return View(); - } - [ValidateInput(true)] public ActionResult Feedback(FeedbackForm form) { if (ModelState.IsValid) { - return View("ThankYou", form); + return View(Constants.Views.ThankYou, form); } else ViewBag.Result = "Invalid Entries, Kindly Recheck."; return View(); } + [HttpGet] + public ActionResult Index() + { + return View(Constants.Views.Feedback); + } } } \ No newline at end of file diff --git a/TakeHome/Controllers/HomeController.cs b/TakeHome/Controllers/HomeController.cs index 9da809a..f49fe39 100644 --- a/TakeHome/Controllers/HomeController.cs +++ b/TakeHome/Controllers/HomeController.cs @@ -1,30 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Mvc; +using System.Web.Mvc; namespace TakeHome.Controllers { - public class HomeController : Controller - { - public ActionResult Index() - { - return View(); - } + public class HomeController : Controller + { + public ActionResult Index() + { + return View(); + } - public ActionResult About() - { - ViewBag.Message = "Your application description page."; + [HandleError] + public ActionResult Error() + { + return View(); + } - return View(); - } + public ActionResult About() + { + ViewBag.Message = "Your application description page."; - public ActionResult Contact() - { - ViewBag.Message = "Your contact page."; + return View(); + } - return View(); - } - } + public ActionResult Contact() + { + ViewBag.Message = "Contact Gregory"; + + return View(); + } + } } \ No newline at end of file diff --git a/TakeHome/Global.asax.cs b/TakeHome/Global.asax.cs index c47808e..e92159e 100644 --- a/TakeHome/Global.asax.cs +++ b/TakeHome/Global.asax.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; +using System.Web; using System.Web.Http; using System.Web.Mvc; using System.Web.Optimization; @@ -9,7 +6,7 @@ namespace TakeHome { - public class MvcApplication : System.Web.HttpApplication + public class MvcApplication : HttpApplication { protected void Application_Start() { @@ -20,4 +17,4 @@ protected void Application_Start() BundleConfig.RegisterBundles(BundleTable.Bundles); } } -} +} \ No newline at end of file diff --git a/TakeHome/Instructions.txt b/TakeHome/Instructions.txt index 7964bae..6102a06 100644 --- a/TakeHome/Instructions.txt +++ b/TakeHome/Instructions.txt @@ -2,7 +2,7 @@ The customer needs a form page added to the website to collect user feedback. This form needs to include the user's name, their email address, and a text area for their feedback. -Your front-end developer has provided the form markup in an html file. You need to incorporate this into the existing website. +Your front-end developer has provided the form markup in an HTML file. You need to incorporate this into the existing website. Requirements: @@ -10,9 +10,9 @@ Requirements: - Create a model for the form and a controller to process the form post. - The form inputs must be validated. - All fields are required. - - The character limit for all fields is 25, and 200 for the feedback field. + - The character limit for all fields is 25, and 200 for the 'Comments' field. - The email field should be a valid email address. -- Upon sucessful submission of the form the user should see a thank you page with the form data reflected (see thankyou.html). +- Upon successful submission of the form the user should see a thank you page with the form data reflected (see thankyou.html). - If the user submits an invalid form, a validation error message should be displayed on the form page. The following bugs have been reported with this feature diff --git a/TakeHome/Models/FeedbackForm.cs b/TakeHome/Models/FeedbackForm.cs index 504d188..20835bf 100644 --- a/TakeHome/Models/FeedbackForm.cs +++ b/TakeHome/Models/FeedbackForm.cs @@ -1,30 +1,32 @@ using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Web; namespace TakeHome.Models { - public class FeedbackForm - { - [Required(AllowEmptyStrings = false, ErrorMessage = "Please Provide First Name")] - [StringLength(25, MinimumLength = 1, ErrorMessage = "First Name Should be min 1 and max 25 length")] + public class FeedbackForm + { + [Required(AllowEmptyStrings = false, ErrorMessage = Constants.Forms.FeedBack.Errors.RequiredFirstName)] + [StringLength(Constants.Forms.FeedBack.Validation.FirstNameMaxLengthInt, MinimumLength = Constants.Forms.FeedBack.Validation.FirstNameMinLengthInt, ErrorMessage = Constants.Forms.FeedBack.Errors.LengthFirstName)] + [Display(Name = Constants.Forms.FeedBack.Display.FirstName)] public String FirstName { get; set; } - [Required(AllowEmptyStrings = false, ErrorMessage = "Please Provide Last Name")] - [StringLength(25, MinimumLength = 1, ErrorMessage = "First Name Should be min 1 and max 25 length")] + + [Required(AllowEmptyStrings = false, ErrorMessage = Constants.Forms.FeedBack.Errors.RequiredLastName)] + [StringLength(Constants.Forms.FeedBack.Validation.LastNameMaxLengthInt, MinimumLength = Constants.Forms.FeedBack.Validation.LastNameMinLengthInt, ErrorMessage = Constants.Forms.FeedBack.Errors.LengthLastName)] + [Display(Name = Constants.Forms.FeedBack.Display.LastName)] public String LastName { get; set; } - [Required(AllowEmptyStrings = false, ErrorMessage = "Please Provide Eamil")] - [RegularExpression("^[a-zA-Z0-9_\\.-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$", ErrorMessage = "Please Provide Valid Email")] - [StringLength(200, MinimumLength = 0, ErrorMessage = "First Name Should be min 1 and max 25 length")] + + [Required(AllowEmptyStrings = false, ErrorMessage = Constants.Forms.FeedBack.Errors.RequiredEmail)] + [RegularExpression(Constants.Forms.Validation.Email, ErrorMessage = Constants.Forms.FeedBack.Errors.RegexEmail)] + [StringLength(Constants.Forms.FeedBack.Validation.EmailMaxLengthInt, MinimumLength = Constants.Forms.FeedBack.Validation.EmailMinLengthInt, ErrorMessage = Constants.Forms.FeedBack.Errors.LengthEmail)] + [Display(Name = Constants.Forms.FeedBack.Display.Email)] public String Email { get; @@ -32,10 +34,8 @@ public String Email } [DataType(DataType.MultilineText)] - [StringLength(200, MinimumLength = 0, ErrorMessage = "Comments should have a max length of 200")] + [StringLength(Constants.Forms.FeedBack.Validation.CommentsMaxLengthInt, MinimumLength = 0, ErrorMessage = Constants.Forms.FeedBack.Errors.LengthComments)] + [Display(Name = Constants.Forms.FeedBack.Display.Comments)] public string Comments { get; set; } - - - - } + } } \ No newline at end of file diff --git a/TakeHome/TakeHome.csproj b/TakeHome/TakeHome.csproj index 3de13b1..2f1a09e 100644 --- a/TakeHome/TakeHome.csproj +++ b/TakeHome/TakeHome.csproj @@ -45,6 +45,9 @@ 4 + + ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + @@ -130,15 +133,13 @@ ..\packages\Microsoft.AspNet.TelemetryCorrelation.1.0.0\lib\net45\Microsoft.AspNet.TelemetryCorrelation.dll - - ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll - + diff --git a/TakeHome/Views/Feedback/Feedback.cshtml b/TakeHome/Views/Feedback/Feedback.cshtml index 6e2d0ec..d9fee2f 100644 --- a/TakeHome/Views/Feedback/Feedback.cshtml +++ b/TakeHome/Views/Feedback/Feedback.cshtml @@ -1,15 +1,13 @@ @model TakeHome.Models.FeedbackForm @{ - ViewBag.Title = "Feedback"; + ViewBag.Title = Constants.Views.Titles.Feedback; }

@ViewBag.Title.

@ViewBag.Message

- @*@using (Html.BeginForm("Submit", "Feedback"))*@ - @using (Html.BeginForm()) + @using (Html.BeginForm(Constants.Controllers.ActionNamesFeedback.Feedback, Constants.Controllers.Feedback)) { - /* form here */
@Html.LabelFor(m => m.FirstName) @@ -42,6 +40,7 @@ @Html.EditorFor(m => m.Comments) @Html.ValidationMessageFor(m => m.Comments)
+
diff --git a/TakeHome/Views/Feedback/ThankYou.cshtml b/TakeHome/Views/Feedback/ThankYou.cshtml index fd9b932..8073213 100644 --- a/TakeHome/Views/Feedback/ThankYou.cshtml +++ b/TakeHome/Views/Feedback/ThankYou.cshtml @@ -1,21 +1,24 @@ -@model object +@model TakeHome.Models.FeedbackForm @{ ViewBag.Title = "ThankYou"; } -

Thank You

-
-
- -
-
- -
-
- -
-
- -
-
+@if (Model != null) +{ +

Thank You

+
+
+ +
+
+ +
+
+ +
+
+ +
+
+} \ No newline at end of file diff --git a/TakeHome/Views/Home/About.cshtml b/TakeHome/Views/Home/About.cshtml index 4b2d9e8..bafe89c 100644 --- a/TakeHome/Views/Home/About.cshtml +++ b/TakeHome/Views/Home/About.cshtml @@ -1,7 +1,7 @@ @{ - ViewBag.Title = "About"; + ViewBag.Title = Constants.Views.Titles.About; }

@ViewBag.Title.

@ViewBag.Message

-

Use this area to provide additional information.

+

Use this area to provide additional information.

\ No newline at end of file diff --git a/TakeHome/Views/Home/Contact.cshtml b/TakeHome/Views/Home/Contact.cshtml index 0f4327e..aee487f 100644 --- a/TakeHome/Views/Home/Contact.cshtml +++ b/TakeHome/Views/Home/Contact.cshtml @@ -1,12 +1,11 @@ @{ - ViewBag.Title = "Contact"; + ViewBag.Title = Constants.Views.Titles.Contact; }

@ViewBag.Title.

@ViewBag.Message

- One Microsoft Way
- Redmond, WA 98052-6399
+ Austin, Tx 78704
P: 425.555.0100
diff --git a/TakeHome/Views/Home/Index.cshtml b/TakeHome/Views/Home/Index.cshtml index 32e1dd9..21e30f9 100644 --- a/TakeHome/Views/Home/Index.cshtml +++ b/TakeHome/Views/Home/Index.cshtml @@ -1,5 +1,5 @@ @{ - ViewBag.Title = "Home Page"; + ViewBag.Title = Constants.Views.Titles.HomePage; }
diff --git a/TakeHome/Views/Shared/Error.cshtml b/TakeHome/Views/Shared/Error.cshtml index 4c9a28a..7acbadf 100644 --- a/TakeHome/Views/Shared/Error.cshtml +++ b/TakeHome/Views/Shared/Error.cshtml @@ -10,4 +10,4 @@

An error occurred while processing your request.

- + \ No newline at end of file diff --git a/TakeHome/Views/Shared/_Layout.cshtml b/TakeHome/Views/Shared/_Layout.cshtml index 188c393..664b7be 100644 --- a/TakeHome/Views/Shared/_Layout.cshtml +++ b/TakeHome/Views/Shared/_Layout.cshtml @@ -3,7 +3,7 @@ - @ViewBag.Title - My ASP.NET Application + @ViewBag.Title - @Constants.Titles.Application @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr") @@ -16,13 +16,14 @@ - @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" }) + @Html.ActionLink(Constants.Titles.Application, Constants.Controllers.ActionNamesHome.Index, Constants.Controllers.Home, new { area = "" }, new { @class = "navbar-brand" })
@@ -31,7 +32,7 @@ @RenderBody()
-

© @DateTime.Now.Year - My ASP.NET Application

+

© @DateTime.Now.Year - @Constants.Titles.Application

@@ -39,4 +40,4 @@ @Scripts.Render("~/bundles/bootstrap") @RenderSection("scripts", required: false) - + \ No newline at end of file diff --git a/TakeHome/Web.config b/TakeHome/Web.config index 30e3a71..5007b79 100644 --- a/TakeHome/Web.config +++ b/TakeHome/Web.config @@ -5,76 +5,70 @@ --> - - - - + + + + - - - - + + + + + - - - - + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + \ No newline at end of file diff --git a/TakeHome/favicon.ico b/TakeHome/favicon.ico index a3a7999..0173d36 100644 Binary files a/TakeHome/favicon.ico and b/TakeHome/favicon.ico differ