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));
            }
        }
Exemple #2
0
        public ActionResult SaveNewStaff()
        {
            try
            {
                using (var transaction = new TransactionScope())
                {
                    string PhysicalPhPath            = "";
                    HttpFileCollectionBase PhotoFile = Request.Files;
                    //var PhotoFile = Request.Files["PhotoFile"];
                    var fMain   = Request.Form["loadInfo"];
                    var obj1    = JObject.Parse(fMain);
                    var StaffId = (int)obj1["loadInfo"]["StaffId"];
                    try
                    {
                        string fileName    = "";
                        string NewPhotoID  = "";
                        string ImgPrefix   = "";
                        string ext         = "";
                        string fileId      = Guid.NewGuid().ToString().Replace("-", "");
                        string PhotoPath   = "";
                        string DBPhotoPath = "";
                        if (PhotoFile != null)
                        {
                            for (int i = 0; i < PhotoFile.Count; i++)
                            {
                                HttpPostedFileBase file = PhotoFile[i];
                                fileName  = Path.GetFileName(file.FileName);
                                ImgPrefix = "Photo";
                                int fSize = file.ContentLength;
                                //var path = Path.Combine(Server.MapPath("~/Uploads/Photo/"), MemberCode, fileId);

                                ext = System.IO.Path.GetExtension(fileName);
                                if (ext.ToLower().Contains("gif") || ext.ToLower().Contains("jpg") ||
                                    ext.ToLower().Contains("jpeg") ||
                                    ext.ToLower().Contains("png"))
                                {
                                    NewPhotoID     = ImgPrefix + 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;
                                }
                                StaffDetails newStaffDetails = new StaffDetails();
                                var          fileByte        = new byte[file.ContentLength];
                                file.InputStream.Read(fileByte, 0, file.ContentLength);
                                newStaffDetails.File     = fileByte;
                                newStaffDetails.FileName = file.FileName;
                                _staffDetailsAppService.Add(newStaffDetails);
                                _staffDetailsAppService.Save();
                            }
                        }
                    }

                    catch (Exception)
                    {
                        transaction.Dispose();
                        return(Json("0", JsonRequestBehavior.AllowGet));
                    }
                    StaffInfo StaffInfo = new StaffInfo();
                    //StaffInfo = newStaff;
                    StaffInfo.StaffId    = (int)obj1["loadInfo"]["StaffId"];
                    StaffInfo.StaffName  = EncryptionDecryption.DH_PEncode((string)obj1["loadInfo"]["StaffName"]);
                    StaffInfo.LoginName  = EncryptionDecryption.DH_PEncode((string)obj1["loadInfo"]["LoginName"]);
                    StaffInfo.BoundaryId = EncryptionDecryption.DH_PEncodeInt((int)obj1["loadInfo"]["BoundaryId"]);
                    //var boundaryId = EncryptionDecryption.DH_PEncode(Convert.ToString(StaffInfo.BoundaryId));
                    StaffInfo.ReportingId = EncryptionDecryption.DH_PEncodeInt((int)obj1["loadInfo"]["ReportingId"]);
                    StaffInfo.Email       = EncryptionDecryption.DH_PEncode((string)obj1["loadInfo"]["Email"]);
                    StaffInfo.Mobile      = EncryptionDecryption.DH_PEncode((string)obj1["loadInfo"]["Mobile"]);
                    StaffInfo.Password    = EncryptionDecryption.DH_PEncode((string)obj1["loadInfo"]["Password"]);// newStaff.Password;
                    StaffInfo.ConfirmPass = EncryptionDecryption.DH_PEncode((string)obj1["loadInfo"]["ConfirmPass"]);
                    StaffInfo.SignPath    = PhysicalPhPath;
                    StaffInfo.SignPin     = EncryptionDecryption.DH_PEncode((string)obj1["loadInfo"]["SignPin"]);
                    _newStaffService.Add(StaffInfo);
                    _newStaffService.Save();
                    ////EncryptionDecryption.DH_PEncode(StaffInfo.StaffId, StaffInfo.StaffName, StaffInfo.LoginName,
                    // StaffInfo.BoundaryId, StaffInfo.ReportingId, StaffInfo.Email, StaffInfo.Mobile, StaffInfo.Password,
                    // StaffInfo.ConfirmPass);
                    transaction.Complete();
                    return(Json("1", JsonRequestBehavior.AllowGet));
                    //return Json(LoadDropDown.LoadLastStaff(newStaff.StaffId), JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception)
            {
                //transaction.Dispose();
                return(Json("0", JsonRequestBehavior.AllowGet));
            }
        }