public void Create(DalTestCompleted e) { CompletedTest completedTest = e.ToOrm(); User user = context.Set<User>().FirstOrDefault(m => m.Id == e.User.Id); List<Option> options = completedTest.Answers .Select(answer => context.Set<Option>().FirstOrDefault(m => m.Id == answer.Id)).ToList(); Test test = context.Set<Test>().FirstOrDefault(m => m.Id == completedTest.Test.Id); completedTest.User = user; completedTest.Answers = options; completedTest.Test = test; completedTest.IsFinished = true; context.Set<CompletedTest>().Add(completedTest); context.SaveChanges(); }
public void Update(DalTestCompleted entity) { throw new NotImplementedException(); }
public void Delete(DalTestCompleted e) { throw new NotImplementedException(); }
public static DalTestCompleted ToDalTestCompleted(this TestCompletedEntity testCompletedEntity) { DalTestCompleted dalTestCompleted = new DalTestCompleted() { Answers = new List<DalOption>(), DateTimeFinish = testCompletedEntity.DateTimeFinish, DateTimeStart = testCompletedEntity.DateTimeStart, Id = testCompletedEntity.Id, IsFinished = testCompletedEntity.IsFinished, Test = testCompletedEntity.Test.ToDalTest(), User = testCompletedEntity.User.ToDalUser() }; foreach (OptionEntity answer in testCompletedEntity.Answers) { dalTestCompleted.Answers.Add(answer.ToDalOption()); } return dalTestCompleted; }