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);
        }
        public async Task <ActionResult> ListDerivativeMappings(DerivativeMappingParameters parameters)
        {
            ValidateDerivativeMappingParameters(parameters, DerivativeMappingParametersValidator.NoValidation);

            var filter = new DerivativeMappingFilter()
            {
                FilterMessage = parameters.FilterMessage,
                CarLine       = parameters.CarLine,
                ModelYear     = parameters.ModelYear,
                Gateway       = parameters.Gateway,
                Action        = DerivativeMappingAction.Mappings
            };

            filter.InitialiseFromJson(parameters);

            var results = await DerivativeMappingViewModel.GetModel(DataContext, filter);

            var jQueryResult = new JQueryDataTableResultModel(results);

            foreach (var result in results.DerivativeMappings.CurrentPage)
            {
                jQueryResult.aaData.Add(result.ToJQueryDataTableResult());
            }

            return(Json(jQueryResult));
        }
Ejemplo n.º 3
0
        public FdpDerivativeMapping FdpDerivativeMappingGet(DerivativeMappingFilter filter)
        {
            FdpDerivativeMapping retVal = new EmptyFdpDerivativeMapping();

            using (var conn = DbHelper.GetDBConnection())
            {
                try
                {
                    var para = new DynamicParameters();
                    para.Add("@FdpDerivativeMappingId", filter.DerivativeMappingId.GetValueOrDefault(), DbType.Int32);

                    var results = conn.Query <FdpDerivativeMapping>("Fdp_DerivativeMapping_Get", para, commandType: CommandType.StoredProcedure);
                    if (results.Any())
                    {
                        retVal = results.First();
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    throw;
                }
            }
            return(retVal);
        }
        public async Task <ActionResult> ListBrochureModelCodes(DerivativeMappingParameters parameters)
        {
            ValidateDerivativeMappingParameters(parameters, DerivativeMappingParametersValidator.NoValidation);

            var filter = new DerivativeMappingFilter()
            {
                FilterMessage = parameters.FilterMessage,
                CarLine       = parameters.CarLine,
                ModelYear     = parameters.ModelYear,
                Gateway       = parameters.Gateway,
                Action        = DerivativeMappingAction.BrochureModelCodes,
                DocumentId    = parameters.DocumentId
            };

            filter.InitialiseFromJson(parameters);

            var results = await DerivativeMappingViewModel.GetModel(DataContext, filter);

            var jQueryResult = new JQueryDataTableResultModel(results);

            foreach (var result in results.OxoDerivatives.CurrentPage)
            {
                try
                {
                    jQueryResult.aaData.Add(result.ToJQueryDataTableResult());
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                }
            }
            return(Json(jQueryResult));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> ModalContent(DerivativeParameters parameters)
        {
            ValidateDerivativeParameters(parameters, DerivativeParametersValidator.Action);

            var filter         = DerivativeMappingFilter.FromParameters(parameters);
            var derivativeView = await GetModelFromParameters(parameters);

            return(PartialView(GetContentPartialViewName(parameters.Action), derivativeView));
        }
        public async Task <ActionResult> BMCPage(DerivativeMappingParameters parameters)
        {
            var filter = new DerivativeMappingFilter()
            {
                PageIndex = PageIndex,
                PageSize  = PageSize
            };

            return(View(await DerivativeMappingViewModel.GetModel(DataContext, filter)));
        }
        private static DerivativeMappingViewModel GetFullAndPartialViewModel(IDataContext context,
                                                                             DerivativeMappingFilter filter)
        {
            var model = new DerivativeMappingViewModel(SharedModelBase.GetBaseModel(context))
            {
                Configuration = context.ConfigurationSettings,
            };

            HydrateModelWithCommonProperties(model, context);

            return(model);
        }
        public async Task <ActionResult> ContextMenu(DerivativeMappingParameters parameters)
        {
            ValidateDerivativeMappingParameters(parameters, DerivativeMappingParametersValidator.DerivativeMappingIdentifier);

            var filter = DerivativeMappingFilter.FromDerivativeMappingParameters(parameters);

            filter.Action = DerivativeMappingAction.Mapping;

            var derivativeMappingView = await DerivativeMappingViewModel.GetModel(DataContext, filter);

            return(PartialView("_ContextMenu", derivativeMappingView));
        }
        protected override bool IsValid(PropertyValidatorContext context)
        {
            Parameters = context.ParentContext.InstanceToValidate as DerivativeMappingParameters;

            var filter = DerivativeMappingFilter.FromDerivativeMappingParameters(Parameters);

            filter.PageSize = int.MaxValue;

            var oxoDerivatives =
                _context.Vehicle.ListOxoDerivatives(filter).Result;

            return
                (!oxoDerivatives.CurrentPage.Any(IsExistingBmc));
        }
        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);
        }
Ejemplo n.º 12
0
        public PagedResults <OxoDerivative> FdpOxoDerivativeGetMany(DerivativeMappingFilter filter)
        {
            PagedResults <FdpDerivativeMapping> interimResults;

            using (var conn = DbHelper.GetDBConnection())
            {
                try
                {
                    var para                = DynamicParameters.FromCDSId(CurrentCDSID);
                    var totalRecords        = 0;
                    var totalDisplayRecords = 0;

                    if (!string.IsNullOrEmpty(filter.CarLine))
                    {
                        para.Add("@CarLine", filter.CarLine, DbType.String);
                    }
                    if (!string.IsNullOrEmpty(filter.ModelYear))
                    {
                        para.Add("@ModelYear", filter.ModelYear, DbType.String);
                    }
                    if (!string.IsNullOrEmpty(filter.Gateway))
                    {
                        para.Add("@Gateway", filter.Gateway, DbType.String);
                    }
                    if (filter.PageIndex.HasValue)
                    {
                        para.Add("@PageIndex", filter.PageIndex.Value, DbType.Int32);
                    }
                    if (filter.PageSize.HasValue)
                    {
                        para.Add("@PageSize", filter.PageSize.Value, DbType.Int32);
                    }
                    if (filter.SortIndex.HasValue)
                    {
                        para.Add("@SortIndex", filter.SortIndex.Value, DbType.Int32);
                    }
                    if (filter.SortDirection != SortDirection.NotSet)
                    {
                        var direction = filter.SortDirection == SortDirection.Descending ? "DESC" : "ASC";
                        para.Add("@SortDirection", direction, DbType.String);
                    }
                    if (filter.IncludeAllDerivatives)
                    {
                        para.Add("@IncludeAllDerivatives", true, DbType.Boolean);
                    }
                    if (filter.OxoDerivativesOnly)
                    {
                        para.Add("@OxoDerivativesOnly", filter.OxoDerivativesOnly, DbType.Boolean);
                    }
                    para.Add("@DocumentId", filter.DocumentId, DbType.Int32);
                    para.Add("@TotalPages", DbType.Int32, direction: ParameterDirection.Output);
                    para.Add("@TotalRecords", DbType.Int32, direction: ParameterDirection.Output);
                    para.Add("@TotalDisplayRecords", DbType.Int32, direction: ParameterDirection.Output);

                    var dbResults = conn.Query <FdpDerivativeMapping>("dbo.Fdp_OxoDerivative_GetMany", para, commandType: CommandType.StoredProcedure);

                    var fdpDerivativeMappings = dbResults as IList <FdpDerivativeMapping> ?? dbResults.ToList();
                    if (fdpDerivativeMappings.Any())
                    {
                        totalRecords        = para.Get <int>("@TotalRecords");
                        totalDisplayRecords = para.Get <int>("@TotalDisplayRecords");
                    }
                    interimResults = new PagedResults <FdpDerivativeMapping>
                    {
                        PageIndex           = filter.PageIndex ?? 1,
                        TotalRecords        = totalRecords,
                        TotalDisplayRecords = totalDisplayRecords,
                        PageSize            = filter.PageSize ?? totalRecords
                    };

                    var currentPage = fdpDerivativeMappings.ToList();

                    interimResults.CurrentPage = currentPage;
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    throw;
                }
            }

            var page = interimResults.CurrentPage.Select(result => new OxoDerivative(result)).ToList();

            return(new PagedResults <OxoDerivative>
            {
                PageIndex = interimResults.PageIndex,
                PageSize = interimResults.PageSize,
                TotalDisplayRecords = interimResults.TotalDisplayRecords,
                TotalFail = interimResults.TotalFail,
                TotalRecords = interimResults.TotalRecords,
                TotalSuccess = interimResults.TotalSuccess,
                CurrentPage = page
            });
        }
Ejemplo n.º 13
0
 private async Task <DerivativeViewModel> GetModelFromParameters(DerivativeParameters parameters)
 {
     return(await DerivativeViewModel.GetModel(DataContext, DerivativeMappingFilter.FromParameters(parameters)));
 }
 public async Task <PagedResults <OxoDerivative> > ListOxoDerivatives(DerivativeMappingFilter filter)
 {
     return(await Task.FromResult(_derivativeDataStore.FdpOxoDerivativeGetMany(filter)));
 }
 public async Task <FdpDerivativeMapping> GetFdpDerivativeMapping(DerivativeMappingFilter filter)
 {
     return(await Task.FromResult(_derivativeDataStore.FdpDerivativeMappingGet(filter)));
 }