public bool Add(StatModel model) { using (var DB = new MainContext()) { model.TestModel.Questions = null; DB.Stats.Add(model); DB.Entry(model.TestModel).State = System.Data.Entity.EntityState.Unchanged; DB.SaveChanges(); return true; } return false; }
public static CheckResultModel CheckTest(TestModel result) { CheckResultModel check = new CheckResultModel() { QuestionsCount = result.Questions.Count, TestId = result.Id }; foreach (var question in result.Questions) { if (CheckQuestion(question)) check.RightAnswers++; } StatModel stat = new StatModel() { Count = check.RightAnswers, Date = DateTime.Now, Username = WebMatrix.WebData.WebSecurity.CurrentUserName, TestModel = result }; new StatsRepository().Add(stat); return check; }