-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabase.cs
48 lines (42 loc) · 1.28 KB
/
Database.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
class Database : DbContext
{
public DbSet<Page> Pages { get; set; }
private IConfiguration Config { get; }
public Database(IConfiguration config)
{
Config = config;
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
var connectionString = Config["CONNECTION_STRING"];
if (connectionString.StartsWith("Filename="))
{
options.UseSqlite(connectionString);
}
else
{
options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
}
}
protected override void OnModelCreating(ModelBuilder model)
{
model.Entity<Page>().HasKey(p => p.ProcessId);
model.Entity<Page>().HasIndex(p => p.InProgress);
}
public Page GetMostRecentByPid(string pid)
{
return Pages.OrderByDescending(p => p.Uploaded).FirstOrDefault(p => p.Pid == pid);
}
}
class Page
{
public string Pid { get; set; }
public int HtrId { get; set; }
public int ProcessId { get; set;}
public bool InProgress { get; set; }
public string User { get; set; }
public DateTime Uploaded { get; set; }
public DateTime? Downloaded { get; set; }
}