Esempio n. 1
0
        /// <summary>
        /// Converts from.
        /// </summary>
        /// <param name="importLog">The import log.</param>
        /// <param name="importLogFilesList">The import log files list.</param>
        /// <returns></returns>
        public FileImportLog ConvertFrom(EstateReporting.Database.Entities.FileImportLog importLog,
                                         List <FileImportLogFile> importLogFilesList)
        {
            FileImportLog model = new FileImportLog();

            model.FileImportLogId       = importLog.FileImportLogId;
            model.FileImportLogDateTime = importLog.ImportLogDateTime;
            model.EstateId = importLog.EstateId;
            model.Files    = new List <ImportLogFile>();

            IEnumerable <FileImportLogFile> currentImportLogFiles = importLogFilesList.Where(fi => fi.FileImportLogId == importLog.FileImportLogId);

            foreach (FileImportLogFile importLogFile in currentImportLogFiles)
            {
                model.Files.Add(new ImportLogFile
                {
                    MerchantId       = importLogFile.MerchantId,
                    EstateId         = importLogFile.EstateId,
                    FileId           = importLogFile.FileId,
                    FilePath         = importLogFile.FilePath,
                    FileProfileId    = importLogFile.FileProfileId,
                    OriginalFileName = importLogFile.OriginalFileName,
                    UserId           = importLogFile.UserId,
                    UploadedDateTime = importLogFile.FileUploadedDateTime
                });
            }

            return(model);
        }
        /// <summary>
        /// Gets the file import log files.
        /// </summary>
        /// <param name="fileImportLogId">The file import log identifier.</param>
        /// <param name="estateId">The estate identifier.</param>
        /// <param name="merchantId">The merchant identifier.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <FileImportLog> GetFileImportLog(Guid fileImportLogId,
                                                           Guid estateId,
                                                           Guid?merchantId,
                                                           CancellationToken cancellationToken)
        {
            EstateReportingGenericContext context = await this.DbContextFactory.GetContext(estateId, cancellationToken);

            EstateReporting.Database.Entities.FileImportLog importLogQuery =
                await context.FileImportLogs.AsAsyncEnumerable().SingleOrDefaultAsync(f => f.FileImportLogId == fileImportLogId, cancellationToken);

            List <FileImportLogFile> importLogFileQuery = await context.FileImportLogFiles.AsAsyncEnumerable()
                                                          .Where(fi => fi.FileImportLogId == fileImportLogId)
                                                          .ToListAsync(cancellationToken);

            if (merchantId.HasValue)
            {
                importLogFileQuery = importLogFileQuery.Where(i => i.MerchantId == merchantId.Value).ToList();
            }

            return(this.ModelFactory.ConvertFrom(importLogQuery, importLogFileQuery));
        }