public AdministratedTestBusiness GetAdministratedTest(int administratedTestId) { _repo = new AdministratedTestRepository(); AdministratedTestBusiness administratedTest = null; try { administratedTest = _repo.GetAdministratedTestById(administratedTestId); } catch (NullReferenceException ex) { //TODO } catch (ArgumentNullException ex) { //TODO } catch (Exception ex) { //TODO } return(administratedTest); }
public AdministratedTestDto(AdministratedTestBusiness administratedTest) { Id = administratedTest.Id; URL = administratedTest.URL; TotalScore = administratedTest.TotalScore; TestId = administratedTest.TestId; TestSubject = administratedTest.TestSubject; Date = administratedTest.Date; AdministratedQuestions = administratedTest.AdministratedQuestions.Select(q => new AdministratedQuestionDto(q)); }
public static AdministratedTest MapDomainToDao(AdministratedTestBusiness domain) { var returned = new AdministratedTest { Id = domain.Id, URL = domain.URL, TotalScore = domain.TotalScore, TestId = domain.TestId, TestSubject = domain.TestSubject, Date = domain.Date, AdministratedQuestions = domain.AdministratedQuestions.Select(AdministratedQuestionMapper.MapDomainToDao).ToList() }; return(returned); }
public static AdministratedTestBusiness MapDaoToDomain(AdministratedTest dao) { var returned = new AdministratedTestBusiness { Id = dao.Id, URL = dao.URL, TotalScore = dao.TotalScore, TestId = dao.TestId, TestSubject = dao.TestSubject, Date = dao.Date, AdministratedQuestions = dao.AdministratedQuestions.Select(AdministratedQuestionMapper.MapDaoToDomain).ToList() }; return(returned); }
public AdministratedTestBusiness Add(AdministratedTestBusiness adTest) { using (_ctx) { try { var newAdTestDB = AdministratedTestMapper.MapDomainToDao(adTest); _ctx.AdministratedTests.Add(newAdTestDB); _ctx.SaveChanges(); adTest = AdministratedTestMapper.MapDaoToDomain(newAdTestDB); return(adTest); } catch (Exception ex) { throw new Exception("Save Failed"); } finally { _ctx.AdministratedTests.Find(1); } } }
public void Update_Save(AdministratedTestBusiness adTest) { var newTest = Mapper.AdministratedTestMapper.MapDomainToDao(adTest); try { foreach (var q in newTest.AdministratedQuestions) { foreach (var a in q.AdministratedAnswers) { if (a.isSelected == true) { _ctx.AdministratedAnswers.FirstOrDefault(x => x.Id == a.Id).isSelected = true; } } } decimal score = 0; foreach (var q in newTest.AdministratedQuestions) { if ((q.AdministratedAnswers.FirstOrDefault(x => x.isSelected == true)) != null) { score = score + q.AdministratedAnswers.FirstOrDefault(x => x.isSelected == true).Score ?? 0; } } _ctx.AdministratedTests.FirstOrDefault(x => x.Id == newTest.Id).TotalScore = decimal.ToInt32(score); _ctx.AdministratedTests.FirstOrDefault(x => x.Id == newTest.Id).Date = DateTime.Today; _ctx.SaveChanges(); } catch (Exception ex) { throw new Exception("Update failed"); } }
public AdministratedTestBusiness AdministratedTest_Builder(TestBusiness test, string subject) { var newAdTest = new AdministratedTestBusiness(); newAdTest.Date = DateTime.Today; newAdTest.URL = test.URL; newAdTest.TestId = test.Id; newAdTest.TestSubject = subject; newAdTest.AdministratedQuestions = new List <AdministratedQuestionBusiness>(); foreach (var q in test.Questions) { newAdTest.AdministratedQuestions.Add(new AdministratedQuestionBusiness() { Text = q.Text, AdministratedTestId = q.TestId, AdministratedAnswers = q.Answers.Select(a => new AdministratedAnswerBusiness() { Text = a.Text, Score = a.Score, AdministratedQuestionId = a.QuestionId, isCorrect = a.IsCorrect, isSelected = false }).ToList() }); } return(newAdTest); }
public void Update_Save(AdministratedTestBusiness adTest) { _repo.Update_Save(adTest); }
public AdministratedTestBusiness Add(AdministratedTestBusiness adTest) { return(_repo.Add(adTest)); }