Exemple #1
0
        protected override Task Handle(CancellationToken cancellationToken)
        {
            var stream = new MemoryStream(Request.Body);

            IList <MfuswiftInfo> mfuswiftInfoList = mFUOperationsHelper.GetMfuswiftInfoList(FileHelper.ExcelExportDataTable(stream));

            var excelFile = Mapper.Map(Request, Entity);

            mFUOperationsHelper.UpdateExcelFile(excelFile, dbContext);

            mFUOperationsHelper.InsertMfuswiftInfoList(mfuswiftInfoList, Request.ExcelFileId, dbContext);

            return(Response.SetSuccessWithEndUserMessage("File Updated Successfully.", "OK").AsTask());
        }
        private ResponseOf <byte[]> GenerateFile(int excelFileId, string userName, string swiftTypeDVP, string swiftTypeDF)
        {
            var fileResponse = new Models.FileResponse();

            var excelFile = dbContext.ExcelFile.FirstOrDefault(x => x.ExcelFileId == excelFileId);

            excelFile.StateMaker = userName;

            fileResponse = CheckFileState(excelFile);

            if (fileResponse.ResponseMessage != null) //fail
            {
                Response.AddMessage(fileResponse.ResponseMessage, "", MessageTypes.Error, isEndUserMessage: true);
                Response.SetFailed();
            }
            else //success
            {
                excelFile.FileStateId = Models.FileState.Processed.Id;
                mFUOperationsHelper.UpdateExcelFile(excelFile, dbContext);

                string userFirstTwhoChar  = userName.ToString().Substring(0, 2).ToUpper();
                string excelFileIdPadLeft = excelFileId.ToString().PadLeft(5, '0') + ".txt";
                string dvpFileName        = userFirstTwhoChar + "543" + excelFileIdPadLeft;
                string dfFileName         = userFirstTwhoChar + "542" + excelFileIdPadLeft;

                var mfUSwiftInfoList = dbContext.MfuswiftInfo.Where(x => x.FileId == excelFileId).ToList();

                fileResponse.ResponseMessage = "Swift messages have been generated SUCCESFULLY. Please check the directory SWIFT MESSAGES.";
                fileResponse.FileNameBodyList.Add(new Models.FileNameBody {
                    Name = dvpFileName, Body = GetDVPFile(mfUSwiftInfoList, dvpFileName, swiftTypeDVP)
                });
                fileResponse.FileNameBodyList.Add(new Models.FileNameBody {
                    Name = dfFileName, Body = GetDFFile(mfUSwiftInfoList, dfFileName, swiftTypeDF)
                });

                Response.Data = FileHelper.ZipFiles(fileResponse.FileNameBodyList);

                Response.AddMessage(fileResponse.ResponseMessage, "", MessageTypes.Success, isEndUserMessage: true);

                Response.SetSuccess();
            }

            return(Response);
        }