Example #1
0
        /// <summary>
        /// The one method to put different types of estate objects into caches. <br/>
        /// Key is chosen automatically. <br/>
        /// Method checks referential integrity on: <br/>
        /// EstateObject.SellerID - Person.key. <br/>
        /// EstateObject.LocationID - Location.key.
        /// </summary>
        /// <param name="value">Estate object to put into cache.</param>
        public static void PutEstateObject (EstateObject value)
        {
            using (var tx = Client.GetTransactions().TxStart())
            {
                // Error if Person with key = value.SellerID is not found.
                if (!(PersonCache.ContainsKey(value.SellerID)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into EstateObject cache.")
                    {
                        Operation = "put",
                        TableName = "EstateObject",
                        FieldName = "SellerID",
                        ReadableMessage = $"Can not put new entry into EstateObject cache because Person with key {value.SellerID} does not exist."
                    };
                }

                // Error if Location not found.
                if (!(LocationCache.ContainsKey(value.LocationID)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into EstateObject cache.")
                    {
                        Operation = "put",
                        TableName = "EstateObject",
                        FieldName = "LocationID",
                        ReadableMessage = $"Can not put new entry into EstateObject cache because Location with key {value.LocationID} does not exist."
                    };
                }

                // Normal operation.
                int key = LastUsedKeys.Get("estateobject");
                switch ((char)value.Variant)
                {
                    case 'o':
                    ObjectCache.Put (key, value);
                    break;

                    case 'h':
                    HouseCache.Put (key, (House)value);
                    break;
                    
                    case 'f':
                    FlatCache.Put (key, (Flat)value);
                    break;

                    case 'l':
                    LandplotCache.Put (key, (Landplot)value);
                    break;

                    default: 
                    break;
                }
                LastUsedKeys.Put("estateobject", key+1);
                tx.Commit();
            }
        }
Example #2
0
        /// <summary>
        /// Get flats in mentioned location, optionally order and set max price.
        /// </summary>
        /// <param name="location"></param>
        /// <param name="price"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        public static Dictionary <int, Flat> GetFlats(int location, int price = 0, string order = "")
        {
            string querystring1 = "", querystring2 = "";

            switch (order)
            {
            case "new":
                querystring1 = $"select _key, _val, PostDate, Price, LocationID, isOpen from Flats where LocationID={location} and isOpen=true ";
                querystring2 = " order by PostDate desc;";
                break;

            case "price":
                querystring1 = $"select _key, _val, Price, LocationID, isOpen from Flats where LocationID={location} and isOpen=true ";
                querystring2 = " order by Price;";
                break;

            case "prisqm":
                querystring1 = $"select _key, _val, Price, HomeArea, (Price/HomeArea) as SqmPrice, LocationID, isOpen from Flats where LocationID={location} and isOpen=true ";
                querystring2 = " order by SqmPrice;";
                break;

            case "pop":
                querystring1 = $"select _key, _val, Price, Cnt, LocationID, isOpen from \"estateobject\".Flats as A left join (select ObjectID, count(PersonID) as Cnt from \"bookmark\".Bookmarks group by ObjectID) as B on A._key = B.ObjectID where LocationID={location} and isOpen=true ";
                querystring2 = " order by Cnt desc;";
                break;

            case "state":
                querystring1 = $"select _key, _val, Price, State, LocationID, isOpen from Flats where LocationID={location} and isOpen=true ";
                querystring2 = " order by State desc;";
                break;

            default:
                querystring1 = $"select _key, _val, Price, LocationID, isOpen from Flats where LocationID={location} and isOpen=true ";
                querystring2 = ";";
                break;
            }

            if (price > 0)
            {
                querystring1 += $" and Price<={price} ";
            }
            querystring1 += querystring2;
            Dictionary <int, Flat> result = new Dictionary <int, Flat>();

            foreach (var row in FlatCache.Query(new SqlFieldsQuery(querystring1)))
            {
                result[(int)row[0]] = row[1] as Flat;
            }
            return(result);
        }
Example #3
0
        /// <summary>
        /// Simply get all estate objects
        /// </summary>
        /// <returns></returns>
        public static Dictionary <int, EstateObject> GetEstateObjects()
        {
            Dictionary <int, EstateObject> result = new Dictionary <int, EstateObject>();

            foreach (var row in ObjectCache.Query(new SqlFieldsQuery("select _key, _val from EstateObjects order by PostDate;")))
            {
                result[(int)row[0]] = (row[1] as EstateObject);
            }
            foreach (var row in HouseCache.Query(new SqlFieldsQuery("select _key, _val from Houses order by PostDate;")))
            {
                result[(int)row[0]] = (row[1] as House);
            }
            foreach (var row in FlatCache.Query(new SqlFieldsQuery("select _key, _val from Flats order by PostDate;")))
            {
                result[(int)row[0]] = (row[1] as Flat);
            }
            foreach (var row in LandplotCache.Query(new SqlFieldsQuery("select _key, _val from Landplots order by PostDate;")))
            {
                result[(int)row[0]] = (row[1] as Landplot);
            }
            return(result);
        }