Пример #1
0
        public async Task <MCResponseModelBase> SubmitToMCreditAsync(MCredit_TempProfileAddModel model, string rootPath)
        {
            try
            {
                if (model == null || model.Id <= 0)
                {
                    return(ToResponse <MCResponseModelBase>(null, Errors.invalid_data));
                }
                if (model.SaleId <= 0)
                {
                    return(ToResponse <MCResponseModelBase>(null, "Vui lòng chọn Sale"));
                }

                var profile = await _rpMCredit.GetTemProfileByIdAsync(model.Id);

                if (!profile.success)
                {
                    return(ToResponse <MCResponseModelBase>(null, profile.error));
                }
                if (profile.data == null)
                {
                    return(ToResponse <MCResponseModelBase>(null, "Hồ sơ không tồn tại"));
                }

                var profileMC = _mapper.Map <MCProfilePostModel>(model);

                var files = await _rpFile.GetFilesByProfileIdAsync(model.Id, (int)ProfileType.MCredit);

                if (files == null || !files.Any())
                {
                    return(ToResponse <MCResponseModelBase>(null, "Vui lòng upload hồ sơ"));
                }

                var result = await _svMcredit.CreateProfile(profileMC);

                if (!result.success)
                {
                    return(ToResponse <MCResponseModelBase>(null, result.error));
                }

                if (result.data == null || string.IsNullOrWhiteSpace(result.data.id))
                {
                    return(ToResponse <MCResponseModelBase>(null, "Không thể gửi qua MC"));
                }

                await _rpMCredit.UpdateMCIdAsync(model.Id, result.data.id.Trim(), _process.User.Id);

                await _rpFile.UpdateFileMCProfileByIdAsync(model.Id, result.data.id);

                var bizMedia = _svProvider.GetService <IMediaBusiness>();

                var zipFile = await bizMedia.ProcessFilesToSendToMC(profile.data.Id, $"{rootPath}/{Utility.FileUtils._profile_parent_folder}");

                if (!zipFile.success)
                {
                    return(ToResponse <MCResponseModelBase>(null, zipFile.result));
                }

                var sendFileResult = await _svMcredit.SendFiles(zipFile.result, result.data.id);

                if (!sendFileResult.success)
                {
                    return(ToResponse <MCResponseModelBase>(null, sendFileResult.error));
                }
                await bizMedia.DeleteFile(zipFile.result);

                return(sendFileResult.data);
            }
            catch (Exception e)
            {
                var error = e.InnerException != null?e.InnerException.Dump() : e.Dump();

                await _rpLog.InsertLog("SubmitToMCredit", error);

                return(ToResponse <MCResponseModelBase>(null, error));
            }
        }
Пример #2
0
        public async Task <List <FileProfile> > GetProfileFileTypeByTypeAsync(string profileType, int profileId = 0, string webRootPath = null, string mcId = null)
        {
            if (string.IsNullOrWhiteSpace(profileType))
            {
                AddError("Dữ liệu không hợp lệ");
                return(null);
            }
            profileType = profileType.ToLower();
            int type = 0;

            switch (profileType)
            {
            case "common":
                type = (int)ProfileType.Common;
                break;

            case "courier":
                type = (int)ProfileType.Courier;
                break;

            case "mcredit":
                type = (int)ProfileType.MCredit;
                break;

            case "company":
                type = (int)ProfileType.Company;
                break;

            case "revoke":
                type = (int)ProfileType.RevokeDebt;
                break;
            }
            if (profileType == "mcredit")
            {
                return(await GetFileUploadMcreditAsync(profileId, mcId, webRootPath));
            }
            bool isReadOnly = false;

            if (type == (int)ProfileType.Common)
            {
                var profileResult = await _rpProfile.GetByIdAsync(profileId);

                if (!profileResult.success || profileResult.data == null)
                {
                    isReadOnly = false;
                }
                if ((_process.User.isSale || _process.User.isRsmAsmSS) && profileResult.data.Ma_Trang_Thai != (int)ProfileStatus.Draft)
                {
                    isReadOnly = true;
                }
            }

            var fileTypes = await _rpFile.GetByType(type);

            if (fileTypes == null || !fileTypes.Any())
            {
                return(null);
            }
            var files = await _rpFile.GetFilesByProfileIdAsync(type, profileId);

            var result = new List <FileProfile>();

            foreach (var kind in fileTypes)
            {
                var filesByType = files.Where(p => p.Key == kind.FileKey);
                //foreach (var f in filesByType)
                //{
                //    f.FileUrl = Path.Combine(webRootPath, f.FileUrl);
                //}
                var item = new FileProfile
                {
                    Id            = kind.Id,
                    RootPath      = webRootPath,
                    FileKey       = kind.FileKey,
                    IsRequire     = kind.IsRequire,
                    Name          = kind.Name,
                    ProfileTypeId = kind.ProfileTypeId,
                    IsReadOnly    = isReadOnly,
                    ProfileFiles  = filesByType != null?filesByType.ToList() : new List <FileUploadModel>()
                };
                result.Add(item);
            }
            return(result);
        }