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.Add(newJob);

                return(RedirectToAction("Index", new { id = newJob.ID }));
            }
            ;

            // 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));
        }
Example #2
0
        public IActionResult New(NewJobViewModel 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.
            if (ModelState.IsValid)
            {
                Job newJob = new Job
                {
                    Name           = newJobViewModel.Name,
                    Employer       = newJobViewModel.Employer,
                    Location       = newJobViewModel.Location,
                    CoreCompetency = newJobViewModel.CoreCompetency,
                    PositionType   = newJobViewModel.PositionType
                };

                JobData.Add(newJob);

                return(Redirect("Job/New"));
            }

            return(View(newJobViewModel));
        }