Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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);
        }