public void Update(ThemeViewModel themeDTO) { Theme theme = Database.Themes.Get(themeDTO.IdTheme); Theme themeUpdate = MapperToDB.Map <Theme>(themeDTO); Database.Themes.Update(themeUpdate); }
public void CreateQuestion(QuestionCreateViewModel model, HttpPostedFileBase image) { Question question = new Question { QuestionText = model.QuestionText, Difficult = model.selectedDifficult, IdTheme = int.Parse(model.selectedTheme), CreateDate = DateTime.Now }; foreach (AnswerViewModel ans in model.Answers) { if (!String.IsNullOrEmpty(ans.AnswerText)) { question.Answers.Add(MapperToDB.Map <AnswerViewModel, Answer> (ans)); } } if (image != null) { question.ImageMimeType = image.ContentType; question.QuestionImage = new byte[image.ContentLength]; image.InputStream.Read(question.QuestionImage, 0, image.ContentLength); } question.AnswerNumber = question.Answers.Count; question.Score = ComputeScore(question); Database.Questions.Add(question); Database.Answers.AddRange(question.Answers); Database.Complete(); }