Exemple #1
0
        public IActionResult Create([Bind("WorkingTitle,Grade,WorkingHours,Rank,Categories")] JobDescriptionViewModel form)
        {
            if (!ModelState.IsValid)
            {
                // model state validation failed, return VM to user with validation error messages
                ViewData["Title"] = "Create a Job Description: Error";
                return(View(form));
            }
            else
            {
                // POST is valid

                // create a JobDescription Object via the constructor that accepts a JobDescriptionViewModel object
                // I need to do this because I need the .JobDescriptionToXml() method to write the Job Description data
                // to the SmartJob entity JobData field, which is XML.
                JobDescription job   = new JobDescription(form);
                SmartJob       DbJob = new SmartJob
                {
                    JobName    = $"{job.Rank}-{job.WorkingTitle}",
                    JobDataXml = job.JobDescriptionToXml() // call the JobDescription method to convert Job Data to XML and write to entity column
                };
                // EF context saves are encapsulated in the IDocumentRepository instance
                _repository.SaveJob(DbJob);
                // return the user to the Index view
                return(RedirectToAction(nameof(Index)));
            }
        }