Example #1
0
        public async Task <(bool success, string result)> ProcessFilesToSendToMC(int portalProfileId, string rootPath)
        {
            var profile = await _rpMCredit.GetTemProfileByIdAsync(portalProfileId);

            if (!profile.success)
            {
                return(false, profile.error);
            }
            if (string.IsNullOrWhiteSpace(profile.data.MCId))
            {
                return(false, "Không tìm thấy McId");
            }
            var files = await _rpFile.GetFilesByProfileIdAsync((int)ProfileType.MCredit, portalProfileId);

            if (files == null || !files.Any())
            {
                return(false, "files are empty");
            }
            var jsonFile  = new McJsonFile();
            var filePaths = new List <string>();

            try
            {
                foreach (var f in files)
                {
                    var group = jsonFile.groups.FirstOrDefault(p => p.id == f.MC_GroupId);
                    if (group == null)
                    {
                        group = new McJsonFileGroup {
                            id = f.MC_GroupId, docs = new List <MCJsonFileGroupDoc>()
                        };
                        jsonFile.groups.Add(group);
                    }
                    var doc = group.docs.FirstOrDefault(p => p.code == f.DocumentCode);
                    if (doc == null)
                    {
                        doc = new MCJsonFileGroupDoc {
                            code = f.DocumentCode, files = new List <MCJsonFileGroupDocFile>()
                        };
                        group.docs.Add(doc);
                    }

                    doc.files.Add(new MCJsonFileGroupDocFile {
                        name = f.FileName
                    });

                    filePaths.Add(System.IO.Path.Combine(f.Folder, f.FileName));
                }
                var jsonFileInfo = CreateJsonFile(jsonFile, profile.data.MCId, rootPath);
                filePaths.Add(jsonFileInfo.FullPath);
                var result = await CreateZipFile(filePaths, jsonFileInfo.Folder, profile.data.MCId);

                return(true, result);
            }
            catch (Exception e)
            {
                return(false, e.Dump());
            }
        }
Example #2
0
        public async Task <string> ProcessFilesToSendToMC(int profileId, string rootPath)
        {
            string mcProfileId = string.Empty;
            var    profile     = await _rpMCredit.GetTemProfileById(profileId);

            mcProfileId = profile.MCId;
            if (string.IsNullOrWhiteSpace(mcProfileId))
            {
                return(string.Empty);
            }
            if (profile == null || string.IsNullOrWhiteSpace(profile.MCId))
            {
                return(string.Empty);
            }
            var files = await _rpTailieu.GetTailieuByHosoId(profileId, (int)HosoType.MCredit);

            if (files == null || !files.Any())
            {
                return("files_is_empty");
            }
            var jsonFile = new McJsonFile();
            var x        = files.Select(p => p.MC_GroupId);
            //string values = "";
            var filePaths = new List <string>();

            foreach (var f in files)
            {
                var group = jsonFile.groups.FirstOrDefault(p => p.id == f.MC_GroupId);
                if (group == null)
                {
                    group = new McJsonFileGroup {
                        id = f.MC_GroupId, docs = new List <MCJsonFileGroupDoc>()
                    };
                    jsonFile.groups.Add(group);
                }
                var doc = group.docs.FirstOrDefault(p => p.code == f.DocumentCode);
                if (doc == null)
                {
                    doc = new MCJsonFileGroupDoc {
                        code = f.DocumentCode, files = new List <MCJsonFileGroupDocFile>()
                    };
                    group.docs.Add(doc);
                }
                //var newFile = RenameFile(f.Folder, f.FileName, $"{mcProfileId}-{f.DocumentCode}-{(doc.files.Count + 1)}.jpg");
                doc.files.Add(new MCJsonFileGroupDocFile {
                    name = f.FileName
                });

                filePaths.Add(System.IO.Path.Combine(f.Folder, f.FileName));
            }
            var jsonFileInfo = CreateJsonFile(jsonFile, mcProfileId, rootPath);

            filePaths.Add(jsonFileInfo.FullPath);
            var result = await CreateZipFile(filePaths, jsonFileInfo.Folder, mcProfileId);

            return(result);
        }
Example #3
0
        protected FileModel CreateJsonFile(McJsonFile model, string profileId, string rootPath)
        {
            if (model == null)
            {
                return(null);
            }
            var fileInfo = GetFileUploadUrl("info", rootPath, Utility.FileUtils.GenerateProfileFolderForMc(), true);

            if (fileInfo == null)
            {
                return(null);
            }
            var content = JsonConvert.SerializeObject(model, Formatting.None);

            fileInfo.FullPath = $"{fileInfo.FullPath}.txt";
            Utility.FileUtils.WriteToFile(fileInfo.FullPath, content);
            return(fileInfo);
        }