public CdContentGeneratorTracking Save(CdContentGeneratorTracking cdContentGeneratorTracking)
        {
            using (var adapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var entityToSave = _mapper.Map(cdContentGeneratorTracking);

                if (!adapter.SaveEntity(entityToSave, true, false))
                {
                    throw new PersistenceFailureException();
                }

                return(_mapper.Map(entityToSave));
            }
        }
        public void Init()
        {
            IoC.Register <ICdContentGeneratorTrackingRepository, CdContentGeneratorTrackingRepository>();
            IoC.Register <IMapper <CdContentGeneratorTracking, CdcontentGeneratorTrackingEntity>, CdContentGeneratorTrackingMapper>();
            IoC.Register <IPersistenceLayer, SqlPersistenceLayer>();

            _cdContentGeneratorTrackingRepository = IoC.Resolve <ICdContentGeneratorTrackingRepository>();
            _cdContentGeneratorTracking           = new CdContentGeneratorTracking
            {
                EventCustomerResultId     = ValidEventCustomerResultId,
                IsContentGenerated        = true,
                IsContentDownloaded       = false,
                DownloadedByOrgRoleUserId = null,
                DownloadedDate            = null
            };
        }
Esempio n. 3
0
        public bool GenerateCdContent(long eventId, long customerId, CorporateAccount corporateAccount)
        {
            //2. Customer who is having CD in the order, pick up those Customer Ids
            var isCdPurchased = _electronicProductRepository.IsProductPurchased(eventId, customerId, Product.UltraSoundImages);

            if (isCdPurchased)
            {
                //3. Check whether cd content is generated or not
                var eventCustomerResult = _eventCustomerResultRepository.GetByCustomerIdAndEventId(customerId, eventId);
                if (eventCustomerResult == null)
                {
                    return(false);
                }

                var cdContentGeneratedRecords     = _cdContentGeneratorTracking.GetCdContentGeneratedforEventCustomerIds(new[] { eventCustomerResult.Id });
                CdContentGeneratorTracking record = cdContentGeneratedRecords != null?cdContentGeneratedRecords.SingleOrDefault() : null;

                var cdContentGenerated = record != null ? record.IsContentGenerated : false;

                if (!cdContentGenerated)
                {
                    //4. Check whether Pdf generated or not
                    if (eventCustomerResult.IsResultPdfGenerated)
                    {
                        //5. Pickup the folder for images
                        var sourceFolderPathforMedia = _mediaRepository.GetResultMediaFileLocation(customerId, eventId).PhysicalPath;
                        //6. Convert the physician evaluation (readonly) page to index page
                        //7. Pick up result Pdf
                        //8. Dump the content as

                        /*
                         * Media-Location
                         *  CdContent
                         *      EventId
                         *          CustomerId
                         *              Media
                         *              ResultPdf
                         *              Index.html
                         *
                         *
                         */
                        var physicalPathForCdContent = _mediaRepository.GetCdContentFolderLocation(eventId, customerId, false).PhysicalPath;
                        try
                        {
                            if (!Directory.Exists(physicalPathForCdContent))
                            {
                                Directory.Delete(physicalPathForCdContent, true);
                            }
                        }
                        catch
                        { }

                        physicalPathForCdContent = _mediaRepository.GetCdContentFolderLocation(eventId, customerId).PhysicalPath;

                        var files = _testResultRepository.GetTestMedia(eventId, customerId);

                        foreach (OrderedPair <string, string> file in files)
                        {
                            var destinationDirectory = Path.Combine(physicalPathForCdContent + @"Media\");
                            if (!Directory.Exists(destinationDirectory))
                            {
                                Directory.CreateDirectory(destinationDirectory);
                            }

                            if (!string.IsNullOrEmpty(file.FirstValue))
                            {
                                file.FirstValue = file.FirstValue.Replace(VideoFileFormat, CDVideoFileFormat);
                                var sourceFile = Path.Combine(sourceFolderPathforMedia, file.FirstValue);
                                var destFile   = Path.Combine(destinationDirectory, file.FirstValue);

                                File.Copy(sourceFile, destFile, true);
                            }

                            if (!string.IsNullOrEmpty(file.SecondValue))
                            {
                                var sourceFile = Path.Combine(sourceFolderPathforMedia, file.SecondValue);
                                var destFile   = Path.Combine(destinationDirectory, file.SecondValue);
                                File.Copy(sourceFile, destFile, true);
                            }
                        }

                        string sourcePdfFile;

                        if (corporateAccount != null && corporateAccount.AddImagesForAbnormal)
                        {
                            sourcePdfFile = _mediaRepository.GetPremiumVersionResultPdfLocation(eventId, customerId).PhysicalPath + _mediaRepository.GetPdfFileNameForResultReport();
                            if (!File.Exists(sourcePdfFile))
                            {
                                sourcePdfFile = _mediaRepository.GetPremiumVersionResultPdfLocation(eventId, customerId).PhysicalPath + _mediaRepository.GetPdfFileNameForPcpResultReport();
                            }
                        }
                        else
                        {
                            sourcePdfFile = _mediaRepository.GetPremiumVersionResultPdfLocation(eventId, customerId).PhysicalPath + _mediaRepository.GetPdfFileNameForResultReport();
                        }

                        if (File.Exists(sourcePdfFile))
                        {
                            var pdfFileName = _mediaRepository.GetPdfFileNameForResultReport();//Path.GetFileName(sourcePdfFile);
                            if (!Directory.Exists(physicalPathForCdContent + @"ResultPdf\"))
                            {
                                Directory.CreateDirectory(physicalPathForCdContent + @"ResultPdf\");
                            }

                            var destPdfFile = Path.Combine(physicalPathForCdContent + @"ResultPdf\", pdfFileName);
                            File.Copy(sourcePdfFile, destPdfFile, true);
                        }

                        ZipCdContentsforEventCustomer(eventId, customerId);

                        var cdContentTracking = new CdContentGeneratorTracking
                        {
                            EventCustomerResultId     = eventCustomerResult.Id,
                            IsContentGenerated        = true,
                            IsContentDownloaded       = false,
                            DownloadedByOrgRoleUserId = null,
                            DownloadedDate            = null,
                            ContentGeneratedDate      = DateTime.Now
                        };

                        if (record != null)
                        {
                            cdContentTracking = record;
                            cdContentTracking.IsContentGenerated   = true;
                            cdContentTracking.ContentGeneratedDate = DateTime.Now;
                        }

                        _cdContentGeneratorTracking.Save(cdContentTracking);
                        //9. Save CD content tracking
                        return(true);
                    }
                }
            }
            return(false);
        }