コード例 #1
0
ファイル: SqliteFavorites.cs プロジェクト: arlyon/browser
        /// <summary>
        /// Changes the entry in the database and calls the event to update in memory.
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <param name="update">
        /// The get update.
        /// </param>
        public async void UpdateById(int id, FavoritesLocation update)
        {
            using (var db = new DataContext())
            {
                var updated = await db.Favorites.SingleAsync(fav => fav.Id == id);

                updated.Url  = update.Url;
                updated.Name = update.Name;
                await db.SaveChangesAsync();

                this.OnFavoritesAddOrUpdate?.Invoke(this, new FavoritesUpdateEventArgs(updated));
            }
        }
コード例 #2
0
ファイル: SqliteFavorites.cs プロジェクト: arlyon/browser
        /// <summary>
        /// Adds a url to the favorites list and into the database.
        /// </summary>
        /// <param name="url">
        /// The url.
        /// </param>
        /// <returns>
        /// The <see cref="FavoritesLocation"/>.
        /// </returns>
        private FavoritesLocation Add(Url url)
        {
            var loc = new FavoritesLocation()
            {
                Name = url.Host, Url = url
            };

            using (var db = new DataContext())
            {
                // if url exists in database
                var inDbUrl = url.Id > 0 ? db.Urls.Single(u => u.Id == url.Id) : db.Urls.SingleOrDefault(u => u.HashCode == url.HashCode);
                loc.Url = inDbUrl ?? loc.Url;

                db.Favorites.Add(loc);
                db.SaveChanges();
            }

            // push change to lists
            this.OnFavoritesAddOrUpdate?.Invoke(this, new FavoritesUpdateEventArgs(loc));
            return(loc);
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FavoritesUpdateEventArgs"/> class.
 /// </summary>
 /// <param name="location">
 /// The location.
 /// </param>
 public FavoritesUpdateEventArgs(FavoritesLocation location)
 {
     this.Location = location;
 }