public bool Edit(QuestionAdminViewModel model) { try { var actual = Mapper.Map<Question>(model); foreach (var answer in model.Answers) { if (answer.Id == 0) { answer.QuestionId = model.Id; this.AnswerService.Create(answer); } else { this.AnswerService.Edit(answer); } } this.Data.Questions.Update(actual); this.Data.SaveChanges(); return true; } catch (Exception e) { return false; } }
public ActionResult Edit(QuestionAdminViewModel model) { if (this.ModelState.IsValid) { var updatedModel = this.QuestionService.Edit(model); if (updatedModel) { //return this.RedirectToAction("AddAnswers", "Answer", new { questionId = updatedModel.Id }); } } return this.View(model); }
public QuestionAdminViewModel Create(QuestionAdminViewModel model) { try { var actual = Mapper.Map<Question>(model); this.Data.Questions.Add(actual); this.Data.SaveChanges(); model.Id = actual.Id; return model; } catch (Exception e) { return null; } }
public ActionResult Create() { var model = new QuestionAdminViewModel(); return this.View(model); }