-
Notifications
You must be signed in to change notification settings - Fork 1
/
MangaMeta.cs
151 lines (129 loc) · 3.76 KB
/
MangaMeta.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using afung.MangaWeb3.Common;
namespace afung.MangaWeb3.Server
{
public class MangaMeta
{
public int Id
{
get;
private set;
}
public Manga ParentManga
{
get;
private set;
}
public string Author
{
get;
private set;
}
public int Volume
{
get;
private set;
}
public string Series
{
get;
private set;
}
public int Year
{
get;
private set;
}
public string Publisher
{
get;
private set;
}
private MangaMeta()
{
Id = -1;
}
public static MangaMeta CreateNewMeta(Manga manga)
{
MangaMeta newMeta = new MangaMeta();
newMeta.ParentManga = manga;
newMeta.Author = newMeta.Series = newMeta.Publisher = string.Empty;
newMeta.Volume = newMeta.Year = -1;
return newMeta;
}
private static MangaMeta FromData(Dictionary<string, object> data)
{
MangaMeta newMeta = new MangaMeta();
newMeta.Id = Convert.ToInt32(data["id"]);
newMeta.Author = Convert.ToString(data["author"]);
newMeta.Series = Convert.ToString(data["series"]);
newMeta.Publisher = Convert.ToString(data["publisher"]);
newMeta.Volume = Convert.ToInt32(data["volume"]);
newMeta.Year = Convert.ToInt32(data["year"]);
return newMeta;
}
public static MangaMeta Get(Manga manga)
{
Dictionary<string, object>[] resultSet = Database.Select("meta", "`mid`=" + Database.Quote(manga.Id.ToString()));
if (resultSet.Length > 0)
{
MangaMeta newMeta = FromData(resultSet[0]);
newMeta.ParentManga = manga;
return newMeta;
}
return null;
}
public void Save()
{
Dictionary<string, object> data = new Dictionary<string, object>();
data.Add("mid", ParentManga.Id);
data.Add("author", Author);
data.Add("volume", Volume);
data.Add("series", Series);
data.Add("year", Year);
data.Add("publisher", Publisher);
if (Id == -1)
{
Id = Database.InsertAndReturnId("meta", data);
}
else
{
data.Add("id", Id);
Database.Replace("meta", data);
}
}
public void Update(AdminMangaMetaJson obj)
{
Author = Utility.Remove4PlusBytesUtf8Chars(obj.author);
Volume = obj.volume;
Series = Utility.Remove4PlusBytesUtf8Chars(obj.series);
Year = obj.year;
Publisher = Utility.Remove4PlusBytesUtf8Chars(obj.publisher);
Save();
}
public static string[] GetAuthors()
{
return Database.GetDistinctStringValues("meta", "author");
}
public static string[] GetSeries()
{
return Database.GetDistinctStringValues("meta", "series");
}
public static string[] GetPublishers()
{
return Database.GetDistinctStringValues("meta", "publisher");
}
public void Copy(MangaMeta other)
{
Author = other.Author;
Volume = other.Volume;
Series = other.Series;
Year = other.Year;
Publisher = other.Publisher;
Save();
}
}
}