public IActionResult CreateJobTitle([FromBody] JobTitleInsertDto jobtitle) { if (jobtitle == null) { return(BadRequest()); } if (_jobtitleRepository.isJobTitleExist(jobtitle.Title)) { ModelState.AddModelError(nameof(LocationInsertDto), "Job Title Already Exist"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var jobtitleEntity = Mapper.Map <JobTitle>(jobtitle); _jobtitleRepository.Add(jobtitleEntity); if (!_jobtitleRepository.Commit()) { throw new Exception("Creating Job Title Failed"); } var jobtitletoReturn = Mapper.Map <JobTitleViewModel>(jobtitleEntity); return(CreatedAtRoute("GetJobTitle", new { id = jobtitletoReturn.Id }, jobtitletoReturn)); }