Ejemplo n.º 1
0
        private async Task <bool> PopulateFields()
        {
            bool resp = false;

            try
            {
                if (!_vehicleObjectId.Equals("NA"))
                {
                    resp = true;
                    await _dataManager.LoadSingleVehicleProfile(_vehicleObjectId);

                    _images = CarProfile.CarsForSale;

                    //load the details
                    string price = "POR - (Price On Request)";
                    await _dataManager.LoadSingleVehicleProfile(_vehicleObjectId);

                    if (CarProfile.description != null || !string.IsNullOrEmpty(CarProfile.description))
                    {
                        var description = CarProfile.description.Trim();
                        if (description.Length > 0)
                        {
                            _lblDescription.Text = CarProfile.description;
                        }
                    }

                    if (CarProfile.listPrice != null)
                    {
                        price = HelperClass.CleanUpPrice(CarProfile.listPrice);
                    }

                    _lblPrice.Text        = price ?? "POR - (Price On Request)";;
                    _lblMake.Text         = CarProfile.make ?? "N/A";
                    _lblModel.Text        = CarProfile.model ?? "N/A";
                    _lblModelVar.Text     = CarProfile.modelVariant ?? "N/A";
                    _lblYear.Text         = CarProfile.year ?? "N/A";
                    _lblDriveTrain.Text   = CarProfile.driveTrain ?? "N/A";
                    _lblEngine.Text       = CarProfile.engine ?? "N/A";
                    _lblTransmission.Text = CarProfile.transmission ?? "N/A";
                    _lblMileage.Text      = CarProfile.mileage.ToString();
                    _lblVin.Text          = CarProfile.vin ?? "N/A";
                    _lblStockNo.Text      = CarProfile.status ?? "N/A";
                    _lblVat.Text          = CarProfile.vat ? "Yes" : "No";
                    _lblIntColor.Text     = CarProfile.interiorColor ?? "N/A";
                    _lblExtColor.Text     = CarProfile.exteriorColor ?? "N/A";
                    _lblOwnerName.Text    = CarProfile.ownerUsername ?? "N/A";
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("Error loading vehicle details {0} {1}", ex.Message, ex.StackTrace));
            }

            AndHUD.Shared.Dismiss(this);
            return(resp);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// prefill the vehicles table for local cache
        /// </summary>
        /// <param name="limit"></param>
        /// <param name="pageIndex"></param>
        public async void CacheVehicleProfiles(int limit = 1000, int pageIndex = 0)
        {
            var vehicleProfile = new List <Tuple <string, string, string, string, Uri, string> >();
            List <VehicleProfileTable> sqlVehicleProfileList = new List <VehicleProfileTable>();

            try
            {
                var vehicleProfileData = await vehicleData.VehicleProfile(limit, pageIndex);

                // ReSharper disable once PossibleMultipleEnumeration
                foreach (var profile in vehicleProfileData)
                {
                    string rawPrice  = profile.ContainsKey("listPrice") ? profile.Get <string>("listPrice") : "0";
                    var    objectId  = profile.ObjectId;
                    var    listPrice = HelperClass.CleanUpPrice(rawPrice);
                    var    make      = profile.ContainsKey("make") ? profile.Get <string>("make") : "N/A";
                    var    carModel  = profile.ContainsKey("model") ? profile.Get <string>("model") : "N/A";
                    var    username  = profile.ContainsKey("username") ? profile.Get <string>("username") : "N/A";

                    var imgUrl = await vehicleData.FetchSingleCarImage(profile.ObjectId);

                    if (imgUrl != null)
                    {
                        var vehicleTuple = new Tuple <string, string, string, string, Uri, string>(profile.ObjectId, make,
                                                                                                   listPrice, carModel, imgUrl, username);
                        vehicleProfile.Add(vehicleTuple);
                    }

                    var json         = JsonConvert.SerializeObject(vehicleProfile); //@TODO some chaos happening here corrrect it
                    var profileTable = new VehicleProfileTable()
                    {
                        ParseObjectId   = objectId,
                        Make            = make,
                        Model           = carModel,
                        Username        = username,
                        VehicleJsonData = json
                    };

                    sqlVehicleProfileList.Add(profileTable);
                }


                //now insert to table
                vCache.InsertVehcileProfile(sqlVehicleProfileList);
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }