public IActionResult CreateSurvey(SurveyDefinitionModel payload) { try { var surveyData = new SurveyDefinitionModel { Id = payload.Id, Name = payload.Name, Questions = new List <QuestionModel>() }; // add multiple records with AddRange() instead of looping through list surveyData.Questions.AddRange(payload.Questions); this._storageProxy.CreateSurveyDef(surveyData); return(Ok(surveyData)); } catch (Exception ex) { // TODO: This is where I would log the error to have the stack trace // for the engineers to inspect. Since we don't have a logger implemented, // we will write it out to console for now and return a BadRequest for the client Console.WriteLine("Exception: " + ex); return(BadRequest($"Error creating the {payload.Name} survey.")); } }
public IActionResult TakeSurvey(SurveyDefinitionModel payload) { try { var takenSurvey = new TakenSurveyModel(); takenSurvey.SurveyDefinitionModel = new SurveyDefinitionModel { Id = payload.Id, Name = payload.Name, Questions = new List <QuestionModel>() }; // do a null check for answers if (payload.Questions.Any(q => q.Answer == null)) { return(BadRequest("test")); } // add multiple records with AddRange instead of looping through takenSurvey.SurveyDefinitionModel.Questions.AddRange(payload.Questions); this._storageProxy.SaveTakenSurvey(takenSurvey); return(Ok(takenSurvey)); } catch (Exception ex) { // TODO: Log error Console.WriteLine("Exception: " + ex); return(BadRequest($"Error updating the {payload.Name} survey.")); } }
public void CreateSurveyDef(SurveyDefinitionModel surveyData) { dbContext.SurveyTemplates.Add(surveyData); dbContext.SaveChanges(); return; }
public IActionResult SurveyPostback(int id, SurveyDefinitionModel definition) { return(View("SurveyEntry", definition)); }