Exemplo n.º 1
0
 static HistoryDb()
 {
     using (var db = new HistoryDb())
     {
         db.Database.Migrate();
     }
 }
Exemplo n.º 2
0
 public static async Task ClearAsync()
 {
     using (var db = new HistoryDb())
     {
         db.HistorySet.RemoveRange(db.HistorySet);
         await db.SaveChangesAsync();
     }
 }
Exemplo n.º 3
0
 public static async Task <List <HistoryRecord> > GetAsync(int limit = -1)
 {
     using (var db = new HistoryDb())
     {
         IQueryable <HistoryRecord> data = db.HistorySet.OrderByDescending(h => h.TimeStamp);
         if (limit > 0)
         {
             data = data.Take(limit);
         }
         return(await data.ToListAsync());
     }
 }
Exemplo n.º 4
0
 public static void Remove(Expression <Func <HistoryRecord, bool> > predicate)
 {
     if (predicate is null)
     {
         throw new ArgumentNullException(nameof(predicate));
     }
     using (var db = new HistoryDb())
     {
         db.HistorySet.RemoveRange(db.HistorySet.Where(predicate));
         db.SaveChanges();
     }
 }
Exemplo n.º 5
0
 public static void Remove(int id)
 {
     if (id <= 0)
     {
         throw new ArgumentOutOfRangeException(nameof(id), "Id of record is 0.");
     }
     using (var db = new HistoryDb())
     {
         db.HistorySet.Remove(db.HistorySet.Find(id));
         db.SaveChanges();
     }
 }
Exemplo n.º 6
0
        public static void Remove(Uri uri)
        {
            if (uri is null)
            {
                throw new ArgumentNullException(nameof(uri));
            }
            var str = uri.ToString();

            using (var db = new HistoryDb())
            {
                db.HistorySet.RemoveRange(db.HistorySet.Where(r => EF.Property <string>(r, "uri") == str));
                db.SaveChanges();
            }
        }
Exemplo n.º 7
0
 public static void Update(HistoryRecord record)
 {
     if (record is null)
     {
         throw new ArgumentNullException(nameof(record));
     }
     if (record.Id == 0)
     {
         throw new ArgumentException("Id of record is 0.", nameof(record));
     }
     record.UpdateTime();
     using (var db = new HistoryDb())
     {
         db.HistorySet.Update(record);
         db.SaveChanges();
     }
 }
Exemplo n.º 8
0
        public static int Add(HistoryRecord record)
        {
            if (record is null)
            {
                throw new ArgumentNullException(nameof(record));
            }
            if (record.Id != 0)
            {
                throw new ArgumentException("Id of record is not 0.", nameof(record));
            }

            record.UpdateTime();
            using (var db = new HistoryDb())
            {
                db.HistorySet.Add(record);
                db.SaveChanges();
                return(record.Id);
            }
        }