private static async Task <IgnoredExceptionViewModel> GetFullAndPartialViewModelForIgnoredExceptions
        (
            IDataContext context,
            IgnoredExceptionFilter filter
        )
        {
            var baseModel = SharedModelBase.GetBaseModel(context);
            var model     = new IgnoredExceptionViewModel(baseModel)
            {
                PageIndex      = filter.PageIndex.HasValue ? filter.PageIndex.Value : 1,
                PageSize       = filter.PageSize.HasValue ? filter.PageSize.Value : Int32.MaxValue,
                Configuration  = context.ConfigurationSettings,
                CurrentUser    = baseModel.CurrentUser,
                CurrentVersion = baseModel.CurrentVersion
            };

            var programmeFilter = new ProgrammeFilter()
            {
                ProgrammeId = filter.ProgrammeId,
                Gateway     = filter.Gateway
            };

            HydrateModelWithCommonProperties(model, context, programmeFilter);

            model.IgnoredExceptions = await context.Import.ListFdpIgnoredExceptions(filter);

            model.TotalPages          = model.IgnoredExceptions.TotalPages;
            model.TotalRecords        = model.IgnoredExceptions.TotalRecords;
            model.TotalDisplayRecords = model.IgnoredExceptions.TotalDisplayRecords;

            foreach (var ignoredException in model.IgnoredExceptions.CurrentPage)
            {
                ignoredException.Programme = model.Programmes.FirstOrDefault(p => p.Id == ignoredException.ProgrammeId.GetValueOrDefault());
                ignoredException.Document  =
                    model.Documents.FirstOrDefault(d => d.Id == ignoredException.DocumentId.GetValueOrDefault());
            }

            return(model);
        }
        private static async Task <MarketMappingViewModel> GetFullAndPartialViewModelForMarketMappings
        (
            IDataContext context,
            MarketMappingFilter filter
        )
        {
            var baseModel = SharedModelBase.GetBaseModel(context);
            var model     = new MarketMappingViewModel(baseModel)
            {
                PageIndex      = filter.PageIndex.HasValue ? filter.PageIndex.Value : 1,
                PageSize       = filter.PageSize.HasValue ? filter.PageSize.Value : Int32.MaxValue,
                Configuration  = context.ConfigurationSettings,
                CurrentUser    = baseModel.CurrentUser,
                CurrentVersion = baseModel.CurrentVersion
            };

            var programmeFilter = new ProgrammeFilter()
            {
                ProgrammeId = filter.ProgrammeId,
                Gateway     = filter.Gateway
            };

            HydrateModelWithCommonProperties(model, context, programmeFilter);

            model.MarketMappings = await context.Market.ListFdpMarketMappings(filter);

            model.TotalPages          = model.MarketMappings.TotalPages;
            model.TotalRecords        = model.MarketMappings.TotalRecords;
            model.TotalDisplayRecords = model.MarketMappings.TotalDisplayRecords;

            foreach (var marketMapping in model.MarketMappings.CurrentPage)
            {
                marketMapping.Programme = model.Programmes.FirstOrDefault(p => p.Id == marketMapping.ProgrammeId.GetValueOrDefault());
            }

            return(model);
        }
        private static async Task <DerivativeViewModel> GetFullAndPartialViewModelForDerivatives(IDataContext context,
                                                                                                 DerivativeFilter filter)
        {
            var baseModel = SharedModelBase.GetBaseModel(context);
            var model     = new DerivativeViewModel()
            {
                PageIndex      = filter.PageIndex.HasValue ? filter.PageIndex.Value : 1,
                PageSize       = filter.PageSize.HasValue ? filter.PageSize.Value : Int32.MaxValue,
                Configuration  = context.ConfigurationSettings,
                CurrentUser    = baseModel.CurrentUser,
                CurrentVersion = baseModel.CurrentVersion
            };

            var programmeFilter = new ProgrammeFilter()
            {
                ProgrammeId = filter.ProgrammeId,
                Gateway     = filter.Gateway
            };

            HydrateModelWithCommonProperties(model, context, programmeFilter);

            model.Derivatives = await context.Vehicle.ListFdpDerivatives(filter);

            model.TotalPages          = model.Derivatives.TotalPages;
            model.TotalRecords        = model.Derivatives.TotalRecords;
            model.TotalDisplayRecords = model.Derivatives.TotalDisplayRecords;

            foreach (var derivative in model.Derivatives.CurrentPage)
            {
                derivative.Programme    = model.Programmes.FirstOrDefault(p => p.Id == derivative.ProgrammeId.GetValueOrDefault());
                derivative.Body         = model.Bodies.FirstOrDefault(b => b.Id == derivative.BodyId);
                derivative.Engine       = model.Engines.FirstOrDefault(e => e.Id == derivative.EngineId);
                derivative.Transmission = model.Transmissions.FirstOrDefault(t => t.Id == derivative.TransmissionId);
            }

            return(model);
        }
        private static async Task <IgnoredExceptionViewModel> GetFullAndPartialViewModelForIgnoredException
        (
            IDataContext context,
            IgnoredExceptionFilter filter
        )
        {
            var baseModel = SharedModelBase.GetBaseModel(context);
            var model     = new IgnoredExceptionViewModel()
            {
                PageIndex      = filter.PageIndex.HasValue ? filter.PageIndex.Value : 1,
                PageSize       = filter.PageSize.HasValue ? filter.PageSize.Value : Int32.MaxValue,
                Configuration  = context.ConfigurationSettings,
                CurrentUser    = baseModel.CurrentUser,
                CurrentVersion = baseModel.CurrentVersion
            };
            var ignoredException = await context.Import.GetFdpImportErrorExclusion(filter);

            var programmeFilter = new ProgrammeFilter()
            {
                ProgrammeId = ignoredException.ProgrammeId,
                Gateway     = ignoredException.Gateway,
                Code        = model.IgnoredException.Programme.VehicleName // In order to filter the gateways specific to the programme
            };

            HydrateModelWithCommonProperties(model, context, programmeFilter);
            model.Gateways = context.Vehicle.ListGateways(programmeFilter);

            if (!(ignoredException is EmptyFdpImportErrorExclusion))
            {
                ignoredException.Programme = model.Programmes.FirstOrDefault(p => p.Id == ignoredException.ProgrammeId.GetValueOrDefault());
                ignoredException.Document  =
                    model.Documents.FirstOrDefault(d => d.Id == ignoredException.DocumentId.GetValueOrDefault());
            }
            model.IgnoredException = ignoredException;

            return(model);
        }