Example #1
0
        private static TakeRateSummary GetVolumeHeader(IDataContext context, TakeRateSummary forHeader)
        {
            TakeRateSummary header       = null;
            var             cacheKey     = string.Format("FdpVolumeHeader_{0}", forHeader.TakeRateId);
            var             cachedLookup = HttpContext.Current.Cache.Get(cacheKey);

            if (cachedLookup != null)
            {
                header = (TakeRateSummary)cachedLookup;
            }
            else
            {
                header = context.Volume.GetVolumeHeader(new VolumeFilter()
                {
                    FdpVolumeHeaderId = forHeader.TakeRateId
                });
                HttpContext.Current.Cache.Add(cacheKey, header, null, DateTime.Now.AddMinutes(60), Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
            }

            // Get the vehicle associated with the import data
            //header.Vehicle = (Vehicle)context.Vehicle.GetVehicle(new VehicleFilter()
            //{
            //    ProgrammeId = header.ProgrammeId,
            //    Gateway = header.Gateway
            //});

            return(header);
        }
        private static async Task <TakeRateSummary> HydrateFdpVolumeHeader(IDataContext context,
                                                                           TakeRateViewModel volumeModel)
        {
            var watch         = Stopwatch.StartNew();
            var volumeSummary = new TakeRateSummary {
                TakeRateId = volumeModel.Document.TakeRateId.GetValueOrDefault()
            };

            volumeSummary = await GetTakeRateDocumentHeader(context, volumeSummary);

            volumeModel.Document.TakeRateSummary = new List <TakeRateSummary> {
                volumeSummary
            };

            watch.Stop();
            Log.Debug(watch.ElapsedMilliseconds);

            return(volumeSummary);
        }
        private static async Task <TakeRateSummary> GetTakeRateDocumentHeader(IDataContext context, TakeRateSummary forHeader)
        {
            var cacheKey     = string.Format("FdpVolumeHeader_{0}", forHeader.TakeRateId);
            var cachedLookup = GetCache(cacheKey);

            if (cachedLookup != null)
            {
                forHeader = (TakeRateSummary)cachedLookup;
            }
            else
            {
                forHeader = await context.TakeRate.GetTakeRateDocumentHeader(new TakeRateFilter()
                {
                    TakeRateId = forHeader.TakeRateId
                });

                AddCache(cacheKey, forHeader);
            }
            return(forHeader);
        }
        private static async Task<TakeRateSummary> HydrateFdpVolumeHeader(IDataContext context,
            TakeRateViewModel volumeModel)
        {
            var watch = Stopwatch.StartNew();
            var volumeSummary = new TakeRateSummary {TakeRateId = volumeModel.Document.TakeRateId.GetValueOrDefault()};
            volumeSummary = await GetTakeRateDocumentHeader(context, volumeSummary);

            volumeModel.Document.TakeRateSummary = new List<TakeRateSummary> { volumeSummary };

            watch.Stop();
            Log.Debug(watch.ElapsedMilliseconds);

            return volumeSummary;
        }
 private static async Task<TakeRateSummary> GetTakeRateDocumentHeader(IDataContext context, TakeRateSummary forHeader)
 {
     var cacheKey = string.Format("FdpVolumeHeader_{0}", forHeader.TakeRateId);
     var cachedLookup = GetCache(cacheKey);
     if (cachedLookup != null)
     {
         forHeader = (TakeRateSummary) cachedLookup;
     }
     else
     {
         forHeader = await context.TakeRate.GetTakeRateDocumentHeader(new TakeRateFilter() {TakeRateId = forHeader.TakeRateId});
         AddCache(cacheKey, forHeader);
     }
     return forHeader;
 }