public async Task <IActionResult> survey(int id, [FromBody] SurveyContract survey) { Logger.HttpRequestOutput("PUT", "api/survey/survey"); bool result = DataBaseService.SaveSurvey(id, survey); return(Json(result)); }
public bool AddSurvey(SurveyContract survey) { try { using (var db = new SurveyDbContext()) { if (!db.Survey.Any(a => a.IdSurvey == survey.IdSurvey)) { db.Survey.Add(new Data.Entities.Survey { IdSurvey = survey.IdSurvey, Description = survey.Description, Name = survey.Name, StartDateUTC = DateTime.Now.ToUniversalTime(), EndDateUTC = survey.EndDateUTC }); var answers = survey.Answers.Select(s => new Data.Entities.Answer { IdAnswer = s.IdAnswer, IdSurvey = survey.IdSurvey, Text = s.Text }); db.Answer.AddRange(answers); db.SaveChanges(); return(true); } return(false); } } catch (Exception e) { Logger.Log(e); return(false); } }
/// <summary> /// To the domain model. /// </summary> /// <param name="surveyDataContract">The survey data contract.</param> /// <returns></returns> public static SurveyModel ToDomainModel(this SurveyContract surveyDataContract) { var memberAdapter = new AsaMemberAdapter(); return(surveyDataContract == null ? null : new SurveyModel() { ListOfAnswerOptions = surveyDataContract.ListOfValues, QuestionText = surveyDataContract.SurveyQuestion, SurveyId = surveyDataContract.SurveyId.ToString(CultureInfo.InvariantCulture), IndividualId = memberAdapter.GetActiveDirectoryKeyFromContext(), MemberId = memberAdapter.GetMemberIdFromContext(), SurveyQuestionId = surveyDataContract.SurveyId.ToString(CultureInfo.InvariantCulture) }); }
public static SurveyModel GetModel(this SurveyContract contract) { return(new SurveyModel { IdSurvey = contract.IdSurvey, Name = contract.Name, Description = contract.Description, EndDateUTC = contract.EndDateUTC, Answers = contract.Answers.Select(s => new AnswerModel { IdAnswer = s.IdAnswer, IdSurvey = s.IdSurvey, Text = s.Text }).ToArray() }); }
public static bool SaveSurvey(SurveyContract surveyContract) { try { Survey survey = new Survey() { CreatorName = surveyContract.CreatorName, CreationDay = Int32.Parse(surveyContract.CreationDay), CreationMonth = Int32.Parse(surveyContract.CreationMonth), CreationYear = Int32.Parse(surveyContract.CreationYear), SurveyName = surveyContract.SurveyName }; model.SurveyList.Add(survey); model.SaveChanges(); return(true); } catch (Exception ex) { Logger.ExceptionOutput(ex); return(false); } }
public static bool SaveSurvey(int id, SurveyContract surveyContract) { try { var survey = (from query_survey in model.SurveyList where query_survey.Id == id select query_survey).FirstOrDefault(); survey.CreatorName = surveyContract.CreatorName; survey.CreationDay = Int32.Parse(surveyContract.CreationDay); survey.CreationMonth = Int32.Parse(surveyContract.CreationMonth); survey.CreationYear = Int32.Parse(surveyContract.CreationYear); survey.SurveyName = surveyContract.SurveyName; model.SaveChanges(); return(true); } catch (Exception ex) { Logger.ExceptionOutput(ex); return(false); } }
public void AddSurvey(SurveyContract survey) { var service = new Services.SurveyService(); service.AddSurvey(survey); }