public ActionResult SaveFileProcessAction() { //foreach (HttpPostedFileBase f in Request.Files) //{ //} HttpFileCollectionBase PhotoFile = Request.Files; var fMain = Request.Form["fMain"]; var obj1 = JObject.Parse(fMain); var fileBelongstoUser = _fileMainService.All().Where(x => x.FileNo == (string)obj1["fMain"]["FileID"]).Select(x => x.UserID).FirstOrDefault(); try { using (var transaction = new TransactionScope()) { var fileNoCheck = _fileMainService.All().Where(x => x.FileNo == (string)obj1["fMain"]["FileID"]).FirstOrDefault(); //FileMain FileMainInfo = new FileMain(); if (fileNoCheck != null) { var VersionNo = EncryptionDecryption.DH_PEncode(_actionListService.All().Where(x => x.ActID == (int)obj1["fMain"]["Action"]).Select(x => x.ActDesc).LastOrDefault()); var UpdUserID = (int)obj1["fMain"]["MarkTo"]; if (UpdUserID == 0) { fileNoCheck.UpdUserID = EncryptionDecryption.DH_PEncodeInt(fileBelongstoUser); //Convert.ToInt32(Session["UserID"]); } else { fileNoCheck.UpdUserID = EncryptionDecryption.DH_PEncodeInt((int)obj1["fMain"]["MarkTo"]); } fileNoCheck.VersionNo = EncryptionDecryption.DH_PEncode(VersionNo); _fileMainService.Update(fileNoCheck); _fileMainService.Save(); } var user = Convert.ToInt32(Session["UserID"]); FileTransMain FileTransMainInfo = new FileTransMain(); FileTransMainInfo.MainID = EncryptionDecryption.DH_PEncodeInt(_fileMainService.All().Where(x => x.FileNo == (string)obj1["fMain"]["FileID"]).Select(x => x.MainID).FirstOrDefault()); FileTransMainInfo.ActionNum = EncryptionDecryption.DH_PEncode(_actionListService.All().Where(x => x.ActID == (int)obj1["fMain"]["Action"]).Select(x => x.ActDesc).LastOrDefault()); //FileTransMainInfo.EntryDate = (DateTime)obj1["fMain"]["Date"]; FileTransMainInfo.MarkToID = EncryptionDecryption.DH_PEncodeInt((int)obj1["fMain"]["MarkTo"]); //FileTransMainInfo.MarkToID = _newStaffService.All().Where(x => x.StaffId ==user).Select(x => x.ReportingId).FirstOrDefault(); if (FileTransMainInfo.MarkToID == 0) { FileTransMainInfo.MarkToID = fileBelongstoUser; } FileTransMainInfo.EntryDate = DateTime.Now; FileTransMainInfo.ActionID = EncryptionDecryption.DH_PEncodeInt((int)obj1["fMain"]["Action"]); FileTransMainInfo.AttachNum = EncryptionDecryption.DH_PEncode(Convert.ToString(PhotoFile.Count)); // var action = _fileTransMainService.All().Where(x => x.MainID ==(int)obj1["fMain"]["FileID"]).Select(x => x.ActionNum).LastOrDefault(); var FileTransNum = Convert.ToInt16(_fileTransMainService.All().Where(x => x.MainID == FileTransMainInfo.MainID).Select(x => x.FileTransNum).LastOrDefault()); FileTransMainInfo.FileTransNum = EncryptionDecryption.DH_PEncode((FileTransNum + 1).ToString()); // FileTransMainInfo.FileTransID = 1; FileTransMainInfo.ActionByID = EncryptionDecryption.DH_PEncodeInt(Convert.ToInt32(Session["UserID"].ToString())); FileTransMainInfo.SignDate = DateTime.Now; FileTransMainInfo.TransDate = DateTime.Now; FileTransMainInfo.Note = EncryptionDecryption.DH_PEncode((string)obj1["fMain"]["Note"]); _fileTransMainService.Add(FileTransMainInfo); _fileTransMainService.Save(); transaction.Complete(); } } catch (Exception ex) { return(Json("0", JsonRequestBehavior.AllowGet)); } var MainIdCheck = _fileMainService.All().Where(x => x.FileNo == (string)obj1["fMain"]["FileID"]).Select(x => x.MainID).LastOrDefault(); string fileName = ""; string NewPhotoID = ""; //string ImgPrefix = ""; string ext = ""; string PhotoPath = ""; string PhysicalPhPath = ""; string DBPhotoPath = ""; try { if (PhotoFile != null) { for (int i = 0; i < PhotoFile.Count; i++) { string fileId = Guid.NewGuid().ToString().Replace("-", ""); HttpPostedFileBase file = PhotoFile[i]; fileName = Path.GetFileName(file.FileName); //ImgPrefix = file.ContentType; //"Photo";//file.ContentType;// int fSize = file.ContentLength; //var path = Path.Combine(Server.MapPath("~/Uploads/Photo/"), MemberCode, fileId); ext = System.IO.Path.GetExtension(fileName); if (ext.ToLower().Contains("txt") || ext.ToLower().Contains("gif") || ext.ToLower().Contains("jpg") || ext.ToLower().Contains("jpeg") || ext.ToLower().Contains("png") || ext.ToLower().Contains(".xls") || ext.ToLower().Contains(".docx") || ext.ToLower().Contains(".xlsx") || ext.ToLower().Contains(".pdf")) { NewPhotoID = fileId + ext; PhotoPath = ConfigurationManager.AppSettings["PhotoPath"]; PhysicalPhPath = Path.Combine(Server.MapPath(PhotoPath), NewPhotoID); //var path = Path.Combine(Server.MapPath("~/Images/Photo"), fileName); file.SaveAs(PhysicalPhPath); DBPhotoPath = PhotoPath + "\\" + NewPhotoID; } var FileTransMain = new FileTransDetail { AttachFileName = fileName, FileType = ext, Size = fSize, FileSourcePath = PhysicalPhPath, FileTransID = _fileTransMainService.All().Where(x => x.MainID == MainIdCheck).Select(x => x.FileTransID).LastOrDefault(), }; _fileTransDetailService.Add(FileTransMain); _fileTransDetailService.Save(); } } return(Json("1", JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json("0", JsonRequestBehavior.AllowGet)); } }
public ActionResult UpdateFileMain() { HttpFileCollectionBase PhotoFile = Request.Files; var fMain = Request.Form["fMain"]; var obj1 = JObject.Parse(fMain); var FileNo = (string)obj1["fMain"]["FileID"]; var MainID = _fileMainService.All().Where(x => x.FileNo == FileNo).Select(x => x.MainID).FirstOrDefault(); FileMain _FileMainInfo = new FileMain(); _FileMainInfo = _fileMainService.All().ToList().FirstOrDefault(x => x.MainID == MainID); try { if (_FileMainInfo != null) { string fileName = ""; string NewPhotoID = ""; string ImgPrefix = ""; string ext = ""; string PhotoPath = ""; string PhysicalPhPath = ""; string DBPhotoPath = ""; string[] fileList = null; string filesToDelete = ""; if (PhotoFile != null) { if (PhotoFile.Count != 0) { var ExistFD = _fileDetailService.All().ToList().Where(x => x.MainID == MainID); if (ExistFD != null) { foreach (var item in ExistFD) { _fileDetailService.Delete(item); } } } for (int i = 0; i < PhotoFile.Count; i++) { string fileId = Guid.NewGuid().ToString().Replace("-", ""); HttpPostedFileBase file = PhotoFile[i]; fileName = Path.GetFileName(file.FileName); ext = System.IO.Path.GetExtension(fileName); ImgPrefix = FileNo.ToString(); //"Photo";//file.ContentType;// int fSize = file.ContentLength; if (ext.ToLower().Contains("txt") || ext.ToLower().Contains("gif") || ext.ToLower().Contains("jpg") || ext.ToLower().Contains("jpeg") || ext.ToLower().Contains("png") || ext.ToLower().Contains(".xls") || ext.ToLower().Contains(".docx") || ext.ToLower().Contains(".xlsx") || ext.ToLower().Contains(".pdf")) { NewPhotoID = ImgPrefix + fileId + ext; PhotoPath = ConfigurationManager.AppSettings["PhotoPath"]; PhysicalPhPath = Path.Combine(Server.MapPath(PhotoPath), NewPhotoID); filesToDelete = ImgPrefix + "*"; // Only delete files containing "membercode+photo" in their filenames fileList = System.IO.Directory.GetFiles(Server.MapPath(PhotoPath), filesToDelete); foreach (string files in fileList) { System.IO.File.Delete(files); } file.SaveAs(PhysicalPhPath); DBPhotoPath = PhotoPath + "\\" + NewPhotoID; } var NewFile = new FileDetail { AttachFileName = fileName, FileType = ext, Size = fSize, FileSourcePath = PhysicalPhPath, MainID = MainID, }; _fileDetailService.Add(NewFile); _fileDetailService.Save(); } } //FileMain FileMainInfo = new FileMain(); var FileMainUp = _fileMainService.All().Where(x => x.MainID == MainID).FirstOrDefault(); FileMainUp.FileNo = (string)obj1["fMain"]["FileID"]; FileMainUp.FileSub = (string)obj1["fMain"]["FileSub"]; FileMainUp.FileRef = (string)obj1["fMain"]["FileRef"]; FileMainUp.FileText = (string)obj1["fMain"]["FileText"]; FileMainUp.AttachNum = Convert.ToByte(PhotoFile.Count); //FileMainInfo.FileID = 1; FileMainUp.UserID = Convert.ToInt32(Session["UserID"].ToString()); FileMainUp.VersionNo = _actionListService.All().Select(x => x.ActDesc).FirstOrDefault(); FileMainUp.UpdUserID = Convert.ToInt32(Session["UserID"].ToString()); FileMainUp.CreateDate = DateTime.Now; FileMainUp.LastUpdDate = DateTime.Now; _fileMainService.Update(FileMainUp); _fileMainService.Save(); } return(Json("1", JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json("0", JsonRequestBehavior.AllowGet)); } }