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)); } }
public async Task <JsonResult> SubmitToMCredit(MCredit_TempProfileAddModel model) { try { var isAdmin = await _rpEmployee.CheckIsAdmin(GlobalData.User.IDUser); if (!isAdmin) { return(ToJsonResponse(false, "Vui lòng liên hệ Admin")); } if (model == null || model.Id <= 0) { return(ToJsonResponse(false, "Dữ liệu không hợp lệ")); } if (model.SaleId <= 0) { return(ToJsonResponse(false, "Vui lòng chọn Sale")); } var profile = await _rpMCredit.GetTemProfileById(model.Id); if (profile == null) { return(ToJsonResponse(false, "Hồ sơ không tồn tại")); } var profileSql = _mapper.Map <MCredit_TempProfile>(model); profileSql.UpdatedBy = GlobalData.User.IDUser; var profileMC = _mapper.Map <MCProfilePostModel>(model); var files = await _rpTailieu.GetTailieuByHosoId(model.Id, (int)HosoType.MCredit); if (files == null || !files.Any()) { return(ToJsonResponse(false, "Vui lòng upload hồ sơ")); } var result = await _svMCredit.CreateProfile(profileMC, GlobalData.User.IDUser); if (result == null || result.status == "error") { return(ToJsonResponse(false, "", result)); } profileSql.MCId = result.id; profile.Status = (int)MCreditProfileStatus.SentToMc; await _rpMCredit.UpdateDraftProfile(profileSql); await _rpTailieu.UpdateTailieuHosoMCId(model.Id, result.id); var zipFile = await _bizMedia.ProcessFilesToSendToMC(model.Id, Server.MapPath($"~{Utility.FileUtils._profile_parent_folder}")); if (zipFile == "files_is_empty") { return(ToJsonResponse(false, "Vui lòng upload hồ sơ")); } var sendFileResult = await _svMCredit.SendFiles(GlobalData.User.IDUser, zipFile, result.id); return(ToJsonResponse(sendFileResult.status == "success" ? true : false, "", sendFileResult)); //return ToJsonResponse(true, "", new { file = zipFile, id = result.id }); } catch (Exception e) { await _rpLog.InsertLog("SubmitToMCredit", e.InnerException != null?e.InnerException.Dump() : e.Dump()); return(ToJsonResponse(false)); } }