Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs fixed per Instructions.txt #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions TakeHome/App_Start/RouteConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
);
}
}
}
98 changes: 98 additions & 0 deletions TakeHome/Constants.cs
Original file line number Diff line number Diff line change
@@ -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";
}
}
}
}
4 changes: 4 additions & 0 deletions TakeHome/Content/Site.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ select,
textarea {
max-width: 280px;
}

span.field-validation-error {
color: red;
}
20 changes: 7 additions & 13 deletions TakeHome/Controllers/FeedbackController.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
46 changes: 24 additions & 22 deletions TakeHome/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
9 changes: 3 additions & 6 deletions TakeHome/Global.asax.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
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;
using System.Web.Routing;

namespace TakeHome
{
public class MvcApplication : System.Web.HttpApplication
public class MvcApplication : HttpApplication
{
protected void Application_Start()
{
Expand All @@ -20,4 +17,4 @@ protected void Application_Start()
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
}
}
6 changes: 3 additions & 3 deletions TakeHome/Instructions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

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:

- Create a new Feedback page and add it to the site header. The Feedback page should leverage the site layout. The body content area will contain the form markup provided by the front end team (see form.html).
- 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
Expand Down
34 changes: 17 additions & 17 deletions TakeHome/Models/FeedbackForm.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
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;
set;
}

[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; }



}
}
}
7 changes: 4 additions & 3 deletions TakeHome/TakeHome.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down Expand Up @@ -130,15 +133,13 @@
<Reference Include="Microsoft.AspNet.TelemetryCorrelation">
<HintPath>..\packages\Microsoft.AspNet.TelemetryCorrelation.1.0.0\lib\net45\Microsoft.AspNet.TelemetryCorrelation.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform">
<HintPath>..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="App_Start\BundleConfig.cs" />
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\WebApiConfig.cs" />
<Compile Include="Constants.cs" />
<Compile Include="Controllers\FeedbackController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Global.asax.cs">
Expand Down
7 changes: 3 additions & 4 deletions TakeHome/Views/Feedback/Feedback.cshtml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
@model TakeHome.Models.FeedbackForm
@{
ViewBag.Title = "Feedback";
ViewBag.Title = Constants.Views.Titles.Feedback;
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>

<div class="form">
@*@using (Html.BeginForm("Submit", "Feedback"))*@
@using (Html.BeginForm())
@using (Html.BeginForm(Constants.Controllers.ActionNamesFeedback.Feedback, Constants.Controllers.Feedback))
{
/* form here */
<fieldset>
<div class="editor-label">
@Html.LabelFor(m => m.FirstName)
Expand Down Expand Up @@ -42,6 +40,7 @@
@Html.EditorFor(m => m.Comments)
@Html.ValidationMessageFor(m => m.Comments)
</div>

<div class="masthead-button-wrapper">
<input class="btn btn-warning" type="submit" value="Submit" />
</div>
Expand Down
Loading