public bool CreateResponse(Response response) { try { _context.AddToResponses(response); _context.SaveChanges(); return true; } catch (Exception) { return false; } }
/// <summary> /// Deprecated Method for adding a new object to the Responses EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToResponses(Response response) { base.AddObject("Responses", response); }
public ActionResult Index(SurveyViewModel model) { try { Entry entry = new Entry(); entry.SurveyID = model.SurveyId; if (User.Identity.Name != "") { entry.UserID = User.Identity.Name; } entry.Date = DateTime.Now; int entryid = _repository.CreateEntry(entry); foreach (var question in model.Questions) { Response r = new Response(); r.Date = DateTime.Now; r.Question = question.QuestionId; r.Answer = question.SelectedAnswer; r.Survey = model.SurveyId; r.UserID = User.Identity.Name; r.Entry = entryid; _repository.CreateResponse(r); } } catch (Exception e) { TempData["Message"] = e; return View("Error"); } TempData["Message"] = "Good times."; return View("Thanks"); }
/// <summary> /// Create a new Response object. /// </summary> /// <param name="id">Initial value of the ID property.</param> /// <param name="survey">Initial value of the Survey property.</param> /// <param name="question">Initial value of the Question property.</param> /// <param name="answer">Initial value of the Answer property.</param> /// <param name="date">Initial value of the Date property.</param> /// <param name="entry">Initial value of the Entry property.</param> public static Response CreateResponse(global::System.Int32 id, global::System.Int32 survey, global::System.Int32 question, global::System.Int32 answer, global::System.DateTime date, global::System.Int32 entry) { Response response = new Response(); response.ID = id; response.Survey = survey; response.Question = question; response.Answer = answer; response.Date = date; response.Entry = entry; return response; }