Пример #1
0
        public ActionResult Student()
        {
            int userId = Convert.ToInt32(HttpContext.User.Identity.Name);

            StudentPageModelResponse response = TheDataStore.FetchStudent(userId);

            StudentPageModel pageModel = response.pageModel;

            return(View(pageModel));
        }
Пример #2
0
 public IActionResult StudentPage(StudentPageModel model)
 {
     return(View(model));
 }
Пример #3
0
        public async Task <IActionResult> Results(StudentPageModel model)
        {
            //Make sure it is a valid model
            if (ModelState.IsValid)
            {
                //string for the file name
                string fileName = null;

                //creates the needed directory if it doesn't exist
                System.IO.Directory.CreateDirectory(hostingEnvironment.WebRootPath + @"/" + "studentCode");

                //checks to make sure it is not empty. Uploads the student program code
                if (model.StudentProgramFiles != null)
                {
                    //uploads each file in the list
                    foreach (IFormFile studentFile in model.StudentProgramFiles)
                    {
                        string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "studentCode");
                        fileName = studentFile.FileName;  //Guid.NewGuid().ToString() + "_" + model.StudentUnitTest.FileName;
                        string filePath = Path.Combine(uploadsFolder, fileName);
                        using (var fileStream = new FileStream(filePath, FileMode.Create))
                        {
                            await studentFile.CopyToAsync(fileStream);
                        }
                    }
                }
                //handles uploading from the text box for sutdent code
                else if (model.StudentProgramCode != null)
                {
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "studentCode");
                    fileName = "StudentProgram.cpp";   //Guid.NewGuid().ToString() + "_StudentCode.cpp";
                    string filePath = Path.Combine(uploadsFolder, fileName);

                    using (System.IO.StreamWriter file = new StreamWriter(System.IO.File.Create(filePath)))
                    {
                        file.WriteLine(model.StudentProgramCode.ToString());
                    }
                }

                //uploads the unit test
                if (model.StudentUnitTest != null)
                {
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "studentCode");
                    fileName = model.StudentUnitTest.FileName;  //Guid.NewGuid().ToString() + "_" + model.StudentUnitTest.FileName;
                    string filePath = Path.Combine(uploadsFolder, fileName);
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        await model.StudentUnitTest.CopyToAsync(fileStream);
                    }
                }
                //creates file from text box for unit test
                else if (model.StudentUnitCode != null)
                {
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "studentCode");
                    fileName = "StudentUnitTests.cpp";   //Guid.NewGuid().ToString() + "_StudentCode.cpp";
                    string filePath = Path.Combine(uploadsFolder, fileName);

                    using (System.IO.StreamWriter file = new StreamWriter(System.IO.File.Create(filePath)))
                    {
                        file.WriteLine(model.StudentUnitCode.ToString());
                    }
                }
            }

            //save restults of the program in the model
            model.StudentResults = Run(Path.Combine(hostingEnvironment.WebRootPath, "studentCode"));


            //returns the student page and model for proper display on same page
            return(View("StudentPage", model));
        }
Пример #4
0
 public StudentPage()
 {
     InitializeComponent();
     BindingContext = new StudentPageModel();
 }