Exemple #1
0
 /// <summary>
 /// Delete an estate object.
 /// </summary>
 /// <param name="key">Key of object to delete.</param>
 /// <returns>True if object was successfully deleted.</returns>
 public static bool DeleteObject(int key)
 {
     if (DealCache.ContainsKey(key))
     {
         return false;
     }
     OrderCache.Query (new SqlFieldsQuery
         ($"delete from Orders where ObjectID={key};"));
     BookmarkCache.Query (new SqlFieldsQuery
         ($"delete from Bookmarks where ObjectID={key};"));
     MatchCache.Query (new SqlFieldsQuery
         ($"delete from Matches where ObjectID={key};"));
     ObjectCache.Remove(key);
     return true;
 }
Exemple #2
0
        /// <summary>
        /// Put deal entity into the cache. <br/>
        /// Referential integrity is checked on: <br/>
        /// Deal.key - EstateObject.key <br/>
        /// Deal.BuyerID - Person.key <br/>
        /// Deal.SellerID - Person.key <br/>
        /// Deal.AgentID - Agent.key <br/>
        /// </summary>
        /// <param name="value">Deal to put into the cache.</param>
        public static void PutDeal (int key, Deal value)
        {
            using (var tx = Client.GetTransactions().TxStart())
            {
                // Error if EstateObject with mentioned key is not found.
                if (!(ObjectCache.ContainsKey(key)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into Deal cache.")
                    {
                        Operation = "put",
                        TableName = "Deal",
                        FieldName = "key",
                        ReadableMessage = $"Can not put new entry into Deal cache because EstateObject with key {key} does not exist."
                    };
                }

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

                // 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 Deal cache.")
                    {
                        Operation = "put",
                        TableName = "Deal",
                        FieldName = "SellerID",
                        ReadableMessage = $"Can not put new entry into Deal cache because Person with key {value.SellerID} does not exist."
                    };
                }

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

                // Normal operation
                DealCache.Put (key, value);
                tx.Commit();
            }
        }