Exemplo n.º 1
0
        public static List <VEHICLE> GetVehiclesByMarketMakeModel(string market, string make, string model, string pricerange)
        {
            List <VEHICLE> retval = null;

            using (Mongo mongo = new Mongo(config.BuildConfiguration()))
            {
                mongo.Connect();
                var db = mongo.GetDatabase(VehicleRecords.VEHICLE_DB.DataBaseName);

                IMongoCollection <Document> collPriceRange = db.GetCollection <Document>(PRICERANGE.TableName);
                Document qPriceRange = new Document();
                qPriceRange["VALUENAME"] = pricerange;

                Document   docPriceRange = collPriceRange.FindOne(qPriceRange);
                PRICERANGE pr            = PRICERANGE.GetPRICERANGEFromDocument(docPriceRange);

                IMongoCollection <Document> collVehicles = db.GetCollection <Document>(VEHICLE.TableName);

                Document qVehicles = new Document();
                qVehicles["MARKET"] = market;

                if (make.Length > 0 && make != "All")
                {
                    qVehicles["MAKE"] = make;
                }

                if (model.Length > 0 && model != "All")
                {
                    qVehicles["MODEL"] = model;
                }

                qVehicles["STILL_FOR_SALE"] = "YES";

                string where = $"(this.CURRENT_PRICE >= {pr.LOWBOUND} && this.CURRENT_PRICE <= {pr.HIGHBOUND})";
                qVehicles.Add("$where", new Code(where));

                VEHICLE[] foundvehicles = VEHICLE.GetVEHICLEsFromQueryDocument(collVehicles, qVehicles);

                if (foundvehicles != null && foundvehicles.Count <VEHICLE>() > 0)
                {
                    retval = foundvehicles.ToList <VEHICLE>();
                }
                mongo.Disconnect();
            }

            return(retval);
        }
Exemplo n.º 2
0
        public static PRICERANGE GetPriceRange(string ValueName)
        {
            PRICERANGE retval = null;

            using (Mongo mongo = new Mongo(config.BuildConfiguration()))
            {
                mongo.Connect();
                var db = mongo.GetDatabase(VehicleRecords.VEHICLE_DB.DataBaseName);
                IMongoCollection <Document> collVehicles = db.GetCollection <Document>(PRICERANGE.TableName);

                var qPR = new Document();
                qPR["VALUENAME"] = ValueName;

                Document resultsdoc = collVehicles.FindOne(qPR);

                if (resultsdoc != null)
                {
                    retval = PRICERANGE.GetPRICERANGEFromDocument(resultsdoc);
                }
            }
            return(retval);
        }