public static void Initialize(MyDbContext context) { //context.Database.EnsureCreated(); // Look for any students. /* * * public int Id { set; get; } * public string CodeIntro { set; get; } * public string CodeSolution { set; get; } * public string CodeExe { set; get; } * public string CodePath { set; get; } * */ //public List<string> CodeInputs { se if (context.TeacherCode.Any()) { return; // DB has been seeded } var teacherCodes = new TeacherCodeModel[] { new TeacherCodeModel { CodeIntro = "Test Code Intro!!!!", CodeSolution = "Alexander", CodeExe = "Teacher1.exe", CodePath = "C:/" }, }; foreach (TeacherCodeModel t in teacherCodes) { context.TeacherCode.Add(t); } context.SaveChanges(); }
public void FromTeacherModel(TeacherCodeModel tc) { QuestionNumber = tc.Id; Objective = tc.CodeIntro; Answer = tc.CodeSolution; Question = "null"; }
public async Task <IActionResult> Edit(int id, [Bind("Id,CodeIntro,CodeSolution,CodeExe,CodePath")] TeacherCodeModel teacherCodeModel) { if (id != teacherCodeModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var teachcode = new TeacherCodeModel().UpdatetoDatabase(teacherCodeModel); //_context.Update(teacherCodeModel); //await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeacherCodeModelExists(teacherCodeModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(teacherCodeModel)); }
public IActionResult Create([Bind("Id,CodeIntro,CodeSolution,CodeExe,CodePath")] TeacherCodeModel teacherCodeModel) { if (ModelState.IsValid) { teacherCodeModel.AddtoDatabase(teacherCodeModel); } return(View(teacherCodeModel)); }
// GET: TeacherCodeModels/Details/5 public IActionResult Details(int?id) { if (id == null) { return(NotFound()); } var teacherCodeModel = new TeacherCodeModel().GetFromDatabase((int)id); return(View(teacherCodeModel)); }
private bool TeacherCodeModelExists(int id) { var exist = new TeacherCodeModel().GetFromDatabase(id); if (exist != null) { return(true); } else { return(false); } }
// GET: TeacherCodeModels/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var teacherCodeModel = new TeacherCodeModel().GetFromDatabase((int)id); if (teacherCodeModel == null) { return(NotFound()); } return(View(teacherCodeModel)); }
public IActionResult Index(CompilerModel model) { /* * SlackerCompile testRunner = new SlackerCompile(); * testRunner.MyExe = @"C:\myTeacher.exe"; * testRunner.MyCode = "using System;public class Program{static void Main(){int myInput = 1000;int mySum = 0;for (int i = myInput - 1; i > 0; i--) { if (i % 3 == 0 || i % 5 == 0) mySum = mySum + i; }Console.WriteLine(mySum);"; * testRunner.MyArgs = ""; * testRunner.CompileItResult = testRunner.CompileIt(testRunner.MyCode, testRunner.MyExe); * testRunner.RunItResult = testRunner.RunIt(testRunner.MyExe,testRunner.MyArgs); */ //If we list all the natural numbers below 10 that are multiples of 3 or 5, //we get 3, 5, 6 and 9.The sum of these multiples is 23. //Find the sum of all the multiples of 3 or 5 below 1000. var myId = TempData["myProblem"]; int toIntId; int.TryParse(myId.ToString(), out toIntId); var teachcode = new TeacherCodeModel().GetFromDatabase(toIntId); /* * var myTeacherCode = _context.TeacherCode * .SingleOrDefault(t => t.Id == toIntId); //grabs teacher row where id matches * if (myTeacherCode == null) return Content("BLEEEECH"); */ //TeacherCodeModel myTeacherCode = (TeacherCodeModel)TempData["myProblem"]; List <string> testList = new List <string> { "1", "2" }; // string testStudentCode = "using System;public class Program { static void Main() { int myInput = 1000; int mySum = 0; for (int i = myInput - 1; i > 0; i--) { if (i % 3 == 0 || i % 5 == 0) mySum = mySum + i; } Console.WriteLine(mySum); } }"; //string testTeacherCode = "using System;public class sum{public static void Main(){int sum = 0;for (int i = 1; i <= 999; i++){if (i % 3 == 0 || i % 5 == 0) { sum += i; }}Console.WriteLine(sum);}}"; //Tester myTester = new Tester(@"C:\inetpub\myTeacher.exe", "myTeacher.exe",testTeacherCode, @"C:\inetpub\myStudent.exe", "myStudent.exe",testStudentCode, testList); //Tester myTester = new Tester(myTeacherCode.CodePath + myTeacherCode.CodeExe, myTeacherCode.CodeExe, myTeacherCode.CodeSolution, @"C:\myStudent.exe", "myStudent.exe", model.inputCode, testList); Tester myTester = new Tester(teachcode.CodePath + teachcode.CodeExe, teachcode.CodeExe, teachcode.CodeSolution, @"C:\inetpub\myStudent.exe", "myStudent.exe", model.inputCode, testList); //return Content(teachcode.CodeSolution); // return Content(model.inputCode); //return Content(myTeacherCode.CodeSolution); bool myTestResult = myTester.TestIt(); if (myTestResult == true) { ViewBag.Message = "Success!"; } else { ViewBag.Message = "Failure!"; } //ViewBag.Message = myTestResult.ToString(); TempData["myProblem"] = TempData["myProblem"]; CompilerModel myModel = new CompilerModel(); if (myTester.myOutputs != null) { ViewBag.myOutputs = myTester.myOutputs; } else { ViewBag.myOutputs = new List <string> { } }; return(View(myModel)); /* * * //return Content(myTestResult.ToString()); * * //sending inputs into the prog. * //testRunner.CompileIt * //testRunner.RunIt * * //take try catch code here, put in compiler class. * * SlackerCompile myRunner = new SlackerCompile(); * myRunner.MyExe = "myGuy.exe"; * myRunner.MyPath = @"C:\"+myRunner.MyExe; * string test = myRunner.MyExe; * // myRunner.MyCode = "public class MyClass{ static void Main(string[] args){System.Console.WriteLine("Hello World"); System.Console.WriteLine("testtesttest"); }}"; * myRunner.MyCode = model.inputCode; * Console.WriteLine("Starting compilation"); * * myRunner.CompileItResult = myRunner.CompileIt(myRunner.MyPath, myRunner.MyExe, myRunner.MyCode); * * * List<Diagnostic> myResult = myRunner.CompileItResult; * * try * { * * List<string> myOutput = myRunner.RunIt(myRunner.MyPath, "");//TODO: Have it use current working directory * * * myRunner.RunItResult = myOutput; * * string StringOutput = ""; * * foreach (string myString in myOutput) StringOutput += myString; * model.outputCode = StringOutput; * var myModel = model; * return View(myModel); * return Content(StringOutput); * } * * catch { * * string StringResult = ""; * foreach (Diagnostic diagnostic in myResult) * { * StringResult += diagnostic.ToString(); * * } * * model.outputCode = StringResult; * var myModel = model; * return View(myModel); * return Content(StringResult); * * } * * * * * * * * //myRunner.MyCode = "public class MyClass{ static void Main(string[] args){System.Console.WriteLine(\"Hello World\"); System.Console.ReadLine(); System.Console.WriteLine(\"testtesttest\"); }}"; * * * * * //TODO: Have it use current working directory * * * * return View(); */ } }