Ejemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] JobTitleViewModel theJobTitle)
        {
            if (ModelState.IsValid)
            {
                //Save to the Database
                var newJobTitle = Mapper.Map <JobTitle>(theJobTitle);

                _repository.AddJobTitle(newJobTitle);

                if (await _repository.SaveChangesAsync())
                {
                    return(Created($"api/jobtitles/{theJobTitle.Name}", Mapper.Map <JobTitleViewModel>(newJobTitle)));
                }
            }

            return(BadRequest("Failed to save changes to the database"));
        }