public ActionResult GetNewFileIdforMoveToProcess(string FileNo)
        {
            //RBACUser rUser = new RBACUser(Session["UserName"].ToString());
            //if (!rUser.HasPermission("Group_Edit"))
            //{
            //    return Json("D", JsonRequestBehavior.AllowGet);
            //}

            try
            {
                FileMain FileMainAdd = new FileMain();
                var      data        = _fileMainService.All().ToList().FirstOrDefault(x => x.FileNo == FileNo);
                var      MainID      = _fileMainService.All().ToList().Where(x => x.FileNo == FileNo).Select(x => x.MainID).FirstOrDefault();
                string   sql         = string.Format(" Select fd.AttachFileName as FileName from FileDetail as fd where MainID= '" + MainID + "' " +
                                                     " union select AttachFileName from FileTransDetail where FileTransID in " +
                                                     "(select FileTransID from FileTransMain where MainID = '" + MainID + "')");
                List <ProcessActionVM> VchrList;
                using (ERPConfigurationContext dbContext = new ERPConfigurationContext())
                {
                    VchrList = dbContext.Database.SqlQuery <ProcessActionVM>(sql).ToList();
                }
                // ViewBag.Items = VchrList;
                if (data != null)
                {
                    FileMainAdd = data;
                }

                return(Json(new { FileMainAdd, VchrList }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json("0", JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult GetAllItem()
        {
            //FileMainInfo.UserID = Convert.ToInt32(Session["UserID"].ToString());
            var uservalid = Convert.ToInt32(Session["UserID"].ToString());

            var FileInfo = _fileMainService.All().ToList().Where(x => x.UserID == uservalid || (x.UpdUserID == uservalid));

            var FileInfoAll = _fileMainService.All();

            //var FileTransNo = _fileMainService.All().Where(x => x.UserID == uservalid).Select(x => x.FileNo).FirstOrDefault();
            //var FileTransInfo = _fileTransMainService.All().Where(x => x.FileID == FileTransNo).Select(x=>x.MarkToID);
            if (uservalid != null)
            {
                List <FileInfos> fInfos = new List <FileInfos>();
                //if (FileInfo!=null)
                //{
                foreach (var item in FileInfo)
                {
                    FileInfos fInfo = new FileInfos();
                    fInfo.FileNo  = item.FileNo;
                    fInfo.FileRef = item.FileRef;
                    fInfo.FileSub = item.FileSub;
                    var openuser      = _fileMainService.All().Where(x => x.FileNo == item.FileNo).Select(x => x.UserID).FirstOrDefault();
                    var openuserstaff = _newStaffService.All().Where(x => x.StaffId == openuser).Select(x => x.StaffName).FirstOrDefault();
                    fInfo.UserName = openuserstaff;

                    var openuserstaffid = _newStaffService.All().Where(x => x.StaffId == openuser).Select(x => x.StaffId).FirstOrDefault();
                    fInfo.UserId = openuserstaffid;

                    var updateUserId = _fileMainService.All().Where(x => x.FileNo == item.FileNo).Select(x => x.UpdUserID).FirstOrDefault();
                    // fInfo.UpdateName = _newStaffService.All().Where(x => x.StaffId == updateUserId).Select(x => x.StaffName).FirstOrDefault();
                    // var approvedCheck = _fileMainService.All().Where(x => x.FileNo == item.FileNo).Select(x => x.VersionNo).LastOrDefault();
                    //var Check = item.VersionNo;
                    var MainId  = _fileMainService.All().Where(x => x.FileNo == item.FileNo).Select(x => x.MainID).FirstOrDefault();
                    var Checkid = _fileTransMainService.All().Where(x => x.MainID == MainId).Select(x => x.ActionID).LastOrDefault();
                    var Check   = _actionListService.All().Where(x => x.ActID == Checkid).Select(x => x.ActDesc).FirstOrDefault();
                    fInfo.approved = _actionListService.All().Where(x => x.ActDesc == Check).Select(x => x.ActID).LastOrDefault();
                    fInfo.Status   = Convert.ToString(Check);
                    if (Check == "New")
                    {
                        fInfo.Status = "New";
                    }
                    //DateTime CurrDate = DateTime.UtcNow;
                    //fInfo.days = (int)(CurrDate.Subtract((DateTime)fInfo.CreateDate)).Days;
                    fInfo.CreateDate = item.CreateDate.ToString("yyyy-MM-dd");
                    fInfo.UpdateUser = updateUserId.ToString();
                    fInfo.LoginUser  = (Session["UserID"].ToString());
                    if (fInfo.UserId == Convert.ToInt64(fInfo.LoginUser) && fInfo.approved == 2)
                    {
                        fInfo.Status = "Processing.....";
                    }
                    fInfos.Add(fInfo);
                }

                if (uservalid == 1002)
                {
                    List <FileInfos> fInfosTr = new List <FileInfos>();
                    foreach (var item in FileInfoAll)
                    {
                        FileInfos fInfoAll = new FileInfos();
                        fInfoAll.FileNo  = item.FileNo;
                        fInfoAll.FileRef = item.FileRef;
                        fInfoAll.FileSub = item.FileSub;
                        var openuser      = _fileMainService.All().Where(x => x.FileNo == item.FileNo).Select(x => x.UserID).FirstOrDefault();
                        var openuserstaff = _newStaffService.All().Where(x => x.StaffId == openuser).Select(x => x.StaffName).FirstOrDefault();
                        fInfoAll.UserName   = openuserstaff;
                        fInfoAll.CreateDate = item.CreateDate.ToString("yyyy-MM-dd");
                        fInfoAll.Status     = item.VersionNo;
                        var updateUserId = _fileMainService.All().Where(x => x.FileNo == item.FileNo).Select(x => x.UpdUserID).FirstOrDefault();
                        fInfoAll.UpdateName = _newStaffService.All().Where(x => x.StaffId == updateUserId).Select(x => x.StaffName).FirstOrDefault();
                        fInfosTr.Add(fInfoAll);

                        return(Json(new { data = fInfoAll }, JsonRequestBehavior.AllowGet));
                    }
                }
                return(Json(new { data = fInfos }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(null);
            }
        }
        public ActionResult SaveNewFile()
        {
            HttpFileCollectionBase PhotoFile = Request.Files;
            var fMain  = Request.Form["fMain"];
            var obj1   = JObject.Parse(fMain);
            var FileNo = (string)obj1["fMain"]["FileID"];

            try
            {
                var fileNoCheck = _fileMainService.All().Where(x => x.FileNo.ToString() == FileNo).Select(x => x.FileNo).FirstOrDefault();

                if (fileNoCheck == null)
                {
                    FileMain FileMainInfo = new FileMain();
                    FileMainInfo.FileNo    = (string)obj1["fMain"]["FileID"];
                    FileMainInfo.FileSub   = (string)obj1["fMain"]["FileSub"];
                    FileMainInfo.FileRef   = (string)obj1["fMain"]["FileRef"];
                    FileMainInfo.FileText  = (string)obj1["fMain"]["FileText"];
                    FileMainInfo.AttachNum = Convert.ToByte(PhotoFile.Count);
                    //FileMainInfo.FileID = 1;
                    FileMainInfo.UserID = Convert.ToInt32(Session["UserID"].ToString());
                    //FileMainInfo.VersionNo = _actionListService.All().Select(x=>x.ActDesc).FirstOrDefault();
                    FileMainInfo.VersionNo   = "New";
                    FileMainInfo.UpdUserID   = Convert.ToInt32(Session["UserID"].ToString());
                    FileMainInfo.CreateDate  = DateTime.Now;
                    FileMainInfo.LastUpdDate = DateTime.Now;
                    _fileMainService.Add(FileMainInfo);
                    _fileMainService.Save();
                }
            }
            catch (Exception ex)
            {
                return(Json("0", JsonRequestBehavior.AllowGet));
            }
            //else
            //{
            //     return Json("2", JsonRequestBehavior.AllowGet);
            //}
            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);
                        ext       = System.IO.Path.GetExtension(fileName);
                        ImgPrefix = FileNo;     //"Photo";//file.ContentType;//
                        int fSize = file.ContentLength;
                        //var path = Path.Combine(Server.MapPath("~/Uploads/Photo/"), MemberCode, fileId);


                        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);
                            //var path = Path.Combine(Server.MapPath("~/Images/Photo"), fileName);
                            file.SaveAs(PhysicalPhPath);

                            DBPhotoPath = PhotoPath + "\\" + NewPhotoID;
                        }
                        var NewFile = new FileDetail
                        {
                            AttachFileName = fileName,
                            FileType       = ext,
                            Size           = fSize,
                            FileSourcePath = PhysicalPhPath,
                            //MainID = (int)obj1["fMain"]["MainID"],
                            MainID = _fileMainService.All().Where(x => x.FileNo == (string)obj1["fMain"]["FileID"]).Select(x => x.MainID).FirstOrDefault(),
                        };
                        _fileDetailService.Add(NewFile);
                        _fileDetailService.Save();
                    }
                }
                return(Json("1", JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json("0", JsonRequestBehavior.AllowGet));
            }
        }