예제 #1
0
        private void TryGetColors(dynamic refStyles, List <ColorReferenceEntity> colorResults)
        {
            if (refStyles.colors != null && refStyles.colors.GetType() == typeof(JArray))
            {
                foreach (var color in refStyles.colors)
                {
                    var colorRefObject = new ColorReferenceEntity();

                    if (color.exterior != null)
                    {
                        var colorObject = new Color
                        {
                            Code = color.exterior.code ?? string.Empty,
                            //Base = color.exterior.base ?? string.Empty,
                            Name       = color.exterior.name ?? string.Empty,
                            RgbHexCode = color.exterior.RGBHexCode ?? string.Empty
                        };
                        colorRefObject.ExternalColor = colorObject;
                    }
                    if (color.interior != null)
                    {
                        var colorObject = new Color
                        {
                            Code = color.interior.code ?? string.Empty,
                            //Base = color.exterior.base ?? string.Empty,
                            Name       = color.interior.name ?? string.Empty,
                            RgbHexCode = color.interior.RGBHexCode ?? string.Empty
                        };
                        colorRefObject.InternalColor = new List <Color>()
                        {
                            colorObject
                        };
                    }

                    colorResults.Add(colorRefObject);
                }
            }
        }
예제 #2
0
        private void TryGetColors(dynamic refStyles, List<ColorReferenceEntity> colorResults)
        {
            if (refStyles.colors != null && refStyles.colors.GetType() == typeof(JArray))
                {
                    foreach (var color in refStyles.colors)
                    {
                        var colorRefObject = new ColorReferenceEntity();

                        if (color.exterior != null )
                        {
                            var colorObject = new Color
                            {
                                Code = color.exterior.code ?? string.Empty,
                                //Base = color.exterior.base ?? string.Empty,
                                Name = color.exterior.name ?? string.Empty,
                                RgbHexCode = color.exterior.RGBHexCode ?? string.Empty
                            };
                            colorRefObject.ExternalColor = colorObject;

                        }
                        if (color.interior != null )
                        {
                            var colorObject = new Color
                            {
                                Code = color.interior.code ?? string.Empty,
                                //Base = color.exterior.base ?? string.Empty,
                                Name = color.interior.name ?? string.Empty,
                                RgbHexCode = color.interior.RGBHexCode ?? string.Empty
                            };
                            colorRefObject.InternalColor = new List<Color>(){
                                            colorObject
                                        };
                        }

                        colorResults.Add(colorRefObject);
                    }

                }
        }
예제 #3
0
        public VehicleEntity CreateVehicle(VehicleEntity newVehicle)
        {
            var resultVehicleEntity = new VehicleEntity();
            EventLogEntryType eventLogType = EventLogEntryType.Information;

            try
            {
                #region Detailer Call
                var requestUri = ConfigurationManager.AppSettings["detailerUrl"];
                dynamic detailerResponse = RestClient.PostData(requestUri, GetDetailerRequestPayload(newVehicle));
                _logger.AppendMessages("Successfully completed Detailer call before Create Vehicle.");
                #endregion Detailer call

                #region Create Vehicle Call
                if (detailerResponse.vehicles != null && detailerResponse.vehicles.GetType() == typeof(JArray)
                    && detailerResponse.vehicles[0] != null && detailerResponse.vehicles[0].vehicle != null)
                {

                    JObject vehicleEntity = detailerResponse.vehicles[0].vehicle;
                    vehicleEntity.Add("stockNumber", newVehicle.StockNumber ?? string.Empty);

                    _logger.AppendMessages("Detailer found atleast one vehicle in response.");

                    if (newVehicle.photoIds != null)
                    {
                        //??
                        _logger.AppendMessages("Number of PhotoIds: " + newVehicle.photoIds.Count());
                        //vehicleEntity.Add("assets", JObject.Parse("{\"dealerPhotos\": []}"));
                        foreach (var id in newVehicle.photoIds)
                        {
                            if (id != null && !id.Equals(string.Empty) && !id.Equals(" ") && vehicleEntity.GetValue("assets") == null)
                            {
                                //??
                                _logger.AppendMessages("L");
                                vehicleEntity.Add("assets", JObject.Parse("{\"dealerPhotos\": [{\"id\":" + id + "}]}"));
                            }
                        }
                    }

                    if (vehicleEntity.GetValue("source") == null)
                    {
                        vehicleEntity.Add("source", "M");
                    }

                    var createVehicleRequestPayload = string.Format("{{\"criteria\":{{\"vehicleContexts\":[{{\"vehicleContext\":{{\"vehicle\":{0},\"modifiedFields\":[\"assets\",\"bodyStyle\",\"bodyType\",\"certified\",\"colors.exterior.base\",\"colors.exterior.code\",\"colors.exterior.name\",\"colors.interior.code\",\"colors.interior.name\",\"createdDate\",\"descriptions\",\"doors\",\"drivetrain\",\"engine.aspiration\",\"engine.cylinders\",\"engine.description\",\"engine.displacement\",\"engine.fuelType\",\"engine.power\",\"id\",\"inventoryOwner\",\"lastModifiedDate\",\"lotDate\",\"make.Id\",\"make.label\",\"model.Id\",\"model.label\",\"odometer\",\"oemModelCode\",\"options.dealerOptions\",\"options.factoryOptions\",\"preOwned\",\"prices.discountPrice\",\"prices.internetPrice\",\"prices.invoicePrice\",\"prices.msrp\",\"prices.retailPrice\",\"prices.vendedPrice\",\"stockNumber\",\"style.Id\",\"style.trim\",\"transmission.speeds\",\"transmission.text\",\"transmission.type\",\"unmodifiable\",\"vin\",\"warranties\",\"year\"]}}}}],\"inventoryOwner\":\"gmps-kindred\",\"useSource\": true}}}}",
            vehicleEntity);

                    _logger.AppendMessages(string.Format("Request payload for create vehicle call - {0}", createVehicleRequestPayload));

                    dynamic result = RestClient.PostData(ConfigurationManager.AppSettings["createVehicleUrl"], createVehicleRequestPayload);

                    if (result != null && result.result != null)
                    {
                        result = result.result;
                        if (result != null
                            && result.status != null
                            && result.status.GetType() == typeof(JArray)
                            && result.status[0].vehicle != null)
                        {
                            _logger.AppendMessages(string.Format("Create Vehicle call successful . result {0} ", result));

                            resultVehicleEntity.Vin = result.status[0].vehicle.vin ?? string.Empty;
                            resultVehicleEntity.StockNumber = result.status[0].vehicle.stockNumber ?? string.Empty;
                            TryGetMake(result.status[0].vehicle, resultVehicleEntity);
                            TryGetModel(result.status[0].vehicle, resultVehicleEntity);
                            TryGetOemModelCode(result.status[0].vehicle, resultVehicleEntity);
                            TryGetTrimAndStyle(result.status[0].vehicle, resultVehicleEntity);
                            TryGetYear(result.status[0].vehicle, resultVehicleEntity);

                            #region Get Color from response
                            var refStyles = result.status[0].vehicle;
                            if (refStyles.colors != null && refStyles.colors.GetType() == typeof(JArray))
                            {
                                foreach (var iColor in refStyles.colors)
                                {
                                    var color = iColor.color;
                                    var colorRefObject = new ColorReferenceEntity();

                                    if (color.category != null && color.category == "Exterior")
                                    {
                                        resultVehicleEntity.ExternalColor = new Color
                                        {
                                            Code = color.code ?? string.Empty,
                                            //Base = color.exterior.base ?? string.Empty,
                                            Name = color.name ?? string.Empty,
                                            RgbHexCode = color.RGBHexCode ?? string.Empty
                                        };
                                    }

                                    if (color.category != null && color.category == "Interior")
                                    {
                                        resultVehicleEntity.InternalColor = new Color
                                        {
                                            Code = color.code ?? string.Empty,
                                            //Base = color.exterior.base ?? string.Empty,
                                            Name = color.name ?? string.Empty,
                                            RgbHexCode = color.RGBHexCode ?? string.Empty
                                        };
                                    }
                                }
                            }

                            #endregion Get Color from response
                        }
                    }

                    if(result.error != null && result.error.message != null)
                    {
                        _logger.AppendMessages("Create Vehicle call unsuccessful");
                        throw new Exception(result.error.message);
                    }
                }

                #endregion Create Vehicle Call
            }
            catch(Exception ex)
            {
                eventLogType = EventLogEntryType.Error;
                _logger.AppendMessages(string.Format("Error - {0}.", ex));
            }
            finally
            {
                _logger.LogAppendedMessages(eventLogType);
            }

            return resultVehicleEntity;
        }
예제 #4
0
        public VehicleEntity CreateVehicle(VehicleEntity newVehicle)
        {
            var resultVehicleEntity        = new VehicleEntity();
            EventLogEntryType eventLogType = EventLogEntryType.Information;

            try
            {
                #region Detailer Call
                var     requestUri       = ConfigurationManager.AppSettings["detailerUrl"];
                dynamic detailerResponse = RestClient.PostData(requestUri, GetDetailerRequestPayload(newVehicle));
                _logger.AppendMessages("Successfully completed Detailer call before Create Vehicle.");
                #endregion Detailer call

                #region Create Vehicle Call
                if (detailerResponse.vehicles != null && detailerResponse.vehicles.GetType() == typeof(JArray) &&
                    detailerResponse.vehicles[0] != null && detailerResponse.vehicles[0].vehicle != null)
                {
                    JObject vehicleEntity = detailerResponse.vehicles[0].vehicle;
                    vehicleEntity.Add("stockNumber", newVehicle.StockNumber ?? string.Empty);

                    _logger.AppendMessages("Detailer found atleast one vehicle in response.");

                    if (newVehicle.photoIds != null)
                    {
                        //??
                        _logger.AppendMessages("Number of PhotoIds: " + newVehicle.photoIds.Count());
                        //vehicleEntity.Add("assets", JObject.Parse("{\"dealerPhotos\": []}"));
                        foreach (var id in newVehicle.photoIds)
                        {
                            if (id != null && !id.Equals(string.Empty) && !id.Equals(" ") && vehicleEntity.GetValue("assets") == null)
                            {
                                //??
                                _logger.AppendMessages("L");
                                vehicleEntity.Add("assets", JObject.Parse("{\"dealerPhotos\": [{\"id\":" + id + "}]}"));
                            }
                        }
                    }

                    if (vehicleEntity.GetValue("source") == null)
                    {
                        vehicleEntity.Add("source", "M");
                    }

                    var createVehicleRequestPayload = string.Format("{{\"criteria\":{{\"vehicleContexts\":[{{\"vehicleContext\":{{\"vehicle\":{0},\"modifiedFields\":[\"assets\",\"bodyStyle\",\"bodyType\",\"certified\",\"colors.exterior.base\",\"colors.exterior.code\",\"colors.exterior.name\",\"colors.interior.code\",\"colors.interior.name\",\"createdDate\",\"descriptions\",\"doors\",\"drivetrain\",\"engine.aspiration\",\"engine.cylinders\",\"engine.description\",\"engine.displacement\",\"engine.fuelType\",\"engine.power\",\"id\",\"inventoryOwner\",\"lastModifiedDate\",\"lotDate\",\"make.Id\",\"make.label\",\"model.Id\",\"model.label\",\"odometer\",\"oemModelCode\",\"options.dealerOptions\",\"options.factoryOptions\",\"preOwned\",\"prices.discountPrice\",\"prices.internetPrice\",\"prices.invoicePrice\",\"prices.msrp\",\"prices.retailPrice\",\"prices.vendedPrice\",\"stockNumber\",\"style.Id\",\"style.trim\",\"transmission.speeds\",\"transmission.text\",\"transmission.type\",\"unmodifiable\",\"vin\",\"warranties\",\"year\"]}}}}],\"inventoryOwner\":\"gmps-kindred\",\"useSource\": true}}}}",
                                                                    vehicleEntity);

                    _logger.AppendMessages(string.Format("Request payload for create vehicle call - {0}", createVehicleRequestPayload));

                    dynamic result = RestClient.PostData(ConfigurationManager.AppSettings["createVehicleUrl"], createVehicleRequestPayload);

                    if (result != null && result.result != null)
                    {
                        result = result.result;
                        if (result != null &&
                            result.status != null &&
                            result.status.GetType() == typeof(JArray) &&
                            result.status[0].vehicle != null)
                        {
                            _logger.AppendMessages(string.Format("Create Vehicle call successful . result {0} ", result));

                            resultVehicleEntity.Vin         = result.status[0].vehicle.vin ?? string.Empty;
                            resultVehicleEntity.StockNumber = result.status[0].vehicle.stockNumber ?? string.Empty;
                            TryGetMake(result.status[0].vehicle, resultVehicleEntity);
                            TryGetModel(result.status[0].vehicle, resultVehicleEntity);
                            TryGetOemModelCode(result.status[0].vehicle, resultVehicleEntity);
                            TryGetTrimAndStyle(result.status[0].vehicle, resultVehicleEntity);
                            TryGetYear(result.status[0].vehicle, resultVehicleEntity);

                            #region Get Color from response
                            var refStyles = result.status[0].vehicle;
                            if (refStyles.colors != null && refStyles.colors.GetType() == typeof(JArray))
                            {
                                foreach (var iColor in refStyles.colors)
                                {
                                    var color          = iColor.color;
                                    var colorRefObject = new ColorReferenceEntity();

                                    if (color.category != null && color.category == "Exterior")
                                    {
                                        resultVehicleEntity.ExternalColor = new Color
                                        {
                                            Code = color.code ?? string.Empty,
                                            //Base = color.exterior.base ?? string.Empty,
                                            Name       = color.name ?? string.Empty,
                                            RgbHexCode = color.RGBHexCode ?? string.Empty
                                        };
                                    }

                                    if (color.category != null && color.category == "Interior")
                                    {
                                        resultVehicleEntity.InternalColor = new Color
                                        {
                                            Code = color.code ?? string.Empty,
                                            //Base = color.exterior.base ?? string.Empty,
                                            Name       = color.name ?? string.Empty,
                                            RgbHexCode = color.RGBHexCode ?? string.Empty
                                        };
                                    }
                                }
                            }

                            #endregion Get Color from response
                        }
                    }

                    if (result.error != null && result.error.message != null)
                    {
                        _logger.AppendMessages("Create Vehicle call unsuccessful");
                        throw new Exception(result.error.message);
                    }
                }

                #endregion Create Vehicle Call
            }
            catch (Exception ex)
            {
                eventLogType = EventLogEntryType.Error;
                _logger.AppendMessages(string.Format("Error - {0}.", ex));
            }
            finally
            {
                _logger.LogAppendedMessages(eventLogType);
            }

            return(resultVehicleEntity);
        }