示例#1
0
        //[HttpPost]
        //public ActionResult ViewHomeworkDetails(StudentHomeworkDetailsVM model, string teacherFolder, string homeworkFolder, string studentFolder, string path)
        //{
        //    if (ModelState.IsValid)
        //    {
        //        if (teacherFolder == null)
        //            return View("Error", "You do not have the rights to access root folder!");
        //        else
        //        {
        //            string teacherName = teacherFolder.Split('_')[0];
        //            var teacherList = _studentService.GetTeacherBelongingToStudent((string)Session["SessionUser"]);
        //            bool found = false;
        //            if ((teacherList != null) && (teacherList.Item3 == teacherName))
        //                found = true;
        //            if ((Request.QueryString["studentFolder"] != (string)Session["SessionUser"] + "_" + Session["SessionUserId"]) || (studentFolder == null)
        //                || (!found) || (homeworkFolder == null))
        //                return View("Error", "You do not have the rights to access root folder!");
        //            string realPath = ConfigurationManager.AppSettings["BasePath"] + teacherFolder + "/" + homeworkFolder + "/" + studentFolder + "/";
        //            if (path != null)
        //                realPath += path;
        //            StudentHomeworkBroswerDetailsVM vm = new StudentHomeworkBroswerDetailsVM();
        //            vm.Details = model;
        //            //string realPath = ConfigurationManager.AppSettings["BasePath"] +
        //            //    "/" + (string)Session["SessionUser"] + "_" + Session["SessionUserId"] + "/");
        //            vm.FolderStructure = _fileSystemService.GetExplorerModel(realPath, Request.Url);
        //            if (!vm.FolderStructure.isFile)
        //                return View(vm);
        //            else
        //            {
        //                string fileText = "";
        //                try
        //                {
        //                    fileText = _fileSystemService.GetFileText(realPath);
        //                }
        //                catch (Exception)
        //                {
        //                    return View("Error", (object)"An error ocurred");
        //                }
        //                return View("ViewStudentHomework", (object)fileText);
        //            }
        //        }
        //    }
        //    else return View("Error", "Invalid data input!");
        //}

        public ActionResult ViewHomeworkDetails(int id, string teacherFolder, string homeworkFolder, string studentFolder, string path)
        {
            if (teacherFolder == null)
            {
                return(View("Error", (object)"You do not have the rights to access root folder!"));
            }
            else
            {
                string teacherName = teacherFolder.Split('_')[0];
                var    teacherList = _studentService.GetTeacherBelongingToStudent((string)Session["SessionUser"]);
                bool   found       = false;
                if ((teacherList != null) && (teacherList.Item3 == teacherName))
                {
                    found = true;
                }
                if ((Request.QueryString["studentFolder"] != (string)Session["SessionUser"] + "_" + Session["SessionUserId"]) || (studentFolder == null) ||
                    (!found) || (homeworkFolder == null))
                {
                    return(View("Error", (object)"You do not have the rights to access this folder!"));
                }
                string realPath = ConfigurationManager.AppSettings["BasePath"] + teacherFolder + "/" + homeworkFolder + "/" + studentFolder + "/";
                if (path != null)
                {
                    realPath += path;
                }
                StudentHomeworkBroswerDetailsVM vm = new StudentHomeworkBroswerDetailsVM();
                vm.Details = _homeworkService.GetStudentHomeworkDetails((int)Session["SessionUserId"], id);

                vm.FolderStructure = _fileSystemService.GetExplorerModel(Server.MapPath(realPath), Request.Url, id);
                ViewBag.HomeworkID = id;
                if (!vm.FolderStructure.isFile)
                {
                    return(View(vm));
                }
                else
                {
                    string fileText = "";
                    try
                    {
                        fileText = _fileSystemService.GetFileText(Server.MapPath(realPath));
                    }
                    catch (Exception)
                    {
                        return(View("Error", (object)"An error ocurred"));
                    }
                    return(View("ViewHomeworkFile", (object)fileText));
                }
            }
        }