public IActionResult Post([FromBody] SurveyCreateDTO survey) { if (survey == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // map dto to entity var surveyToAdd = new SurveyDTO { Name = survey.Name, Description = survey.Description, SurveyTypeCode = survey.SurveyTypeCode, Instructions = survey.Instructions, IsLocked = survey.IsLocked, CloseDate = survey.CloseDate, CreateDate = survey.CreateDate, CreatedBy = survey.CreatedBy, UpdateDate = survey.UpdateDate, UpdatedBy = survey.UpdatedBy, SchoolYear = survey.SchoolYear, LeaverYear = survey.LeaverYear, IsReported = survey.IsReported, OpenDate = survey.OpenDate }; try { // save _adminManager.AddSurvey <SurveyCreateDTO>(surveyToAdd); _adminManager.SurveySave(); return(CreatedAtRoute("GetSurvey", new { id = surveyToAdd.Id }, surveyToAdd)); } catch (Exception ex) { // return error message if there was an exception return(BadRequest(ex.Message)); } }