Exemple #1
0
        public ActionResult Upload(HttpPostedFileBase file)
        {
            if (Session["IsStudent"] == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            else if (!(bool)Session["IsStudent"])
            {
                return(RedirectToAction("Manager", "Dashboard"));
            }

            string errorMessage;

            if (file == null || file.ContentLength <= 0)
            {
                errorMessage = "File is empty";
                return(RedirectToAction("Upload", new { errorMessage = errorMessage }));
            }
            else if (file.ContentType != "text/html" || (file.FileName.Split('.')).Last() != "html")
            {
                errorMessage = "File invalid file type";
                return(RedirectToAction("Upload", new { errorMessage = errorMessage }));
            }

            var assignment = new Assignment {
                Student_ID  = (int)Session["Id"],
                Status_ID   = 0, Feedback = "",
                Lecturer_ID = StudentManager.GetLecturerIdByStudentID((int)Session["Id"])
            };

            var status = AssignmentManager.UploadAssignment(assignment, file, out errorMessage);

            //error message
            return(RedirectToAction("Manager", new { message = "Assignment uploaded successfully", errorMessage = errorMessage }));
        }