Exemplo n.º 1
0
        public ResponseModel DownloadDefaultReport([FromBody] DefaultReportRequestModel objRequest)
        {
            ResponseModel  objResponseModel = new ResponseModel();
            int            statusCode       = 0;
            string         statusMessage    = "";
            SettingsCaller dbSearchMaster   = new SettingsCaller();
            string         strCSV           = string.Empty;

            try
            {
                string       token        = Convert.ToString(Request.Headers["X-Authorized-Token"]);
                Authenticate authenticate = new Authenticate();

                var temp = SecurityService.DecryptStringAES(token);
                authenticate = SecurityService.GetAuthenticateDataFromTokenCache(Cache, SecurityService.DecryptStringAES(token));

                strCSV = dbSearchMaster.DownloadDefaultReport(new ReportService(Cache, Db), objRequest, authenticate.UserMasterID, authenticate.TenantId);

                string dateformat = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                string csvname    = "DefaultReport" + "_" + dateformat + ".csv";

                var   exePath        = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
                Regex appPathMatcher = new Regex(@"(?<!fil)[A-Za-z]:\\+[\S\s]*?(?=\\+bin)");
                var   appRoot        = appPathMatcher.Match(exePath).Value;

                string Folderpath    = Path.Combine(appRoot, "ReportDownload");
                string URLFolderpath = Path.Combine(rootPath, "ReportDownload");

                if (!Directory.Exists(Folderpath))
                {
                    Directory.CreateDirectory(Folderpath);
                }

                Folderpath    = Path.Combine(Folderpath, csvname);
                URLFolderpath = URLFolderpath + @"/" + csvname;
                CommonService.SaveFile(Folderpath, strCSV);

                statusCode    = (int)EnumMaster.StatusCode.Success;
                statusMessage = CommonFunction.GetEnumDescription((EnumMaster.StatusCode)statusCode);

                objResponseModel.Status     = true;
                objResponseModel.StatusCode = statusCode;
                objResponseModel.Message    = statusMessage;

                if (System.IO.File.Exists(Folderpath))
                {
                    FileInfo fileInfo = new FileInfo(Folderpath);
                    float    sizeInMB = (fileInfo.Length / 1024f) / 1024f;
                    if (sizeInMB > 5)
                    {
                        objResponseModel.ResponseData = !string.IsNullOrEmpty(URLFolderpath) ? URLFolderpath + "@mail" : null;
                    }
                    else
                    {
                        objResponseModel.ResponseData = URLFolderpath;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(objResponseModel);
        }