コード例 #1
0
ファイル: Query.cs プロジェクト: qdraw/starsky
        /// <summary>
        /// Add a new item to the database
        /// </summary>
        /// <param name="updateStatusContent">the item</param>
        /// <returns>item with id</returns>
        public FileIndexItem AddItem(FileIndexItem updateStatusContent)
        {
            if (string.IsNullOrWhiteSpace(updateStatusContent.FileName) &&
                updateStatusContent.IsDirectory == false)
            {
                throw new MissingFieldException("use filename (exception: the root folder can have no name)");
            }

            try
            {
                _context.FileIndex.Add(updateStatusContent);
                _context.SaveChanges();
            }
            catch (ObjectDisposedException)
            {
                var context = new InjectServiceScope(_scopeFactory).Context();
                context.FileIndex.Add(updateStatusContent);
                context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException e)
            {
                _logger?.LogInformation("AddItem catch-ed DbUpdateConcurrencyException (ignored)", e);
            }

            AddCacheItem(updateStatusContent);

            return(updateStatusContent);
        }
コード例 #2
0
ファイル: QueryAddRange.cs プロジェクト: qdraw/starsky
        /// <summary>
        /// (Sync) Add a new item to the database
        /// </summary>
        /// <param name="fileIndexItemList"></param>
        /// <returns>items with id</returns>
        public List <FileIndexItem> AddRange(List <FileIndexItem> fileIndexItemList)
        {
            try
            {
                _context.FileIndex.AddRange(fileIndexItemList);
                _context.SaveChanges();
            }
            catch (ObjectDisposedException)
            {
                var context = new InjectServiceScope(_scopeFactory).Context();
                context.FileIndex.AddRange(fileIndexItemList);
                context.SaveChanges();
            }

            foreach (var fileIndexItem in fileIndexItemList)
            {
                AddCacheItem(fileIndexItem);
            }

            return(fileIndexItemList);
        }