Exemple #1
0
 public ActionResult Savepa_fpmain(FileTransMain pafpmain)
 {
     try
     {
         //RBACUser rUser = new RBACUser(Session["UserName"].ToString());
         //if (!rUser.HasPermission("Receive_Insert"))
         //{
         //    return Json("X", JsonRequestBehavior.AllowGet);
         //}
         var IfExit = _FileTransMainService.All().Where(x => x.FileTransID == pafpmain.FileTransID).ToList();
         if (IfExit.Count == 0)
         {
             FileTransMain pa_fpmains = new FileTransMain();
             pa_fpmains = pafpmain;
             //pa_fpmains.ProcessNo = _pafamainService.All().Select(x => x.ProcessNo).LastOrDefault() + 1;
             _FileTransMainService.Add(pa_fpmains);
             _FileTransMainService.Save();
         }
         var ecode = 1;
         return(Json(ecode, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json("0", JsonRequestBehavior.AllowGet));
     }
 }
        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));
            }
        }