public static List <ClassDTO> GetClasses() { using (Entities e = new Entities()) { return(ClassCasting.ClassesToDTO(e.classes.ToList())); } }
//create a simple test public static WebResult AddSimpleTest(SimpleTest newtest) { using (Entities e = new Entities()) { WebResult wb = new WebResult(); try { //add new test var t = e.tests.Add(TestCasting.TestToDAL(newtest.test)); //add classes o the new test t.classes = ClassCasting.ClassesToDAL(newtest.classes); //add questions to the new test t.questions = QuestionCasting.QuestionsToDAL(newtest.questions); wb.status = true; wb.message = "succeed"; wb.value = TestCasting.TestToDTO(t); e.SaveChanges(); return(wb); } catch (Exception ex) { wb.status = false; wb.message = ex.Message; return(wb); } } }
private static void HandleCastClass(ClassCasting casting, StringBuilder bodySb, ClosureEntities closureEntities) { var typeDescription = casting.AssignedTo.ComputedType(); bodySb .AppendFormat("{0} = std::static_pointer_cast<{2}>({1});", casting.AssignedTo.Name, casting.Value.Name, typeDescription.GetClrType(closureEntities).ToDeclaredVariableType(EscapingMode.Stack)); }
public void CastClass(Type operand) { var valueToCast = _evaluator.Pop(); var result = SetNewVReg(); result.FixedType = new TypeDescription(operand); var casting = new ClassCasting { AssignedTo = result, Value = valueToCast }; AddOperation(casting); }
//create generated test public static WebResult AddGeneratedTest(GeneratedTest newtest) { using (Entities e = new Entities()) { WebResult wb = new WebResult(); try { //add new test test t = e.tests.Add(TestCasting.TestToDAL(newtest.test)); e.SaveChanges(); //add rand questions to the new test List <question> newQuesList = RandQues(t.test_id, t.level, newtest.american, newtest.yesNo, newtest.match, newtest.classes.FirstOrDefault().teacher_id, newtest.subCategories); t.classes.AddRange(ClassCasting.ClassesToDAL(newtest.classes)); newQuesList.ForEach(q => { question qq = new question() { question_level = q.question_level, question_id = q.question_id, question_text = q.question_text, //// answers = q.answers, // sub_category = q.sub_category, sub_category_id = q.sub_category_id, // tests = q.tests, // type = q.type, type_id = q.type_id }; t.questions.Add(qq); }); //t.questions.AddRange(newQuesList.ToList()); wb.status = true; wb.message = "succeed"; wb.value = TestCasting.TestToDTO(t); e.SaveChanges(); return(wb); } catch (Exception ex) { wb.status = false; wb.message = ex.Message; return(wb); } } }
public static List <ClassDTO> GetClassesByTeacherId(int teacherId) { using (Entities e = new Entities()) { try { var classes = e.classes.Where(c => c.teacher_id == teacherId).ToList(); if (classes != null) { return(ClassCasting.ClassesToDTO(classes)); } throw new Exception("no classes"); } catch (Exception ex) { throw ex; } } }
public static ClassDTO GetClassById(int classId) { using (Entities e = new Entities()) { try { var cls = e.classes.FirstOrDefault(c => c.class_id == classId); if (cls != null) { return(ClassCasting.ClassToDTO(cls)); } throw new Exception("class is not exists"); } catch (Exception ex) { throw ex; } } }
public static ClassDTO AddClass(ClassDTO cls) { using (Entities e = new Entities()) { var c = e.teachers.FirstOrDefault(t => t.teacher_id == cls.teacher_id); if (c == null) { throw new Exception("teacher id is not exists"); } var cl = e.classes.FirstOrDefault(cc => cc.teacher_id == cls.teacher_id && cc.class_name == cls.class_name); if (cl != null) { throw new Exception("class name is exists"); } var added = e.classes.Add(ClassCasting.ClassToDAL(cls)); e.SaveChanges(); return(ClassCasting.ClassToDTO(added)); } }