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"); }
public int CreateEntry(Entry entry) { try { _context.AddToEntries(entry); _context.SaveChanges(); return entry.ID; } catch (Exception) { return 0; } }
/// <summary> /// Create a new Entry object. /// </summary> /// <param name="id">Initial value of the ID property.</param> /// <param name="surveyID">Initial value of the SurveyID property.</param> /// <param name="date">Initial value of the Date property.</param> public static Entry CreateEntry(global::System.Int32 id, global::System.Int32 surveyID, global::System.DateTime date) { Entry entry = new Entry(); entry.ID = id; entry.SurveyID = surveyID; entry.Date = date; return entry; }
/// <summary> /// Deprecated Method for adding a new object to the Entries EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToEntries(Entry entry) { base.AddObject("Entries", entry); }