Exemple #1
0
        public ActionResult UploadAnswer(long id, string qqfile)
        {
            var length = long.Parse(Request.Params["CONTENT_LENGTH"]);

            var filename = Path.GetFileNameWithoutExtension(qqfile);
            var ext      = Path.GetExtension(qqfile);

            var  uploader = new FileHandler(filename.ToSafeUrl() + ext, UploaderType.HOMEWORK, sessionid);
            bool ok       = uploader.Save(Request.InputStream);

            if (!ok)
            {
                return(Json("An error has occurred. Unable to save file".ToJsonFail()));
            }

            // save to database
            var homeworkstudent = db.homework_students.SingleOrDefault(x => x.studentid == sessionid.Value && x.id == id);

            var answer = new homework_answer();

            answer.created    = DateTime.Now;
            answer.url        = uploader.url;
            answer.filename   = qqfile;
            answer.size       = uploader.size;
            answer.homeworkid = homeworkstudent.homeworkid;
            homeworkstudent.homework_answers.Add(answer);

            repository.Save();

            // notify teacher?
            if (homeworkstudent.homework.notifyme)
            {
                var viewmodel   = new NotificationSendViewModel();
                var studentname = homeworkstudent.user.ToName();
                viewmodel.message =
                    string.Format(
                        "An answer has been uploaded by <a href='http://wwww.ioschools.edu.my/users/{0}'>{1}</a>",
                        homeworkstudent.studentid, studentname);
                viewmodel.message += string.Format("<br/> To view your homeworks. <a href='http://wwww.ioschools.edu.my/homework'>Please follow this link</a>.");

                var teacher = homeworkstudent.homework.user;

                if (!string.IsNullOrEmpty(teacher.email))
                {
                    viewmodel.receiver = teacher.ToName();
                    this.SendEmailNow(
                        EmailViewType.HOMEWORK_NOTIFICATION,
                        viewmodel,
                        string.Format("Homework {0}: Answer uploaded by {1}", homeworkstudent.homework.title, studentname),
                        teacher.email,
                        viewmodel.receiver);
                }
            }

            var retVal = new IdName(answer.id, uploader.filename);

            return(Json(retVal.ToJsonOKData()));
        }
        public ActionResult Upload(string qqfile)
        {
            var length = long.Parse(Request.Params["CONTENT_LENGTH"]);

            if (sessionid.HasValue)
            {
                var inuse = repository.GetUserDiskUsage(sessionid.Value);
                if (inuse + length > Constants.MAX_DISK_SIZE)
                {
                    return(Json("Disk Quota exceeded. Please delete old uploaded files.".ToJsonFail()));
                }
            }

            var filename = Path.GetFileNameWithoutExtension(qqfile);
            var ext      = Path.GetExtension(qqfile);

            var  uploader = new FileHandler(filename.ToSafeUrl() + ext, UploaderType.HOMEWORK, sessionid);
            bool ok       = uploader.Save(Request.InputStream);

            if (!ok)
            {
                return(Json("An error has occurred. Unable to save file".ToJsonFail()));
            }

            // save to database
            var homework_file = new homework_file();

            homework_file.url      = uploader.url;
            homework_file.filename = qqfile;
            homework_file.size     = uploader.size;
            repository.AddHomeworkFile(homework_file);

            var retVal = new IdName(homework_file.id, uploader.filename);

            return(Json(retVal.ToJsonOKData()));
        }