Exemplo n.º 1
0
 //Insert
 public void Insert(AcceptedFiles acceptedFiles)
 {
     db.AcceptedFiles.Add(acceptedFiles);
     Save();
 }
Exemplo n.º 2
0
 //Update
 public void Update(AcceptedFiles acceptedFiles)
 {
     db.Entry(acceptedFiles).State = EntityState.Modified;
     Save();
 }
Exemplo n.º 3
0
 public JsonResult Upload()
 {
     using (TransactionScope Trans = new TransactionScope())
     {
         try
         {
             for (int i = 0; i < Request.Files.Count; i++)
             {
                 string reference = Request.Files.AllKeys[i];
                 HttpPostedFileBase file = Request.Files[i]; //Uploaded file
                                                             //Use the following properties to get file's name, size and MIMEType
                 int fileSize = file.ContentLength;
                 string fileName = file.FileName;
                 string mimeType = file.ContentType;
                 System.IO.Stream fileContent = file.InputStream;
                 //To save file, use SaveAs method
                 if (System.IO.File.Exists(Server.MapPath("~/Content/Docs/acpd/") + reference + "_" + fileName))
                 {
                     return Json("อัพโหลดไม่สำเร็จ - มีไฟล์นี้อยู่แล้ว");
                 }
                 AcceptedFiles acpdFiles = new AcceptedFiles();
                 acpdFiles.SHPMNTNO = reference;
                 acpdFiles.FILEPATH = "Content/Docs/acpd" + reference + "_" + fileName;
                 acpdFiles.LOADED_DATE = DateTime.Now;
                 acpdFiles.LOADED_BY = User.Identity.Name;
                 objBs.acceptedFilesBs.Insert(acpdFiles);
                 file.SaveAs(Server.MapPath("~/Content/Docs/acpd/") + reference + "_" + fileName); //File will be saved in application root
             }
             Trans.Complete();
             return Json("อัพโหลดสำเร็จ " + Request.Files.Count + " ไฟล์");
         }
         catch (Exception e)
         {
             return Json("อัพโหลดไม่สำเร็จ :: Code " + e.ToString());
         }
     }
 }