private static async Task <ImportViewModel> GetFullAndPartialViewModelForImportQueueItem(IDataContext context,
                                                                                                 ImportQueueFilter filter)
        {
            var model = new ImportViewModel(GetBaseModel(context))
            {
                PageIndex               = filter.PageIndex ?? 1,
                PageSize                = filter.PageSize ?? int.MaxValue,
                Configuration           = context.ConfigurationSettings,
                CurrentImport           = await context.Import.GetImportQueue(filter),
                AvailableExceptionTypes = await context.Import.ListExceptionTypes(filter)
            };

            var programmeFilter = new ProgrammeFilter(model.CurrentImport.ProgrammeId)
            {
                DocumentId = model.CurrentImport.DocumentId
            };

            model.AvailableDocuments = context.Vehicle.ListPublishedDocuments(programmeFilter);
            model.Exceptions         = await context.Import.ListExceptions(filter);

            model.TotalPages          = model.Exceptions.TotalPages;
            model.TotalRecords        = model.Exceptions.TotalRecords;
            model.TotalDisplayRecords = model.Exceptions.TotalDisplayRecords;
            model.Document            = model.AvailableDocuments.FirstOrDefault(d => d.Id == programmeFilter.DocumentId);
            model.Programme           = context.Vehicle.GetProgramme(programmeFilter);
            model.Gateway             = model.CurrentImport.Gateway;
            model.Summary             = await context.Import.GetImportSummary(filter);

            return(model);
        }
        private static async Task <ImportViewModel> GetFullAndPartialViewModelForSummary(IDataContext context, ImportQueueFilter filter)
        {
            var model = new ImportViewModel(GetBaseModel(context))
            {
                Summary = await context.Import.GetImportSummary(filter)
            };

            return(model);
        }
        private static async Task <ImportViewModel> GetFullAndPartialViewModel(IDataContext context)
        {
            var model = new ImportViewModel(GetBaseModel(context))
            {
                Configuration       = context.ConfigurationSettings,
                AvailableProgrammes = await
                                      Task.FromResult(context.Vehicle.ListProgrammes(new ProgrammeFilter())),
                AvailableDocuments = await
                                     Task.FromResult(context.Vehicle.ListPublishedDocuments(new ProgrammeFilter())),
                AvailableImportStatuses = await context.Import.ListImportStatuses()
            };

            model.AvailableDocuments = context.Vehicle.ListPublishedDocuments(new ProgrammeFilter());

            return(model);
        }
        private static async Task <ImportViewModel> GetFullAndPartialViewModelForImportQueue(IDataContext context,
                                                                                             ImportQueueFilter filter)
        {
            var model = new ImportViewModel(GetBaseModel(context))
            {
                PageIndex     = filter.PageIndex ?? 1,
                PageSize      = filter.PageSize ?? int.MaxValue,
                Configuration = context.ConfigurationSettings,
                ImportQueue   = await context.Import.ListImportQueue(filter)
            };

            model.TotalPages          = model.ImportQueue.TotalPages;
            model.TotalRecords        = model.ImportQueue.TotalRecords;
            model.TotalDisplayRecords = model.ImportQueue.TotalDisplayRecords;

            model.AvailableProgrammes = context.Vehicle.ListProgrammes(new ProgrammeFilter());
            model.AvailableDocuments  = context.Vehicle.ListPublishedDocuments(new ProgrammeFilter());

            return(model);
        }
        public static async Task <ImportViewModel> GetModel(IDataContext context,
                                                            ImportQueueFilter filter)
        {
            ImportViewModel model = null;

            switch (filter.Action)
            {
            case enums.ImportAction.ImportQueue:
                model = await GetFullAndPartialViewModelForImportQueue(context, filter);

                break;

            case enums.ImportAction.Exception:
                model = await GetFullAndPartialViewModelForException(context, filter);

                break;

            case enums.ImportAction.ImportQueueItem:
            case enums.ImportAction.ProcessTakeRateData:
            case enums.ImportAction.DeleteImport:
                model = await GetFullAndPartialViewModelForImportQueueItem(context, filter);

                break;

            case enums.ImportAction.Summary:
                model = await GetFullAndPartialViewModelForSummary(context, filter);

                break;

            default:
                model = await GetFullAndPartialViewModel(context);

                break;
            }
            return(model);
        }
        private static async Task<ImportViewModel> GetFullAndPartialViewModelForSummary(IDataContext context, ImportQueueFilter filter)
        {
            var model = new ImportViewModel(GetBaseModel(context))
            {
                Summary = await context.Import.GetImportSummary(filter)
            };

            return model;
        }
        private static async Task<ImportViewModel> GetFullAndPartialViewModelForImportQueueItem(IDataContext context,
                                                                                                ImportQueueFilter filter)
        {
            var model = new ImportViewModel(GetBaseModel(context))
            {
                PageIndex = filter.PageIndex ?? 1,
                PageSize = filter.PageSize ?? int.MaxValue,
                Configuration = context.ConfigurationSettings,
                CurrentImport = await context.Import.GetImportQueue(filter),
                AvailableExceptionTypes = await context.Import.ListExceptionTypes(filter)
            };

            var programmeFilter = new ProgrammeFilter(model.CurrentImport.ProgrammeId)
            {
                DocumentId = model.CurrentImport.DocumentId
            };
            model.AvailableDocuments = context.Vehicle.ListPublishedDocuments(programmeFilter);
            model.Exceptions = await context.Import.ListExceptions(filter);
            model.TotalPages = model.Exceptions.TotalPages;
            model.TotalRecords = model.Exceptions.TotalRecords;
            model.TotalDisplayRecords = model.Exceptions.TotalDisplayRecords;
            model.Document = model.AvailableDocuments.FirstOrDefault(d => d.Id == programmeFilter.DocumentId);
            model.Programme = context.Vehicle.GetProgramme(programmeFilter);
            model.Gateway = model.CurrentImport.Gateway;
            model.Summary = await context.Import.GetImportSummary(filter);

            return model;
        }
        private static async Task<ImportViewModel> GetFullAndPartialViewModelForException(IDataContext context,
                                                                                          ImportQueueFilter filter)
        {
            var model = new ImportViewModel(GetBaseModel(context))
            {
                PageIndex = filter.PageIndex ?? 1,
                PageSize = filter.PageSize ?? int.MaxValue,
                Configuration = context.ConfigurationSettings,
                CurrentException = await context.Import.GetException(filter)
            };

            var programmeFilter = new ProgrammeFilter(model.CurrentException.ProgrammeId) { DocumentId = model.CurrentException.DocumentId };
            var featureFilter = new FeatureFilter { ProgrammeId = model.CurrentException.ProgrammeId, DocumentId = model.CurrentException.DocumentId };
            
            model.Programme = context.Vehicle.GetProgramme(programmeFilter);
            programmeFilter.VehicleId = model.Programme.VehicleId;

            model.Gateway = model.CurrentException.Gateway;
            model.AvailableDocuments = context.Vehicle.ListPublishedDocuments(programmeFilter);
            model.AvailableEngines = context.Vehicle.ListEngines(programmeFilter);
            model.AvailableTransmissions = context.Vehicle.ListTransmissions(programmeFilter);
            model.AvailableBodies = context.Vehicle.ListBodies(programmeFilter);
            model.AvailableSpecialFeatures = await context.TakeRate.ListSpecialFeatures(programmeFilter);
            model.AvailableMarkets = await context.Market.ListAvailableMarkets();
            model.AvailableFeatures = await context.Vehicle.ListFeatures(featureFilter);
            model.AvailableFeatureGroups = context.Vehicle.ListFeatureGroups(programmeFilter);
            model.AvailableTrimLevels = context.Vehicle.ListTrimLevels(programmeFilter);

            var derivativeFilter = new DerivativeFilter
            {
                CarLine = model.Programme.VehicleName,
                ModelYear = model.Programme.ModelYear,
                Gateway = model.Gateway,
                ProgrammeId = model.CurrentException.ProgrammeId,
            };

            model.AvailableDerivatives = context.Vehicle.ListDerivatives(derivativeFilter);
            model.AvailableImportDerivatives = await ListImportDerivatives(model.CurrentException.ImportQueueId, context);
            model.AvailableImportTrimLevels = await ListImportTrimLevels(model.CurrentException.ImportQueueId, context);
            model.AvailableImportFeatures = await ListImportFeatures(model.CurrentException.ImportQueueId, context);

            derivativeFilter.Bmc = model.CurrentException.ImportDerivativeCode;
           
            var trimFilter = new TrimMappingFilter
            {
                CarLine = model.Programme.VehicleName,
                ModelYear = model.Programme.ModelYear,
                Gateway = model.Gateway,
                DocumentId = model.CurrentException is EmptyOxoDocument ? (int?) null : model.CurrentException.DocumentId,
                IncludeAllTrim = false
            };
            model.AvailableTrim = (await context.Vehicle.ListOxoTrim(trimFilter)).CurrentPage;
            model.Document = model.AvailableDocuments.FirstOrDefault(d => d.Id == model.CurrentException.DocumentId);

            return model;
        }
        private static async Task<ImportViewModel> GetFullAndPartialViewModelForImportQueue(IDataContext context,
                                                                                            ImportQueueFilter filter)
        {
            var model = new ImportViewModel(GetBaseModel(context))
            {
                PageIndex = filter.PageIndex ?? 1,
                PageSize = filter.PageSize ?? int.MaxValue,
                Configuration = context.ConfigurationSettings,
                ImportQueue = await context.Import.ListImportQueue(filter)
            };
            model.TotalPages = model.ImportQueue.TotalPages;
            model.TotalRecords = model.ImportQueue.TotalRecords;
            model.TotalDisplayRecords = model.ImportQueue.TotalDisplayRecords;

            model.AvailableProgrammes = context.Vehicle.ListProgrammes(new ProgrammeFilter());
            model.AvailableDocuments = context.Vehicle.ListPublishedDocuments(new ProgrammeFilter());

            return model;
        }
        private static async Task<ImportViewModel> GetFullAndPartialViewModel(IDataContext context)
        {
            var model = new ImportViewModel(GetBaseModel(context))
            {
                Configuration = context.ConfigurationSettings,
                AvailableProgrammes = await
                    Task.FromResult(context.Vehicle.ListProgrammes(new ProgrammeFilter())),
                AvailableDocuments = await
                    Task.FromResult(context.Vehicle.ListPublishedDocuments(new ProgrammeFilter())),
                AvailableImportStatuses = await context.Import.ListImportStatuses()
            };

            model.AvailableDocuments = context.Vehicle.ListPublishedDocuments(new ProgrammeFilter());

            return model;
        }
        private static async Task <ImportViewModel> GetFullAndPartialViewModelForException(IDataContext context,
                                                                                           ImportQueueFilter filter)
        {
            var model = new ImportViewModel(GetBaseModel(context))
            {
                PageIndex        = filter.PageIndex ?? 1,
                PageSize         = filter.PageSize ?? int.MaxValue,
                Configuration    = context.ConfigurationSettings,
                CurrentException = await context.Import.GetException(filter)
            };

            var programmeFilter = new ProgrammeFilter(model.CurrentException.ProgrammeId)
            {
                DocumentId = model.CurrentException.DocumentId
            };
            var featureFilter = new FeatureFilter {
                ProgrammeId = model.CurrentException.ProgrammeId, DocumentId = model.CurrentException.DocumentId
            };

            model.Programme           = context.Vehicle.GetProgramme(programmeFilter);
            programmeFilter.VehicleId = model.Programme.VehicleId;

            model.Gateway                  = model.CurrentException.Gateway;
            model.AvailableDocuments       = context.Vehicle.ListPublishedDocuments(programmeFilter);
            model.AvailableEngines         = context.Vehicle.ListEngines(programmeFilter);
            model.AvailableTransmissions   = context.Vehicle.ListTransmissions(programmeFilter);
            model.AvailableBodies          = context.Vehicle.ListBodies(programmeFilter);
            model.AvailableSpecialFeatures = await context.TakeRate.ListSpecialFeatures(programmeFilter);

            model.AvailableMarkets = await context.Market.ListAvailableMarkets();

            model.AvailableFeatures = await context.Vehicle.ListFeatures(featureFilter);

            model.AvailableFeatureGroups = context.Vehicle.ListFeatureGroups(programmeFilter);
            model.AvailableTrimLevels    = context.Vehicle.ListTrimLevels(programmeFilter);

            var derivativeFilter = new DerivativeFilter
            {
                CarLine     = model.Programme.VehicleName,
                ModelYear   = model.Programme.ModelYear,
                Gateway     = model.Gateway,
                ProgrammeId = model.CurrentException.ProgrammeId,
            };

            model.AvailableDerivatives       = context.Vehicle.ListDerivatives(derivativeFilter);
            model.AvailableImportDerivatives = await ListImportDerivatives(model.CurrentException.ImportQueueId, context);

            model.AvailableImportTrimLevels = await ListImportTrimLevels(model.CurrentException.ImportQueueId, context);

            model.AvailableImportFeatures = await ListImportFeatures(model.CurrentException.ImportQueueId, context);

            derivativeFilter.Bmc = model.CurrentException.ImportDerivativeCode;

            var trimFilter = new TrimMappingFilter
            {
                CarLine        = model.Programme.VehicleName,
                ModelYear      = model.Programme.ModelYear,
                Gateway        = model.Gateway,
                DocumentId     = model.CurrentException is EmptyOxoDocument ? (int?)null : model.CurrentException.DocumentId,
                IncludeAllTrim = false
            };

            model.AvailableTrim = (await context.Vehicle.ListOxoTrim(trimFilter)).CurrentPage;
            model.Document      = model.AvailableDocuments.FirstOrDefault(d => d.Id == model.CurrentException.DocumentId);

            return(model);
        }