Пример #1
0
        public JsonResult UploadDocument(Dictionary <int, List <DocumentDetailsModel> > dicDocumentDetailsModel, int acid, int buttonName, int index, string divclone)
        {
            var ErrorDictionary = new Dictionary <string, string>();

            String UploadStatusMsg  = "";
            int    UploadStatusCode = -1; //used to set upload status message - this is default return msg code

            LoginUserDetails   objLoginUserDetails   = null;
            DocumentDetailsDTO objDocumentDetailsDTO = null;

            List <DocumentDetailsModel> lstSaveDetailsModel = null;
            List <Object> lstobject = null;

            try
            {
                string        directory     = ConfigurationManager.AppSettings["Document"];
                string        rootDirectory = directory;
                DirectoryInfo di;

                objLoginUserDetails   = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails);
                objDocumentDetailsDTO = new DocumentDetailsDTO();

                lstSaveDetailsModel = new List <DocumentDetailsModel>();
                lstobject           = new List <object>();
                bool   bFlag         = false; //flag used to
                bool   bReturnStatus = true;
                int    nMapToId      = 0;
                string newFileName   = string.Empty;

                //check dictionary which content document uploade details - if it is not empty
                if (dicDocumentDetailsModel.Count != 0 && dicDocumentDetailsModel.ContainsKey(buttonName))
                {
                    List <DocumentDetailsModel> lstDocumentDetailsModel = new List <DocumentDetailsModel>();
                    List <string> lstExtensions = new List <string>();
                    lstExtensions.Add("pdf");
                    lstExtensions.Add("xls");
                    lstExtensions.Add("xlsx");
                    lstExtensions.Add("doc");
                    lstExtensions.Add("docx");
                    lstExtensions.Add("png");
                    lstExtensions.Add("jpg");
                    lstExtensions.Add("jpeg");
                    //lstExtensions.Add("html");
                    //lstExtensions.Add("htm");
                    lstDocumentDetailsModel = dicDocumentDetailsModel[buttonName];

                    //process each document model
                    foreach (DocumentDetailsModel objDocumentDetailsModel in lstDocumentDetailsModel)
                    {
                        //Check file contains more than one dots
                        if (objDocumentDetailsModel.Document != null)
                        {
                            //check if actual file is uploaded by checking model document property
                            string extension = System.IO.Path.GetExtension(objDocumentDetailsModel.Document.FileName).ToLower();

                            if (extension != ".pdf" && acid == InsiderTrading.Common.ConstEnum.UserActions.CO_DISCLOSURE_DETAILS_CONTINUOUS_DISCLOSURE_LETTER_SUBMISSION && objLoginUserDetails.CompanyName.ToUpper().Contains(InsiderTrading.Common.ConstEnum.CLIENT_DB_NAME_IGNORE_DATABASE))
                            {
                                UploadStatusCode = 5;
                            }
                            else if (extension != ".html" && extension != ".htm" && acid == InsiderTrading.Common.ConstEnum.UserActions.COMPANY_VIEW)
                            {
                                UploadStatusCode = 6;
                            }
                            else
                            {
                                if (lstExtensions.Contains(extension.Remove(0, 1)))
                                {
                                    extension   = System.IO.Path.GetExtension(objDocumentDetailsModel.Document.FileName).ToLower();
                                    newFileName = Guid.NewGuid() + extension;

                                    //check if document is uploaded for first time or updating existing document
                                    if (objDocumentDetailsModel.MapToId != 0)
                                    {
                                        //updating existing document record
                                        bFlag    = true;
                                        nMapToId = objDocumentDetailsModel.MapToId;
                                        lstSaveDetailsModel.Add(objDocumentDetailsModel);
                                    }
                                    Common.Common.CopyObjectPropertyByName(objDocumentDetailsModel, objDocumentDetailsDTO);
                                    objDocumentDetailsDTO.DocumentName = objDocumentDetailsModel.Document.FileName;
                                    objDocumentDetailsDTO.GUID         = newFileName;
                                    objDocumentDetailsDTO.DocumentPath = Path.Combine(directory, newFileName);
                                    objDocumentDetailsDTO.FileSize     = objDocumentDetailsModel.Document.ContentLength;
                                    objDocumentDetailsDTO.FileType     = extension;

                                    //get temp folder path
                                    directory = Path.Combine(directory, "temp");

                                    //if temp directory not exists then create temp folder
                                    if (!Directory.Exists(directory))
                                    {
                                        di = Directory.CreateDirectory(directory);
                                    }

                                    //check guid is set or document id set then remove temp folder file
                                    if ((objDocumentDetailsModel.DocumentId != 0 && objDocumentDetailsModel.DocumentId != null) || objDocumentDetailsModel.GUID != null)
                                    {
                                        //get file object and delete file
                                        FileInfo file = new FileInfo(Path.Combine(rootDirectory, "temp", objDocumentDetailsModel.GUID));
                                        file.Delete();
                                        //remove guid stored in session
                                        objLoginUserDetails.DocumentDetails.Remove(objDocumentDetailsModel.GUID);
                                    }
                                    //save file into temp folder with new name as guid
                                    objDocumentDetailsModel.Document.SaveAs(Path.Combine(directory, newFileName));

                                    //add uploaded file info into session variable
                                    objLoginUserDetails.DocumentDetails.Add(newFileName, objDocumentDetailsDTO);

                                    //save file information into user session
                                    Common.Common.SetSessionValue(ConstEnum.SessionValue.UserDetails, objLoginUserDetails);

                                    string IsofficeInstalled = ConfigurationManager.AppSettings["IsOfficeInstalled"];
                                    ///This block is used to check whether office is installed on server
                                    if (IsofficeInstalled == "true")
                                    {
                                        if (extension == ".doc" || extension == ".docx")
                                        {
                                            Microsoft.Office.Interop.Word._Application _appWord = new Microsoft.Office.Interop.Word.Application();
                                            Microsoft.Office.Interop.Word.Document     doc      = null;
                                            string pathToWordFile = Path.Combine(directory, newFileName);
                                            bool   _hasMacroWord  = false;
                                            try
                                            {
                                                doc = _appWord.Documents.Open(pathToWordFile, Type.Missing, true);
                                                Microsoft.Office.Interop.Word.Application wordApplication = new Microsoft.Office.Interop.Word.Application();
                                                wordApplication.DisplayAlerts         = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
                                                wordApplication.ShowVisualBasicEditor = false;
                                                _hasMacroWord = doc.HasVBProject;
                                                if (_hasMacroWord)
                                                {
                                                    UploadStatusCode = 4;
                                                }
                                                else
                                                {
                                                    UploadStatusCode = 0;
                                                }
                                                doc.Close(Type.Missing, Type.Missing, Type.Missing);
                                                // _appWord.Application.Quit(); // optional
                                                _appWord.Quit();
                                                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(_appWord);
                                                _appWord = null;
                                                if (UploadStatusCode == 4)
                                                {
                                                    //get file object and delete file
                                                    FileInfo file = new FileInfo(Path.Combine(rootDirectory, "temp", newFileName));
                                                    file.Delete();
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                                // optional: this Log function should be defined somewhere in your code                                     }
                                            }
                                            finally
                                            {
                                                if (_appWord != null)
                                                {
                                                    _appWord.Quit();
                                                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(_appWord);
                                                }
                                            }
                                        }
                                        else if (extension == ".xls" || extension == ".xlsx")
                                        {
                                            Microsoft.Office.Interop.Excel._Application _appExcel = new Microsoft.Office.Interop.Excel.Application();
                                            Microsoft.Office.Interop.Excel.Workbook     _workbook = null;
                                            string pathToExcelFile = Path.Combine(directory, newFileName);
                                            bool   _hasMacro       = false;
                                            try
                                            {
                                                _workbook = _appExcel.Workbooks.Open(pathToExcelFile, Type.Missing, true);
                                                _hasMacro = _workbook.HasVBProject;
                                                if (_hasMacro)
                                                {
                                                    UploadStatusCode = 4;
                                                }
                                                else
                                                {
                                                    //lstobject.Add(dic); //set uploaded file into list to return
                                                    UploadStatusCode = 0;
                                                }
                                                _workbook.Close(false, Type.Missing, Type.Missing);
                                                _appExcel.Application.Quit();
                                                _appExcel.Quit();
                                                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(_appExcel);
                                                _appExcel = null;
                                                if (UploadStatusCode == 4)
                                                {
                                                    FileInfo file = new FileInfo(Path.Combine(rootDirectory, "temp", newFileName));
                                                    file.Delete();
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                                // optional: this Log function should be defined somewhere in your code
                                            }
                                            finally
                                            {
                                                if (_appExcel != null)
                                                {
                                                    _appExcel.Quit();
                                                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(_appExcel);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            UploadStatusCode = 0;     //set return msg code
                                        }
                                    }
                                    else
                                    {
                                        UploadStatusCode = 0;     //set return msg code
                                    }
                                    //block end


                                    if (UploadStatusCode != 4)
                                    {
                                        //set uploaded file information into dictionary to sent back as output
                                        Dictionary <string, string> dic = new Dictionary <string, string>();
                                        dic.Add("GUID", objDocumentDetailsDTO.GUID);
                                        dic.Add("DocumentID", objDocumentDetailsDTO.DocumentId.ToString());
                                        dic.Add("Index", objDocumentDetailsModel.Index.ToString());
                                        dic.Add("SubIndex", objDocumentDetailsModel.SubIndex.ToString());
                                        dic.Add("DocumentName", objDocumentDetailsDTO.DocumentName);
                                        dic.Add("FileType", objDocumentDetailsDTO.FileType);
                                        dic.Add("UserAction", acid.ToString());
                                        lstobject.Add(dic);     //set uploaded file into list to return
                                        UploadStatusCode = 0;   //set return msg code
                                    }
                                }
                                else
                                {
                                    UploadStatusCode = 3;     //set return msg code
                                }
                            }
                        }
                        else
                        {
                            //UploadStatusCode = 2; //set return msg code
                        }
                    }

                    //upload and update existing records
                    if (bFlag == true && UploadStatusCode != 4)
                    {
                        using (DocumentDetailsSL objDocumentDetailsSL = new DocumentDetailsSL())
                        {
                            List <DocumentDetailsModel> retlistDocumentDetailsModel = new List <DocumentDetailsModel>();

                            FileInfo file = new FileInfo(Path.Combine(rootDirectory, "temp", newFileName));
                            file.Delete();
                            //as uploading file for already existing record which has MaptoId - upload/save record directly
                            retlistDocumentDetailsModel = objDocumentDetailsSL.SaveDocumentDetails(objLoginUserDetails.CompanyDBConnectionString, lstSaveDetailsModel, buttonName, nMapToId, objLoginUserDetails.LoggedInUserID);

                            lstobject.Clear();

                            foreach (DocumentDetailsModel objDocModel in retlistDocumentDetailsModel)
                            {
                                //set uploaded file information into dictionary to sent back as output
                                Dictionary <string, string> dic = new Dictionary <string, string>();
                                dic.Add("GUID", objDocModel.GUID);
                                dic.Add("DocumentID", objDocModel.DocumentId.ToString());
                                dic.Add("Index", objDocModel.Index.ToString());
                                dic.Add("SubIndex", objDocModel.SubIndex.ToString());
                                dic.Add("DocumentName", objDocModel.DocumentName);
                                dic.Add("FileType", objDocModel.FileType);
                                dic.Add("UserAction", acid.ToString());

                                lstobject.Add(dic);   //set uploaded file into list to return

                                UploadStatusCode = 0; //set return msg code
                            }
                        }
                    }

                    lstExtensions = null;
                }
                else
                {
                    UploadStatusCode = 1; //set return msg code
                }

                switch (UploadStatusCode)
                {
                case 0:
                    UploadStatusMsg = "Document uploaded successfully";
                    break;

                case 1:
                    UploadStatusMsg = "Error occured while uploading file. Please try again";
                    bReturnStatus   = false;
                    break;

                case 2:
                    UploadStatusMsg = "File is not attached properly and thus not able to upload file. Please try again";
                    bReturnStatus   = false;
                    break;

                case 3:
                    UploadStatusMsg = "Only following file types can be uploaded: pdf,xls,xlsx,doc,docx,png,jpg,jpeg";
                    bReturnStatus   = false;
                    break;

                case 4:
                    UploadStatusMsg = "Uploaded file contains macros, please remove it and then upload";
                    bReturnStatus   = false;
                    break;

                case 5:
                    UploadStatusMsg = "Only pdf file can be uploaded";
                    bReturnStatus   = false;
                    break;

                case 6:
                    UploadStatusMsg = "Only html file can be uploaded";
                    bReturnStatus   = false;
                    break;

                default:
                    UploadStatusMsg = "Error occured while uploading file. Please try again";
                    bReturnStatus   = false;
                    break;
                }

                ErrorDictionary.Add("Document", UploadStatusMsg);

                return(Json(new
                {
                    status = bReturnStatus,
                    Message = ErrorDictionary,
                    obj = lstobject,
                    divclone = divclone
                }, "text/html"));
            }
            catch (Exception exp)
            {
                return(null);
            }
            finally
            {
                objLoginUserDetails   = null;
                objDocumentDetailsDTO = null;
                lstSaveDetailsModel   = null;
            }
        }
Пример #2
0
        public ActionResult SaveImportedRecordsProc(int acid, MassUploadModel objMassUploadModel, Dictionary <int, List <DocumentDetailsModel> > dicPolicyDocumentsUploadFileList, int massuploadid)
        {
            LoginUserDetails objLoginUserDetails   = null;
            string           sCurrentCompanyDBName = "";
            string           sConnectionString     = "";
            CompanyDTO       objCompanyToMassUpload;

            Dictionary <string, DocumentDetailsDTO> objDocumentDetailsdDTO = new Dictionary <string, DocumentDetailsDTO>();
            string sFilePath     = "";
            string sFileName     = "";
            string sErrorMessage = "";
            //objDocumentDetailsdDTO.
            string directory = ConfigurationManager.AppSettings["Document"];
            Dictionary <string, List <MassUploadResponseDTO> > objSheetWiseError = new Dictionary <string, List <MassUploadResponseDTO> >();
            Dictionary <string, string> objInvalidSheetColumnError = new Dictionary <string, string>();
            MassUploadDTO objSelectedMassUploadDTO = new MassUploadDTO();

            string sErrorFileGuid           = "";
            bool   bErrorExistInExcelSheets = false;
            bool   bCheckifExcelIsvalid     = false;
            int    nSavedMassUploadLogId    = 0;

            try
            {
                objLoginUserDetails    = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)InsiderTrading.Common.ConstEnum.SessionValue.UserDetails);
                objDocumentDetailsdDTO = objLoginUserDetails.DocumentDetails;
                sCurrentCompanyDBName  = objLoginUserDetails.CompanyName;
                sConnectionString      = objLoginUserDetails.CompanyDBConnectionString;

                using (var objCompaniesSL = new CompaniesSL())
                {
                    objCompanyToMassUpload = objCompaniesSL.getSingleCompanies(Common.Common.getSystemConnectionString(), objLoginUserDetails.CompanyName);
                }
                sConnectionString = objCompanyToMassUpload.CompanyConnectionStringWithTimeout(5000);
                ViewBag.acid      = acid;
                if (dicPolicyDocumentsUploadFileList.ContainsKey(InsiderTrading.Common.ConstEnum.Code.MassUpload) && dicPolicyDocumentsUploadFileList[InsiderTrading.Common.ConstEnum.Code.MassUpload].Count > 0)
                {
                    if (dicPolicyDocumentsUploadFileList[InsiderTrading.Common.ConstEnum.Code.MassUpload].Count > 0)
                    {
                        using (var objMassUploadSL = new MassUploadSL())
                        {
                            objSelectedMassUploadDTO = objMassUploadSL.GetSingleMassUploadDetails(sConnectionString, massuploadid);
                        }
                        string sUploadedFileOriginalName = dicPolicyDocumentsUploadFileList[InsiderTrading.Common.ConstEnum.Code.MassUpload][0].DocumentName;
                        sUploadedFileOriginalName = sUploadedFileOriginalName.Substring(0, sUploadedFileOriginalName.IndexOf("."));
                        if (objSelectedMassUploadDTO.TemplateFileName != sUploadedFileOriginalName)
                        {
                            sErrorMessage            = "The selected file name does not match with the Template to be used for \"" + objSelectedMassUploadDTO.MassUploadName + "\". Please select correct file and try again.";
                            TempData["ErrorMessage"] = sErrorMessage;
                            TempData["IsError"]      = "1";
                            return(RedirectToAction("OpenFileUploadDialog", "MassUpload", new { acid = ViewBag.acid, massuploadid = massuploadid }));
                        }

                        sFileName = dicPolicyDocumentsUploadFileList[InsiderTrading.Common.ConstEnum.Code.MassUpload][0].GUID;
                    }
                    sFilePath = directory + "temp/" + sFileName;
                }

                if (sFileName == null || sFileName == "" || sFilePath == "")
                {
                    sErrorMessage            = "File not selected.";
                    TempData["ErrorMessage"] = sErrorMessage;
                    TempData["IsError"]      = "1";
                    return(RedirectToAction("OpenFileUploadDialog", "MassUpload", new { acid = ViewBag.acid, massuploadid = massuploadid }));
                }
                using (var objParameterisedMassUploadSL = new MassUploadSL(massuploadid, sConnectionString, sCurrentCompanyDBName))
                {
                    //objMassUploadSL = new InsiderTradingMassUpload.MassUploadSL(massuploadid, sConnectionString, sCurrentCompanyDBName);
                    //Add entry in the Log table and generate the MapToId (i.e. the log table id) for the document to be saved.
                    objParameterisedMassUploadSL.AddUpdateLogEntry(objLoginUserDetails.CompanyDBConnectionString, 0, massuploadid, InsiderTrading.Common.ConstEnum.Code.MassUploadStarted, null, "", "", objLoginUserDetails.LoggedInUserID, out nSavedMassUploadLogId);
                    //Save the document and add entry in the Document table
                    List <DocumentDetailsModel> objSavedDocumentDetialsModelList = new List <DocumentDetailsModel>();
                    using (var objDocumentDetailsSL = new DocumentDetailsSL())
                    {
                        objSavedDocumentDetialsModelList = objDocumentDetailsSL.SaveDocumentDetails(objLoginUserDetails.CompanyDBConnectionString, dicPolicyDocumentsUploadFileList[InsiderTrading.Common.ConstEnum.Code.MassUpload], Convert.ToInt32(InsiderTrading.Common.ConstEnum.Code.MassUpload), nSavedMassUploadLogId, objLoginUserDetails.LoggedInUserID);
                    }

                    objParameterisedMassUploadSL.AddUpdateLogEntry(objLoginUserDetails.CompanyDBConnectionString, nSavedMassUploadLogId, massuploadid, InsiderTrading.Common.ConstEnum.Code.MassUploadStarted, objSavedDocumentDetialsModelList[0].DocumentId, "", "", objLoginUserDetails.LoggedInUserID, out nSavedMassUploadLogId);
                    objParameterisedMassUploadSL.SetUploadedfileGUID(objSavedDocumentDetialsModelList[0].GUID);
                    sFilePath = objSavedDocumentDetialsModelList[0].DocumentPath;
                    objParameterisedMassUploadSL.SetExcelFilePath(sFilePath);
                    objParameterisedMassUploadSL.SetEncryptionSaltValue(Common.ConstEnum.User_Password_Encryption_Key);

                    objParameterisedMassUploadSL.ExecuteMassUploadCall();

                    bCheckifExcelIsvalid = objParameterisedMassUploadSL.IsExcelValid();

                    if (!bCheckifExcelIsvalid)
                    {
                        //Check if there are errors in the excel sheet before processing it for mass upload insert.
                        //If all the data from the excel is valid then only let user impoert the excel file.
                        bErrorExistInExcelSheets = objParameterisedMassUploadSL.CheckIfErrorExistInExcelSheets();
                        Dictionary <string, List <MassUploadExcelSheetErrors> > objAllSheetColumnWiseErrorList = objParameterisedMassUploadSL.GetExcelSheetWiseErrors();

                        if (bErrorExistInExcelSheets)
                        {
                            TempData["AllSheetErrors"]        = objAllSheetColumnWiseErrorList;
                            TempData["AllSheetErrorsPresent"] = bErrorExistInExcelSheets;
                            sErrorFileGuid = objParameterisedMassUploadSL.WriteErrorsToExcel(ConfigurationManager.AppSettings["ExportDocument"], ConfigurationManager.AppSettings["Document"]);
                            //Update the error log file name in log table
                            objParameterisedMassUploadSL.AddUpdateLogEntry(objLoginUserDetails.CompanyDBConnectionString, nSavedMassUploadLogId, massuploadid, Common.ConstEnum.Code.MassUploadFailed, null, sErrorFileGuid + ".xlsx", "", objLoginUserDetails.LoggedInUserID, out nSavedMassUploadLogId);
                            TempData["ErrorFileGuid"]  = sErrorFileGuid;
                            TempData["SuccessMessage"] = "Successfully Imported the Excel";
                        }
                    }
                    else
                    {
                        sErrorMessage = "Uploaded excel is not valid. Please use the provided template for corresponding mass upload and try again.";
                        objParameterisedMassUploadSL.AddUpdateLogEntry(objLoginUserDetails.CompanyDBConnectionString, nSavedMassUploadLogId, massuploadid, Common.ConstEnum.Code.MassUploadFailed, null, "", sErrorMessage, objLoginUserDetails.LoggedInUserID, out nSavedMassUploadLogId);
                    }
                }
            }
            catch (Exception exp)
            {
                sErrorMessage = exp.Message;
                if (exp.Source == "Microsoft JET Database Engine")
                {
                    sErrorMessage = "Uploaded excel is not valid. Please use the provided template for corresponding mass upload and try again.";
                }
                using (var objMassUploadSL = new MassUploadSL())
                {
                    objMassUploadSL.AddUpdateLogEntry(objLoginUserDetails.CompanyDBConnectionString, nSavedMassUploadLogId, massuploadid, Common.ConstEnum.Code.MassUploadFailed, null, "", sErrorMessage, objLoginUserDetails.LoggedInUserID, out nSavedMassUploadLogId);
                }
            }
            finally
            {
                //objLoginUserDetails = null;
                objCompanyToMassUpload     = null;;
                objDocumentDetailsdDTO     = null;
                objSheetWiseError          = null;
                objInvalidSheetColumnError = null;
                objSelectedMassUploadDTO   = null;
            }
            //TempData is equivalent to ViewBag, but TempData is used when sending the data during redirection
            if ((sErrorMessage != null && sErrorMessage != "") || bErrorExistInExcelSheets)
            {
                TempData["ErrorMessage"] = sErrorMessage;
                TempData["IsError"]      = "1";
            }
            else
            {
                TempData["SuccessMessage"] = "Successfully Imported the Excel";
                TempData["IsError"]        = "0";
                using (var objMassUploadSL = new MassUploadSL())
                {
                    objMassUploadSL.AddUpdateLogEntry(objLoginUserDetails.CompanyDBConnectionString, nSavedMassUploadLogId, massuploadid, Common.ConstEnum.Code.MassUploadCompleted, null, "", "", objLoginUserDetails.LoggedInUserID, out nSavedMassUploadLogId);
                }
            }
            objMassUploadModel.MassUploadFile = Common.Common.GenerateDocumentList(Common.ConstEnum.Code.MassUpload, 0, 0, null, 0);
            return(RedirectToAction("OpenFileUploadDialog", "MassUpload", new { acid = ViewBag.acid, massuploadid = massuploadid }));
        }
Пример #3
0
        public JsonResult SaveDocumentDetails(int nMapToTypeCodeId, int nMapToId, string sDocName, string sDocDescription, int acid, string GUID, int nDocumentDetailsID = 0)
        {
            bool statusFlag      = false;
            var  ErrorDictionary = new Dictionary <string, string>();

            LoginUserDetails            objLoginUserDetails     = null;
            DocumentDetailsDTO          objDocumentDetailsDTO   = null;
            List <DocumentDetailsModel> lstDocumentDetailsModel = null;
            DocumentDetailsModel        objDocumentDetailsModel = null;

            try
            {
                if (GUID == null || GUID == "")
                {
                    string sErrMessage = "Please Upload Document";
                    ErrorDictionary.Add("Document", sErrMessage);
                }
                else
                {
                    objLoginUserDetails   = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails);
                    objDocumentDetailsDTO = new DocumentDetailsDTO();

                    lstDocumentDetailsModel = new List <DocumentDetailsModel>();

                    objDocumentDetailsModel = new DocumentDetailsModel();

                    objDocumentDetailsModel.MapToTypeCodeId = nMapToTypeCodeId;
                    objDocumentDetailsModel.MapToId         = nMapToId;
                    objDocumentDetailsModel.DocumentId      = nDocumentDetailsID;
                    objDocumentDetailsModel.GUID            = GUID;
                    objDocumentDetailsModel.DocumentName    = sDocName;
                    objDocumentDetailsModel.Description     = sDocDescription;
                    lstDocumentDetailsModel.Add(objDocumentDetailsModel);

                    using (DocumentDetailsSL objDocumentDetailsSL = new DocumentDetailsSL())
                    {
                        lstDocumentDetailsModel = objDocumentDetailsSL.SaveDocumentDetails(objLoginUserDetails.CompanyDBConnectionString, lstDocumentDetailsModel, nMapToTypeCodeId, nMapToId, objLoginUserDetails.LoggedInUserID);

                        if (lstDocumentDetailsModel.Count > 0)
                        {
                            statusFlag = true;
                        }
                    }
                }
                return(Json(new
                {
                    status = statusFlag,
                    Message = ErrorDictionary
                }, "text/html"));
            }
            catch (Exception exp)
            {
                throw exp;
            }
            finally
            {
                objLoginUserDetails     = null;
                objDocumentDetailsDTO   = null;
                lstDocumentDetailsModel = null;
                objDocumentDetailsModel = null;
            }
        }
Пример #4
0
        public ActionResult Save(InsiderTrading.Models.NSEGroupDocumentMappingModel objNSEGroupDocumentModel, Dictionary <int, List <DocumentDetailsModel> > dicPolicyDocumentsUploadFileList, int GroupId)
        {
            ModelState.Remove("KEY");
            ModelState.Add("KEY", new ModelState());
            ModelState.Clear();
            var StockExchangeDateSubmission = Request.Form["SubmissionFromDate"];
            LoginUserDetails            objLoginUserDetails  = null;
            DocumentDetailsSL           objDocumentDetailsSL = new DocumentDetailsSL();
            List <DocumentDetailsModel> UploadFileDocumentDetailsModelList = null;
            NSEGroupDocumentMappingDTO  objNSEGroupDocDTO     = new NSEGroupDocumentMappingDTO();
            NSEGroupDetailsDTO          objNSEGroupDetailsDTO = new NSEGroupDetailsDTO();
            NSEGroupDTO objNSEGroupDTO = new NSEGroupDTO();

            objLoginUserDetails = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails);
            DateTime?date = null;

            using (NSEGroupSL ObjNSEGroupSL = new NSEGroupSL())
            {
                List <NSEGroupDTO> lstDate = ObjNSEGroupSL.Get_Group_Date(objLoginUserDetails.CompanyDBConnectionString, GroupId);
                foreach (var submitdate in lstDate)
                {
                    date = submitdate.DownloadedDate;
                }
            }
            if (StockExchangeDateSubmission == "")
            {
                ModelState.AddModelError("DateOfSubmissionToNSE", Common.Common.getResource("nse_lbl_50535"));
            }
            else
            {
                objNSEGroupDTO.SubmissionDate = Convert.ToDateTime(StockExchangeDateSubmission);
                if (objNSEGroupDTO.SubmissionDate > Common.Common.GetCurrentDate(objLoginUserDetails.CompanyDBConnectionString))
                {
                    ModelState.AddModelError("DateOfSubmissionToNSE", Common.Common.getResource("nse_lbl_50534"));
                }
                if (Convert.ToDateTime(date).Date > objNSEGroupDTO.SubmissionDate)
                {
                    ModelState.AddModelError("DateOfSubmissionToNSE", Common.Common.getResource("nse_lbl_50536"));
                }
            }
            if (ModelState.IsValid)
            {
                if (dicPolicyDocumentsUploadFileList.Count > 0) // file is uploaded and data found for file upload
                {
                    UploadFileDocumentDetailsModelList = dicPolicyDocumentsUploadFileList[ConstEnum.Code.UploadNseDocument];
                }
                List <DocumentDetailsModel> objSavedDocumentDetialsModelList = objDocumentDetailsSL.SaveDocumentDetails(objLoginUserDetails.CompanyDBConnectionString, UploadFileDocumentDetailsModelList, ConstEnum.Code.UploadNseDocument, GroupId, objLoginUserDetails.LoggedInUserID, objLoginUserDetails.CompanyName);
                DocumentDetailsDTO          objDocumentDetailsDTO            = null;
                objDocumentDetailsDTO = new DocumentDetailsDTO();
                using (NSEGroupSL objNSEGroupSL = new NSEGroupSL())
                {
                    if (UploadFileDocumentDetailsModelList != null)
                    {
                        foreach (var fleGUID in UploadFileDocumentDetailsModelList)
                        {
                            objNSEGroupDetailsDTO.LoggedInUserId = objLoginUserDetails.LoggedInUserID;
                            objNSEGroupDetailsDTO.GroupId        = GroupId;
                            List <NSEGroupDetailsDTO> GrouplistDetails = objNSEGroupSL.Save_NSEGroup_Details(objLoginUserDetails.CompanyDBConnectionString, objNSEGroupDetailsDTO);
                            foreach (var nseuserId in GrouplistDetails)
                            {
                                objNSEGroupDocDTO.NSEGroupDetailsId = nseuserId.NSEGroupDetailsId;
                                objNSEGroupDetailsDTO.GroupId       = Convert.ToInt32(GroupId);
                                bool bReturnDoc = objNSEGroupSL.Save_New_NSEDocument(objLoginUserDetails.CompanyDBConnectionString, objNSEGroupDocDTO, fleGUID.GUID);
                            }
                        }
                    }
                    objNSEGroupDTO.GroupId        = GroupId;
                    objNSEGroupDTO.LoggedInUserId = objLoginUserDetails.LoggedInUserID;
                    objNSEGroupDTO.StatusCodeId   = 508007;
                    bool bReturn = objNSEGroupSL.Update_NSEGroup(objLoginUserDetails.CompanyDBConnectionString, objNSEGroupDTO);
                }
                TradingTransactionMasterDTO objTradingTransactionMasterDTO = null;
                using (TradingTransactionSL objTradingTransactionSL = new TradingTransactionSL())
                {
                    using (NSEGroupSL objNSEGroupSL = new NSEGroupSL())
                    {
                        List <NSEGroupDetailsDTO> grpTransIdList = objNSEGroupSL.Get_Group_TransactionId(objLoginUserDetails.CompanyDBConnectionString, GroupId);
                        foreach (var TransId in grpTransIdList)
                        {
                            objTradingTransactionMasterDTO = new TradingTransactionMasterDTO();
                            objTradingTransactionMasterDTO.TransactionMasterId        = TransId.transId;
                            objTradingTransactionMasterDTO.TransactionStatusCodeId    = ConstEnum.Code.DisclosureStatusForHardCopySubmittedByCO;
                            objTradingTransactionMasterDTO.HardCopyByCOSubmissionDate = Convert.ToDateTime(StockExchangeDateSubmission);
                            objTradingTransactionMasterDTO = objTradingTransactionSL.GetTradingTransactionMasterCreate(objLoginUserDetails.CompanyDBConnectionString, objTradingTransactionMasterDTO, objLoginUserDetails.LoggedInUserID, out nDisclosureCompletedFlag);
                        }
                    }
                }
                return(RedirectToAction("Index", "NSEDownload", new { acid = ConstEnum.UserActions.NSEDownload }));
            }
            else
            {
                ViewBag.groupId      = GroupId;
                ViewBag.DownloadDate = date;
                ViewBag.UserAction   = Common.ConstEnum.UserActions.NSEDownload;
                objNSEGroupDocumentModel.NSEGroupDocumentFile = Common.Common.GenerateDocumentList(ConstEnum.Code.UploadNseDocument, 0, 0, null, 0, false, 0, ConstEnum.FileUploadControlCount.NSEUploadFile);
                return(View("NSEUploadDoc", objNSEGroupDocumentModel));
            }
        }