コード例 #1
0
        public bool SubmitWork(SubmissionDetail subDetail, MemoryStream file, bool isUploaded)
        {
            try
            {
                if (!isUploaded)
                {
                    _SubDao.Insert(subDetail);
                }

                if (isUploaded)
                {
                    _FileDao.Delete(subDetail.UserNo, subDetail.AssignmentNo);
                }

                var userSecurity = new SecurityService(subDetail.UserNo.ToString(), subDetail.AssignmentNo.ToString());
                var byteFile     = _commonService.StreamToByte(file);
                var encryptFile  = userSecurity.EncryptFile(byteFile);
                var fileNo       = _FileDao.Insert(encryptFile);

                subDetail.FileNo = fileNo;

                _SubDao.Update(subDetail);
            }
            catch (Exception e)
            {
                throw e;
            }
            return(true);
        }
コード例 #2
0
 public void Init()
 {
     _assignment = new Assignment()
     {
         CourseNo = 1, AssignOrder = 1, AssignmentTitle = "單元測試", EndDate = new DateTime(2017, 12, 16)
     };
     _subDetail = new SubmissionDetail()
     {
         UserNo = 1, AssignmentNo = 2, FileName = "單元測試檔案"
     };
 }
コード例 #3
0
ファイル: StudentController.cs プロジェクト: JunKaiJuang/PASS
        public JsonResult UploadFile(Int64 assignmentNo, HttpPostedFileBase file)
        {
            HttpCookie cookie = Request.Cookies["PASS.LoginInfo"];

            var userNo = Convert.ToInt64(cookie["UserNo"]);

            var viewSub = _AMService.GetViewSubmissionByUserNoAndAssignmentNo(userNo, assignmentNo);
            var sub     = new SubmissionDetail()
            {
                UserNo = userNo, AssignmentNo = assignmentNo, FileName = file.FileName
            };

            using (Stream inputStream = file.InputStream)
            {
                MemoryStream memoryStream = inputStream as MemoryStream;
                if (memoryStream == null)
                {
                    memoryStream = new MemoryStream();
                    inputStream.CopyTo(memoryStream);
                }
                _AMService.SubmitWork(sub, memoryStream, viewSub.IsUploaded);
            }
            return(Json(true));
        }