Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
C. Brown committed Dec 1, 2018
1 parent a75f584 commit 54f4f52
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 14 deletions.
5 changes: 4 additions & 1 deletion TechJobs.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
27 changes: 24 additions & 3 deletions src/TechJobs/Controllers/JobController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using TechJobs.Data;
using TechJobs.ViewModels;
using TechJobs.Models;
using System.Collections.Generic;

namespace TechJobs.Controllers
{
Expand All @@ -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();
Expand All @@ -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);
}

}
}
4 changes: 3 additions & 1 deletion src/TechJobs/Models/Job.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace TechJobs.Models
using System.ComponentModel.DataAnnotations;

namespace TechJobs.Models
{
public class Job
{
Expand Down
37 changes: 36 additions & 1 deletion src/TechJobs/ViewModels/NewJobViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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<SelectListItem>
// collections needed in the view

Expand Down
26 changes: 25 additions & 1 deletion src/TechJobs/Views/Job/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,32 @@
// TODO #2.1- declare the ViewModel (outside of this @{ } block)
}

@model TechJobs.Models.Job
<table class="job-listing">
@{
// TODO #2.2 - display the job fields, one per row (outside of this @{ } block)
}
</table>

<tr>
<td>Name</td>
<td>@Model.Name</td>
</tr>
<tr>
<td>Employer</td>
<td>@Model.Employer</td>
</tr>
<tr>
<td>Location</td>
<td>@Model.Location</td>
</tr>
<tr>
<td>Skill</td>
<td>@Model.CoreCompetency</td>
</tr>
<tr>
<td>Position Type</td>
<td>@Model.PositionType</td>
</tr>

</table>

16 changes: 14 additions & 2 deletions src/TechJobs/Views/Job/New.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@model TechJobs.ViewModels.NewJobViewModel

<div asp-validation-summary="All"></div>
<div class="error" asp-validation-summary="All"></div>

<form asp-controller="Job" asp-action="New" method="post">
<div class="form-group">
Expand All @@ -11,8 +11,20 @@
<label asp-for="EmployerID"></label>
<select asp-for="EmployerID" asp-items="Model.Employers"></select>
</div>
<div class="form-group">
<label asp-for="LocationID"></label>
<select asp-for="LocationID" asp-items="Model.Locations"></select>
</div>
<div class="form-group">
<label asp-for="CoreCompetencyID"></label>
<select asp-for="CoreCompetencyID" asp-items="Model.CoreCompetencies"></select>
</div>
<div class="form-group">
<label asp-for="PositionTypeID"></label>
<select asp-for="PositionTypeID" asp-items="Model.PositionTypes"></select>
</div>

@{
@{
// TODO #5 - Create <select> dropdowns for other job fields (outside of this @{ } block)
}

Expand Down
10 changes: 5 additions & 5 deletions src/TechJobs/web.config
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>

<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->

<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">
<environmentVariables />
</aspNetCore>
</system.webServer>
</configuration>
</configuration>
3 changes: 3 additions & 0 deletions src/TechJobs/wwwroot/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ table.job-listing td:last-child {

label {
margin-right: 15px;
}
.error{
color: red;
}

0 comments on commit 54f4f52

Please sign in to comment.