From 54f4f528cfe837a2376853f647bda819de3964bf Mon Sep 17 00:00:00 2001 From: "C. Brown" Date: Sat, 1 Dec 2018 14:32:08 -0600 Subject: [PATCH] Checkpoint #1 --- TechJobs.sln | 5 ++- src/TechJobs/Controllers/JobController.cs | 27 ++++++++++++++-- src/TechJobs/Models/Job.cs | 4 ++- src/TechJobs/ViewModels/NewJobViewModel.cs | 37 +++++++++++++++++++++- src/TechJobs/Views/Job/Index.cshtml | 26 ++++++++++++++- src/TechJobs/Views/Job/New.cshtml | 16 ++++++++-- src/TechJobs/web.config | 10 +++--- src/TechJobs/wwwroot/css/site.css | 3 ++ 8 files changed, 114 insertions(+), 14 deletions(-) diff --git a/TechJobs.sln b/TechJobs.sln index 6c778b3c..868c0fba 100644 --- a/TechJobs.sln +++ b/TechJobs.sln @@ -4,7 +4,7 @@ VisualStudioVersion = 15.0.26430.6 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{359DDFC7-BDB1-4B02-8FC3-C38BDCFF7E9F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechJobs", "src\TechJobs\TechJobs.csproj", "{14778719-D230-4A24-BD3B-704D11DA20D8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TechJobs", "src\TechJobs\TechJobs.csproj", "{14778719-D230-4A24-BD3B-704D11DA20D8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -31,4 +31,7 @@ Global GlobalSection(NestedProjects) = preSolution {14778719-D230-4A24-BD3B-704D11DA20D8} = {359DDFC7-BDB1-4B02-8FC3-C38BDCFF7E9F} EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3940CEF2-302C-4EC4-88C8-8E5634AE1841} + EndGlobalSection EndGlobal diff --git a/src/TechJobs/Controllers/JobController.cs b/src/TechJobs/Controllers/JobController.cs index 5bf10a19..2ed3f670 100644 --- a/src/TechJobs/Controllers/JobController.cs +++ b/src/TechJobs/Controllers/JobController.cs @@ -1,6 +1,8 @@ using Microsoft.AspNetCore.Mvc; using TechJobs.Data; using TechJobs.ViewModels; +using TechJobs.Models; +using System.Collections.Generic; namespace TechJobs.Controllers { @@ -20,9 +22,9 @@ public IActionResult Index(int id) { // TODO #1 - get the Job with the given ID and pass it into the view - return View(); - } + return View(jobData.Find(id)); + } public IActionResult New() { NewJobViewModel newJobViewModel = new NewJobViewModel(); @@ -32,11 +34,30 @@ public IActionResult New() [HttpPost] public IActionResult New(NewJobViewModel newJobViewModel) { + + if (ModelState.IsValid) + { + Job newJob = new Job + { + Name = newJobViewModel.Name, + Employer = jobData.Employers.Find(newJobViewModel.EmployerID), + Location = jobData.Locations.Find(newJobViewModel.LocationID), + CoreCompetency = jobData.CoreCompetencies.Find(newJobViewModel.CoreCompetencyID), + PositionType = jobData.PositionTypes.Find(newJobViewModel.PositionTypeID) + }; + jobData.Jobs.Add(newJob); + return Redirect($"/Job?={newJob.ID}"); + + } + else + { + return View(newJobViewModel); + } // TODO #6 - Validate the ViewModel and if valid, create a // new Job and add it to the JobData data store. Then // redirect to the Job detail (Index) action/view for the new Job. - return View(newJobViewModel); } + } } diff --git a/src/TechJobs/Models/Job.cs b/src/TechJobs/Models/Job.cs index 55f14d54..2e92df63 100644 --- a/src/TechJobs/Models/Job.cs +++ b/src/TechJobs/Models/Job.cs @@ -1,4 +1,6 @@ -namespace TechJobs.Models +using System.ComponentModel.DataAnnotations; + +namespace TechJobs.Models { public class Job { diff --git a/src/TechJobs/ViewModels/NewJobViewModel.cs b/src/TechJobs/ViewModels/NewJobViewModel.cs index e1999a62..7b84a7b4 100644 --- a/src/TechJobs/ViewModels/NewJobViewModel.cs +++ b/src/TechJobs/ViewModels/NewJobViewModel.cs @@ -15,6 +15,18 @@ public class NewJobViewModel [Display(Name = "Employer")] public int EmployerID { get; set; } + [Required] + [Display(Name = "Location")] + public int LocationID { get; set; } + + [Required] + [Display(Name = "Skill")] + public int CoreCompetencyID { get; set; } + + [Required] + [Display(Name = "Position Type")] + public int PositionTypeID { get; set; } + // TODO #3 - Included other fields needed to create a job, // with correct validation attributes and display names. @@ -35,7 +47,30 @@ public NewJobViewModel() Text = field.Value }); } - + foreach (Location field in jobData.Locations.ToList()) + { + Locations.Add(new SelectListItem + { + Value = field.ID.ToString(), + Text = field.Value + }); + } + foreach (CoreCompetency field in jobData.CoreCompetencies.ToList()) + { + CoreCompetencies.Add(new SelectListItem + { + Value = field.ID.ToString(), + Text = field.Value + }); + } + foreach (PositionType field in jobData.PositionTypes.ToList()) + { + PositionTypes.Add(new SelectListItem + { + Value = field.ID.ToString(), + Text = field.Value + }); + } // TODO #4 - populate the other List // collections needed in the view diff --git a/src/TechJobs/Views/Job/Index.cshtml b/src/TechJobs/Views/Job/Index.cshtml index 9f04a770..b90c27ce 100644 --- a/src/TechJobs/Views/Job/Index.cshtml +++ b/src/TechJobs/Views/Job/Index.cshtml @@ -2,8 +2,32 @@ // TODO #2.1- declare the ViewModel (outside of this @{ } block) } +@model TechJobs.Models.Job @{ // TODO #2.2 - display the job fields, one per row (outside of this @{ } block) } -
\ No newline at end of file + + + Name + @Model.Name + + + Employer + @Model.Employer + + + Location + @Model.Location + + + Skill + @Model.CoreCompetency + + + Position Type + @Model.PositionType + + + + diff --git a/src/TechJobs/Views/Job/New.cshtml b/src/TechJobs/Views/Job/New.cshtml index e2ccff39..8f3aac01 100644 --- a/src/TechJobs/Views/Job/New.cshtml +++ b/src/TechJobs/Views/Job/New.cshtml @@ -1,6 +1,6 @@ @model TechJobs.ViewModels.NewJobViewModel -
+
@@ -11,8 +11,20 @@
+
+ + +
+
+ + +
+
+ + +
- @{ + @{ // TODO #5 - Create