public SurveyEntity CreateSurvey(int adminId, SurveyData surveyData) { var survey = new SurveyEntity(); if (new[] { surveyData.Name, surveyData.Info }.Any(entry => entry == null)) { throw new Exception("Important properties were not filled!"); } survey.AdminId = adminId; survey.Name = surveyData.Name; /* * var surveyInfo = new { * created = DateTime.UtcNow * }; */ var surveyInfo = JObject.Parse(surveyData.Info); surveyInfo["created"] = DateTime.UtcNow; survey.Info = surveyInfo.ToJson(); _context.Surveys.Add(survey); _context.SaveChanges(); return(survey); }
public SurveyEntity UpdateSurvey(int adminId, int surveyId, SurveyData surveyData) { var survey = GetSurvey(adminId, surveyId); if (surveyData.Name != null) { survey.Name = surveyData.Name; } if (surveyData.Info != null) { survey.Info = surveyData.Info; } _context.SaveChanges(); return(survey); }