public static async Task <DerivativeMappingViewModel> GetModel(IDataContext context,
                                                                       DerivativeMappingFilter filter)
        {
            DerivativeMappingViewModel model = null;

            if (filter.Action == DerivativeMappingAction.Delete ||
                filter.Action == DerivativeMappingAction.Mapping ||
                filter.Action == DerivativeMappingAction.Copy)
            {
                model = await GetFullAndPartialViewModelForDerivativeMapping(context, filter);
            }
            else if (filter.Action == DerivativeMappingAction.Mappings ||
                     filter.Action == DerivativeMappingAction.CopyAll)
            {
                model = await GetFullAndPartialViewModelForDerivativeMappings(context, filter);
            }
            else if (filter.Action == DerivativeMappingAction.BrochureModelCodes)
            {
                model = await GetFullAndPartialViewModelForBrochureModelCodes(context, filter);
            }
            else
            {
                model = GetFullAndPartialViewModel(context, filter);
            }
            if (filter.Action != DerivativeMappingAction.NotSet)
            {
                model.IdentifierPrefix = Enum.GetName(filter.Action.GetType(), filter.Action);
            }
            return(model);
        }
        private static DerivativeMappingViewModel GetFullAndPartialViewModel(IDataContext context,
                                                                             DerivativeMappingFilter filter)
        {
            var model = new DerivativeMappingViewModel(SharedModelBase.GetBaseModel(context))
            {
                Configuration = context.ConfigurationSettings,
            };
            HydrateModelWithCommonProperties(model, context);

            return model;
        }
 private static void HydrateModelWithCommonProperties(DerivativeMappingViewModel model, IDataContext context, ProgrammeFilter programmeFilter)
 {
     model.Programmes    = context.Vehicle.ListProgrammes(programmeFilter);
     model.Bodies        = context.Vehicle.ListBodies(programmeFilter);
     model.Engines       = context.Vehicle.ListEngines(programmeFilter);
     model.Transmissions = context.Vehicle.ListTransmissions(programmeFilter);
     model.Gateways      = model.Programmes.ListGateways();
     model.CarLines      = model.Programmes.ListCarLines();
     model.ModelYears    = model.Programmes.ListModelYears();
     model.Documents     = context.Vehicle.ListPublishedDocuments(programmeFilter);
 }
        private static DerivativeMappingViewModel GetFullAndPartialViewModel(IDataContext context,
                                                                             DerivativeMappingFilter filter)
        {
            var model = new DerivativeMappingViewModel(SharedModelBase.GetBaseModel(context))
            {
                Configuration = context.ConfigurationSettings,
            };

            HydrateModelWithCommonProperties(model, context);

            return(model);
        }
        private static async Task <DerivativeMappingViewModel> GetFullAndPartialViewModelForBrochureModelCodes
        (
            IDataContext context,
            DerivativeMappingFilter filter
        )
        {
            var baseModel = GetBaseModel(context);
            var model     = new DerivativeMappingViewModel(baseModel)
            {
                PageIndex      = filter.PageIndex ?? 1,
                PageSize       = filter.PageSize ?? int.MaxValue,
                Configuration  = context.ConfigurationSettings,
                CurrentUser    = baseModel.CurrentUser,
                CurrentVersion = baseModel.CurrentVersion
            };

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

            HydrateModelWithCommonProperties(model, context, programmeFilter);

            filter.IncludeAllDerivatives = false;

            model.OxoDerivatives = await context.Vehicle.ListOxoDerivatives(filter);

            model.TotalPages          = model.OxoDerivatives.TotalPages;
            model.TotalRecords        = model.OxoDerivatives.TotalRecords;
            model.TotalDisplayRecords = model.OxoDerivatives.TotalDisplayRecords;

            foreach (var oxoDerivative in model.OxoDerivatives.CurrentPage)
            {
                oxoDerivative.Document = model.Documents
                                         .FirstOrDefault(d => d.Id == oxoDerivative.DocumentId);
                oxoDerivative.Programme = model.Programmes
                                          .FirstOrDefault(p => p.Id == oxoDerivative.ProgrammeId.GetValueOrDefault());
                oxoDerivative.Body = model.Bodies
                                     .FirstOrDefault(b => b.DocumentId == oxoDerivative.DocumentId && b.Id == oxoDerivative.BodyId);
                oxoDerivative.Engine = model.Engines
                                       .FirstOrDefault(e => e.DocumentId == oxoDerivative.DocumentId && e.Id == oxoDerivative.EngineId);
                oxoDerivative.Transmission = model.Transmissions
                                             .FirstOrDefault(t => t.DocumentId == oxoDerivative.DocumentId && t.Id == oxoDerivative.TransmissionId);
            }

            return(model);
        }
        private static async Task <DerivativeMappingViewModel> GetFullAndPartialViewModelForDerivativeMapping
        (
            IDataContext context,
            DerivativeMappingFilter filter
        )
        {
            var baseModel = SharedModelBase.GetBaseModel(context);
            var model     = new DerivativeMappingViewModel()
            {
                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 derivativeMapping = await context.Vehicle.GetFdpDerivativeMapping(filter);

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

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

            // If we are copying to another gateway, we need to remove the source gateway from the list of available gateways
            if (filter.Action == DerivativeMappingAction.Copy)
            {
                model.Gateways = model.Gateways.Where(g => !(g.Name.Equals(derivativeMapping.Gateway, StringComparison.InvariantCultureIgnoreCase)));
            }

            if (!(derivativeMapping is EmptyFdpDerivativeMapping))
            {
                derivativeMapping.Programme    = model.Programmes.FirstOrDefault(p => p.Id == derivativeMapping.ProgrammeId.GetValueOrDefault());
                derivativeMapping.Body         = model.Bodies.FirstOrDefault(b => b.Id == derivativeMapping.BodyId);
                derivativeMapping.Engine       = model.Engines.FirstOrDefault(e => e.Id == derivativeMapping.EngineId);
                derivativeMapping.Transmission = model.Transmissions.FirstOrDefault(t => t.Id == derivativeMapping.TransmissionId);
            }
            model.DerivativeMapping = derivativeMapping;

            return(model);
        }
 private static void HydrateModelWithCommonProperties(DerivativeMappingViewModel model, IDataContext context)
 {
     HydrateModelWithCommonProperties(model, context, new ProgrammeFilter());
 }
        private static async Task<DerivativeMappingViewModel> GetFullAndPartialViewModelForDerivativeMapping
        (
            IDataContext context,
            DerivativeMappingFilter filter
        )
        {
            var baseModel = SharedModelBase.GetBaseModel(context);
            var model = new DerivativeMappingViewModel()
            {
                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 derivativeMapping = await context.Vehicle.GetFdpDerivativeMapping(filter);
            var programmeFilter = new ProgrammeFilter()
            {
                ProgrammeId = derivativeMapping.ProgrammeId,
                Gateway = derivativeMapping.Gateway,
                Code = model.DerivativeMapping.Programme.VehicleName // In order to filter the gateways specific to the programme
            };
            HydrateModelWithCommonProperties(model, context, programmeFilter);
            model.Gateways = context.Vehicle.ListGateways(programmeFilter);

            // If we are copying to another gateway, we need to remove the source gateway from the list of available gateways
            if (filter.Action == DerivativeMappingAction.Copy)
            {
                model.Gateways = model.Gateways.Where(g => !(g.Name.Equals(derivativeMapping.Gateway, StringComparison.InvariantCultureIgnoreCase)));
            }
            
            if (!(derivativeMapping is EmptyFdpDerivativeMapping))
            {
                derivativeMapping.Programme = model.Programmes.FirstOrDefault(p => p.Id == derivativeMapping.ProgrammeId.GetValueOrDefault());
                derivativeMapping.Body = model.Bodies.FirstOrDefault(b => b.Id == derivativeMapping.BodyId);
                derivativeMapping.Engine = model.Engines.FirstOrDefault(e => e.Id == derivativeMapping.EngineId);
                derivativeMapping.Transmission = model.Transmissions.FirstOrDefault(t => t.Id == derivativeMapping.TransmissionId);
            }
            model.DerivativeMapping = derivativeMapping;
           
            return model;
        }
 private static void HydrateModelWithCommonProperties(DerivativeMappingViewModel model, IDataContext context, ProgrammeFilter programmeFilter)
 {
     model.Programmes = context.Vehicle.ListProgrammes(programmeFilter);
     model.Bodies = context.Vehicle.ListBodies(programmeFilter);
     model.Engines = context.Vehicle.ListEngines(programmeFilter);
     model.Transmissions = context.Vehicle.ListTransmissions(programmeFilter);
     model.Gateways = model.Programmes.ListGateways();
     model.CarLines = model.Programmes.ListCarLines();
     model.ModelYears = model.Programmes.ListModelYears();
     model.Documents = context.Vehicle.ListPublishedDocuments(programmeFilter);
 }
 private static void HydrateModelWithCommonProperties(DerivativeMappingViewModel model, IDataContext context)
 {
     HydrateModelWithCommonProperties(model, context, new ProgrammeFilter());
 }
        private static async Task<DerivativeMappingViewModel> GetFullAndPartialViewModelForBrochureModelCodes
        (
            IDataContext context,
            DerivativeMappingFilter filter
        )
        {
            var baseModel = GetBaseModel(context);
            var model = new DerivativeMappingViewModel(baseModel)
            {
                PageIndex = filter.PageIndex ?? 1,
                PageSize = filter.PageSize ?? int.MaxValue,
                Configuration = context.ConfigurationSettings,
                CurrentUser = baseModel.CurrentUser,
                CurrentVersion = baseModel.CurrentVersion
            };

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

            filter.IncludeAllDerivatives = false;

            model.OxoDerivatives = await context.Vehicle.ListOxoDerivatives(filter);
            model.TotalPages = model.OxoDerivatives.TotalPages;
            model.TotalRecords = model.OxoDerivatives.TotalRecords;
            model.TotalDisplayRecords = model.OxoDerivatives.TotalDisplayRecords;

            foreach (var oxoDerivative in model.OxoDerivatives.CurrentPage)
            {
                oxoDerivative.Document = model.Documents
                    .FirstOrDefault(d => d.Id == oxoDerivative.DocumentId);
                oxoDerivative.Programme = model.Programmes
                    .FirstOrDefault(p => p.Id == oxoDerivative.ProgrammeId.GetValueOrDefault());
                oxoDerivative.Body = model.Bodies
                    .FirstOrDefault(b => b.DocumentId == oxoDerivative.DocumentId && b.Id == oxoDerivative.BodyId);
                oxoDerivative.Engine = model.Engines
                    .FirstOrDefault(e => e.DocumentId == oxoDerivative.DocumentId && e.Id == oxoDerivative.EngineId);
                oxoDerivative.Transmission = model.Transmissions
                    .FirstOrDefault(t => t.DocumentId == oxoDerivative.DocumentId && t.Id == oxoDerivative.TransmissionId);
            }

            return model;
        }