Esempio n. 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;
 }
Esempio n. 2
0
        /// <summary>
        /// Get bookmarked objects.
        /// </summary>
        /// <param name="personid"></param>
        /// <returns>Key-value pairs of bookmarked objects' short descriptions.</returns>
        public static Dictionary <int, string> GetBookmarks(int personid)
        {
            List <int> idlist = new List <int>();
            Dictionary <int, string> result = new Dictionary <int, string>();

            foreach (var row in BookmarkCache.Query(new SqlFieldsQuery($"select ObjectID from Bookmarks where PersonID={personid}")))
            {
                idlist.Add((int)row[0]);
            }
            foreach (var entry in ObjectCache.GetAll(idlist))
            {
                var obj = entry.Value;
                if (obj.Description.Length > 200)
                {
                    obj.Description = obj.Description.Substring(0, 180);
                }
                result.Add(entry.Key, $"{obj.PostDate.ToLocalTime()} | {obj.Price} USD | {obj.Description}");
            }
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Put bookmark entity into the cache. <br/>
        /// Referential integrity check is done on: <br/>
        /// Bookmark.PersonID - Person.key <br/>
        /// Bookmark.ObjectID - Object.key <br/>
        /// </summary>
        /// <param name="value">Bookmark to put into the cache.</param>
        public static void PutBookmark (Bookmark value)
        {
            using (var tx = Client.GetTransactions().TxStart())
            {
                // Error if Person with key = value.ClientID is not found.
                if (!(PersonCache.ContainsKey(value.PersonID)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into Bookmark cache.")
                    {
                        Operation = "put",
                        TableName = "Bookmark",
                        FieldName = "PersonID",
                        ReadableMessage = $"Can not put new entry into Bookmark cache because Person with key {value.PersonID} does not exist."
                    };
                }

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

                // Normal operation
                long key = (((long)value.PersonID)<<32) + value.ObjectID;
                BookmarkCache.Put (key, value);
                tx.Commit();
            }
        }