예제 #1
0
        public ActionResult EditSubmission(ParamInputCreateModel param)
        {
            int res       = 0;
            var userInfor = (UserLoginModel)Session[Helper.Commons.USER_SEESION];
            var subInfor  = dataAccess.GetSubmittionByID(param.Sub_ID);

            param.description = HttpUtility.HtmlDecode(RemoveHtmlTag(HttpUtility.HtmlDecode(param.description).Replace("<br />", "\n").Replace("</li>", "\n").Replace("&nbsp;", "")));
            var inforSubmit = new SUBMITTION()
            {
                Sub_ID          = param.Sub_ID,
                Sub_Title       = param.title,
                Sub_Description = param.description,
                Updated_Date    = DateTime.Now,
                Updated_By      = userInfor.UserID
            };

            res = dataAccess.EditSubmission(inforSubmit);
            var listOwnFile = dataAccess.GetFilesBySubCode(param.SubCode);

            if (param.files.Count() > 0)  // if student has file change
            {
                // xoa file cũ trong Folder va DB
                var rootFolder = Server.MapPath("~/Uploads/FilesSubmitted/");
                foreach (var item in listOwnFile)
                {
                    if (System.IO.File.Exists(Path.Combine(rootFolder, item.File_Path)))
                    {
                        System.IO.File.Delete(Path.Combine(rootFolder, item.File_Path));
                    }

                    var delete = dataAccess.DeleteFile(item.File_ID);
                }
                // edit file in DbContext and save new file
                foreach (var item in param.files)
                {
                    var    newFile  = new FILE();
                    string filename = string.Format("{0}_{1}_{2}{3}", userInfor.Username, param.SubCode, DateTime.Now.Ticks.ToString(), System.IO.Path.GetExtension(item.FileName));

                    newFile.Sub_ID    = param.Sub_ID;
                    newFile.Sub_Code  = param.SubCode;
                    newFile.File_Name = item.FileName;
                    newFile.File_Path = filename;

                    item.SaveAs(rootFolder + filename);
                    res = dataAccess.InsertFile(newFile);
                }
            }

            return(Json(res, JsonRequestBehavior.AllowGet));
        }