public void AddQuestion(SurveyQuestions surveyQuestions) { SurveyQuestions questionModel = new SurveyQuestions { QuestionBody = surveyQuestions.QuestionBody, MemberId = GlobalMTHelper.GetMemberId(), SurveyId = surveyQuestions.SurveyId }; Add(questionModel); }
public void AddSurveyOption(SurveyOptions surveyOptions) { SurveyOptions options = new SurveyOptions { OptionType = surveyOptions.OptionType, Title = surveyOptions.Title, MemberId = GlobalMTHelper.GetMemberId(), SurveyId = surveyOptions.SurveyId }; Add(options); }
public ActionResult SurveyFeedbackForm(FormCollection formCollection) { using (MovingTacticsEntities db = new MovingTacticsEntities()) { int ResponseID = 0; int SurveyResponseId = 0; var x = Request.Form["SurveyId"];//Getting Survey Id from the form hidden field. #region Survey Responses SurveyResponses surveyResponses = new SurveyResponses { SurveyId = Int32.Parse(x.ToString()), MemberId = GlobalMTHelper.GetMemberId(), DateCreated = DateTime.Now.ToLongDateString(), TimeCreated = DateTime.Now.ToLongTimeString(), }; db.SurveyResponses.Add(surveyResponses); db.SaveChanges(); SurveyResponseId = surveyResponses.SurveyResponseId; #endregion for (int i = 1; i < formCollection.Keys.Count; i++) { #region Getting Values for each question in the form collection and taking them one by one var formTest = formCollection.GetValues(i); var formKey = formCollection.GetKey(i); //string value = formCollection[i]; //string[] variable = value.Split(','); #endregion #region Check If theres a comment value in Array var option = formTest.Count() > 1 ? formTest[1].ToString() == string.Empty ? null : formTest[1].ToString() : null; #endregion #region Storing the responses for each question Response response = new Response { QuestionId = Convert.ToInt32(formKey), MemberId = GlobalMTHelper.GetMemberId(), SurveyId = Int32.Parse(x.ToString()), ResponseValue = formTest[0].ToString(), Comment = option, YesQuestionCount = 10, DateCreated = DateTime.Now.ToLongDateString(), SurveyResponseId = SurveyResponseId }; db.Responses.Add(response); db.SaveChanges(); ResponseID = response.ResponseId; #endregion #region Checking File count According to question var FileCount = Request.Files.GetMultiple(formKey).Count(); var CheckFiles = Request.Files.GetMultiple(formKey); #endregion #region Media // the count of the files and looping it for (int v = 0; v < FileCount; v++) { //going through each file and checking if its null var file = CheckFiles[v]; if (file != null && file.ContentLength > 0) { #region Saving media files for each response question SurveyMedia media = new SurveyMedia { QuestionId = Convert.ToInt32(formKey), MemberId = GlobalMTHelper.GetMemberId(), SurveyId = Int32.Parse(x.ToString()), ResponseId = ResponseID, DateCreated = DateTime.Now.ToLongDateString() }; using (var reader = new System.IO.BinaryReader(file.InputStream)) { media.MediaContent = reader.ReadBytes(file.ContentLength); } db.SurveyMedias.Add(media); db.SaveChanges(); #endregion } } #endregion } return(RedirectToAction("Index")); } }