public ActionResult CreateTestCase(TestCaseModels testcaseModel ) { string name=HttpContext.User.Identity.Name; if(name!=null) { if (checkRole.IsLecturer(name)) { TestCas testcase = new TestCas(); testcase.MaDB = testcaseModel.MaDB; testcase.Input = testcaseModel.Input; testcase.Output = testcaseModel.Output; testcase.Diem = testcaseModel.Diem; testcase.MoTa = testcaseModel.MoTa; db.TestCases.AddObject(testcase); db.SaveChanges(); return RedirectToAction("CreateTestCase", new { ProblemID = testcase.MaDB }); } else return RedirectToAction("Index", "Home"); } else return RedirectToAction("Index", "Home"); }
public string Unzipfile(Problem problem, Stream inputStream) { Dictionary<string, TestCas> dTestcase = new Dictionary<string, TestCas>(); ZipInputStream s = new ZipInputStream(inputStream); ZipEntry ZEntry; string sFileName = ""; String configXML = null; while ((ZEntry = s.GetNextEntry()) != null) { string directoryName = ""; directoryName = Path.GetDirectoryName(ZEntry.Name); if (directoryName != "" && directoryName != null && !dTestcase.ContainsKey(directoryName)) { TestCas tcTemp = new TestCas(); tcTemp.MaDB = problem.ID; dTestcase.Add(directoryName, tcTemp); db.TestCases.AddObject(tcTemp); problem.TestCases.Add(tcTemp); } sFileName = Path.GetFileName(ZEntry.Name); if (sFileName == String.Empty) continue; #region Doc file entry int size = 2048; using (MemoryStream memStream = new MemoryStream(size)) { byte[] data = new byte[size]; while (true) { size = s.Read(data, 0, data.Length); if (size > 0) { memStream.Write(data, 0, size); } else { break; } } memStream.Position = 0; switch (Path.GetExtension(sFileName).ToLower()) { case ".inp": using (StreamReader docFile = new System.IO.StreamReader(memStream)) { TestCas tc = dTestcase[directoryName]; tc.Input = docFile.ReadToEnd(); docFile.Close(); } break; case ".out": using (StreamReader docFile = new System.IO.StreamReader(memStream)) { TestCas tc = dTestcase[directoryName]; tc.Output = docFile.ReadToEnd(); docFile.Close(); } break; case ".xml": //Doc file cau hinh if (Path.GetFileNameWithoutExtension(sFileName).ToLower() == problem.Name) using (StreamReader docFile = new System.IO.StreamReader(memStream)) { configXML = docFile.ReadToEnd(); docFile.Close(); } break; case ".doc": case ".docx": case ".pdf": byte[] problemfile = memStream.ToArray(); SPKTOnline.Models.File file = new SPKTOnline.Models.File(); file.Content = problemfile; file.Type = Path.GetExtension(sFileName); file.Name = sFileName; file.DownloadCount = 0; db.Files.AddObject(file); problem.File = file; break; default: break; } } #endregion } //TODO: Gan du lieu Problem tu cau hinh xml double phanTramDiem = Math.Round(100.0 / problem.TestCases.Count, 2); foreach (TestCas tc in dTestcase.Values) { tc.Diem = phanTramDiem; } s.Close(); return sFileName; }
public ActionResult EditTestCase(TestCas Testcase) { string name=HttpContext.User.Identity.Name; if(name!=null) { if (checkRole.IsLecturer(name)) { db.TestCases.Attach(Testcase); db.ObjectStateManager.ChangeObjectState(Testcase, EntityState.Modified); db.SaveChanges(); return RedirectToAction("CreateTestCase", new { ProblemID = Testcase.MaDB }); } else return RedirectToAction("Index", "Home"); } else return RedirectToAction("Index", "Home"); }
/// <summary> /// Deprecated Method for adding a new object to the TestCases EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToTestCases(TestCas testCas) { base.AddObject("TestCases", testCas); }
/// <summary> /// Create a new TestCas object. /// </summary> /// <param name="maTestCase">Initial value of the MaTestCase property.</param> /// <param name="maDB">Initial value of the MaDB property.</param> /// <param name="input">Initial value of the Input property.</param> /// <param name="output">Initial value of the Output property.</param> /// <param name="diem">Initial value of the Diem property.</param> /// <param name="timeStamp">Initial value of the TimeStamp property.</param> public static TestCas CreateTestCas(global::System.Int32 maTestCase, global::System.Int32 maDB, global::System.String input, global::System.String output, global::System.Double diem, global::System.Byte[] timeStamp) { TestCas testCas = new TestCas(); testCas.MaTestCase = maTestCase; testCas.MaDB = maDB; testCas.Input = input; testCas.Output = output; testCas.Diem = diem; testCas.TimeStamp = timeStamp; return testCas; }