1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Data ;
4
+ using System . Data . Entity ;
5
+ using System . Data . Entity . Infrastructure ;
6
+ using System . Linq ;
7
+ using System . Net ;
8
+ using System . Net . Http ;
9
+ using System . Web ;
10
+ using System . Web . Http ;
11
+ using System . Web . Http . Description ;
12
+ using System . Web . Script . Serialization ;
13
+ using WebAPI ;
14
+ using static WebAPI . Controllers . Utils ;
15
+
16
+ namespace WebAPI . Controllers
17
+ {
18
+ public class ExpertInfoesController : ApiController
19
+ {
20
+ private WebAPIEntities db = new WebAPIEntities ( ) ;
21
+
22
+ /// <summary>
23
+ /// 返回专家数据(从cookie中读取userID)
24
+ /// </summary>
25
+ /// <returns>
26
+ /// Message:success/Message:error,Details:error infomation Data:专家数据信息
27
+ /// </returns>
28
+ [ HttpPost , Route ( "Expert/Info" ) ]
29
+ public HttpResponseMessage GetExpertInfo ( )
30
+ {
31
+ Dictionary < string , string > res = new Dictionary < string , string > ( ) ;
32
+ var cookie = HttpContext . Current . Request . Cookies [ "account" ] ;
33
+ if ( cookie == null )
34
+ {
35
+ res . Add ( "Message" , "error" ) ;
36
+ res . Add ( "Details" , "cookie error" ) ;
37
+ return ConvertToJson ( res ) ;
38
+ }
39
+ long userID = long . Parse ( HttpContext . Current . Request . Cookies [ "account" ] [ "userID" ] ) ;
40
+ UserExpert ue = db . UserExpert . FirstOrDefault ( UserExpert => UserExpert . UserID == userID ) ;
41
+ if ( ue == null )
42
+ {
43
+ res . Add ( "Message" , "error" ) ;
44
+ res . Add ( "Details" , "not an expert" ) ;
45
+ return ConvertToJson ( res ) ;
46
+ }
47
+ long expertID = ( long ) ue . ExpertID ;
48
+ ExpertInfo ei = db . ExpertInfo . Find ( expertID ) ;
49
+ res . Add ( "Message" , "success" ) ;
50
+
51
+ db . Configuration . ProxyCreationEnabled = false ;
52
+ JavaScriptSerializer serializer = new JavaScriptSerializer ( ) ;
53
+ Dictionary < string , string > data = new Dictionary < string , string > ( ) ;
54
+ data . Add ( "Name" , ei . Name ) ;
55
+ data . Add ( "Workstation" , ei . Workstation ) ;
56
+ data . Add ( "TimesCited" , ei . TimesCited . ToString ( ) ) ;
57
+ data . Add ( "Results" , ei . Results . ToString ( ) ) ;
58
+ data . Add ( "PUJournals" , ei . PUJournals . ToString ( ) ) ;
59
+ data . Add ( "CSCDJournals" , ei . CSCDJournals . ToString ( ) ) ;
60
+ data . Add ( "CTJournals" , ei . CTJournals . ToString ( ) ) ;
61
+ data . Add ( "EIJournals" , ei . EIJournals . ToString ( ) ) ;
62
+ data . Add ( "SCIEJournals" , ei . SCIEJournals . ToString ( ) ) ;
63
+ data . Add ( "SSCIJournals" , ei . SSCIJournals . ToString ( ) ) ;
64
+ data . Add ( "OtherJournals" , ei . OtherJournals . ToString ( ) ) ;
65
+ data . Add ( "ConferencePapers" , ei . ConferencePapers . ToString ( ) ) ;
66
+ data . Add ( "Field" , ei . Field ) ;
67
+ data . Add ( "Books" , ei . Books . ToString ( ) ) ;
68
+ data . Add ( "Others" , ei . Others . ToString ( ) ) ;
69
+ string r = serializer . Serialize ( data ) ;
70
+ res . Add ( "Data" , r ) ;
71
+ return ConvertToJson ( res ) ;
72
+ }
73
+
74
+ /// <summary>
75
+ /// 修改专家信息(改什么传什么)
76
+ /// </summary>
77
+ /// <param name="info">Name, Workstation, Field</param>
78
+ /// <returns>Message:success / Message:error,Details:xxx</returns>
79
+ [ HttpPost , Route ( "Expert/ModifyInfo" ) ]
80
+ public HttpResponseMessage ModifyExpertInfo ( ExpertInfo info )
81
+ {
82
+ Dictionary < string , string > res = new Dictionary < string , string > ( ) ;
83
+ var cookie = HttpContext . Current . Request . Cookies [ "account" ] ;
84
+ if ( cookie == null )
85
+ {
86
+ res . Add ( "Message" , "error" ) ;
87
+ res . Add ( "Details" , "cookie error" ) ;
88
+ return ConvertToJson ( res ) ;
89
+ }
90
+ long userID = long . Parse ( HttpContext . Current . Request . Cookies [ "account" ] [ "userID" ] ) ;
91
+ UserExpert ue = db . UserExpert . FirstOrDefault ( UserExpert => UserExpert . UserID == userID ) ;
92
+ if ( ue == null )
93
+ {
94
+ res . Add ( "Message" , "error" ) ;
95
+ res . Add ( "Details" , "not an expert" ) ;
96
+ return ConvertToJson ( res ) ;
97
+ }
98
+ long expertID = ( long ) ue . ExpertID ;
99
+ ExpertInfo ei = db . ExpertInfo . Find ( expertID ) ;
100
+ if ( ei . Name != null )
101
+ ei . Name = info . Name ;
102
+ if ( ei . Workstation != null )
103
+ ei . Workstation = info . Workstation ;
104
+ if ( ei . Field != null )
105
+ ei . Field = info . Field ;
106
+ db . SaveChanges ( ) ;
107
+ res . Add ( "Message" , "success" ) ;
108
+ return ConvertToJson ( res ) ;
109
+
110
+ }
111
+
112
+ /// <summary>
113
+ /// 返回专家Paper
114
+ /// </summary>
115
+ /// <returns></returns>
116
+ [ HttpPost , Route ( "Expert/GetPapers" ) ]
117
+ public HttpResponseMessage GetPapersInfo ( )
118
+ {
119
+ Dictionary < string , string > res = new Dictionary < string , string > ( ) ;
120
+ var cookie = HttpContext . Current . Request . Cookies [ "account" ] ;
121
+ if ( cookie == null )
122
+ {
123
+ res . Add ( "Message" , "error" ) ;
124
+ res . Add ( "Details" , "cookie error" ) ;
125
+ return ConvertToJson ( res ) ;
126
+ }
127
+ long userID = long . Parse ( HttpContext . Current . Request . Cookies [ "account" ] [ "userID" ] ) ;
128
+ UserExpert ue = db . UserExpert . FirstOrDefault ( UserExpert => UserExpert . UserID == userID ) ;
129
+ if ( ue == null )
130
+ {
131
+ res . Add ( "Message" , "error" ) ;
132
+ res . Add ( "Details" , "not an expert" ) ;
133
+ return ConvertToJson ( res ) ;
134
+ }
135
+ long expertID = ( long ) ue . ExpertID ;
136
+ int paperCount = db . ExpertPaper . Count ( ExpertPaper => ExpertPaper . ExpertID == expertID ) ;
137
+ Dictionary < string , string > data = new Dictionary < string , string > ( ) ;
138
+ JavaScriptSerializer serializer = new JavaScriptSerializer ( ) ;
139
+ if ( paperCount == 0 )
140
+ {
141
+ data . Add ( "number" , "0" ) ;
142
+ data . Add ( "paper" , "[]" ) ;
143
+ res . Add ( "Data" , serializer . Serialize ( data ) ) ;
144
+ }
145
+ string papers = "[" ;
146
+ var eps =
147
+ from ExpertPaper in db . ExpertPaper
148
+ where ExpertPaper . ExpertID == expertID
149
+ select ExpertPaper ;
150
+ bool first = true ;
151
+ foreach ( var ep in eps )
152
+ {
153
+ if ( first != true )
154
+ papers = papers + "," ;
155
+ Dictionary < string , string > paperData = new Dictionary < string , string > ( ) ;
156
+ Paper paper = db . Paper . FirstOrDefault ( Paper => Paper . PaperID == ep . PaperID ) ;
157
+ paperData . Add ( "Id" , paper . PaperID . ToString ( ) ) ;
158
+ paperData . Add ( "Title" , paper . Title ) ;
159
+ paperData . Add ( "Abstract" , paper . Abstract ) ;
160
+ paperData . Add ( "Publisher" , paper . Publisher ) ;
161
+ papers = papers + serializer . Serialize ( paperData ) ;
162
+ first = false ;
163
+ }
164
+ data . Add ( "number" , paperCount . ToString ( ) ) ;
165
+ data . Add ( "Data" , papers ) ;
166
+ res . Add ( "Data" , serializer . Serialize ( data ) ) ;
167
+ return ConvertToJson ( res ) ;
168
+
169
+ }
170
+
171
+ /// <summary>
172
+ /// 返回专家Patent
173
+ /// </summary>
174
+ /// <returns></returns>
175
+ [ HttpPost , Route ( "Expert/GetPatent" ) ]
176
+ public HttpResponseMessage GetPatentInfo ( )
177
+ {
178
+ Dictionary < string , string > res = new Dictionary < string , string > ( ) ;
179
+ var cookie = HttpContext . Current . Request . Cookies [ "account" ] ;
180
+ if ( cookie == null )
181
+ {
182
+ res . Add ( "Message" , "error" ) ;
183
+ res . Add ( "Details" , "cookie error" ) ;
184
+ return ConvertToJson ( res ) ;
185
+ }
186
+ long userID = long . Parse ( HttpContext . Current . Request . Cookies [ "account" ] [ "userID" ] ) ;
187
+ UserExpert ue = db . UserExpert . FirstOrDefault ( UserExpert => UserExpert . UserID == userID ) ;
188
+ if ( ue == null )
189
+ {
190
+ res . Add ( "Message" , "error" ) ;
191
+ res . Add ( "Details" , "not an expert" ) ;
192
+ return ConvertToJson ( res ) ;
193
+ }
194
+ long expertID = ( long ) ue . ExpertID ;
195
+ int paperCount = db . ExpertPatent . Count ( ExpertPatent => ExpertPatent . ExpertID == expertID ) ;
196
+ Dictionary < string , string > data = new Dictionary < string , string > ( ) ;
197
+ JavaScriptSerializer serializer = new JavaScriptSerializer ( ) ;
198
+ if ( paperCount == 0 )
199
+ {
200
+ data . Add ( "number" , "0" ) ;
201
+ data . Add ( "paper" , "[]" ) ;
202
+ res . Add ( "Data" , serializer . Serialize ( data ) ) ;
203
+ }
204
+ string papers = "[" ;
205
+ var eps =
206
+ from ExpertPatent in db . ExpertPatent
207
+ where ExpertPatent . ExpertID == expertID
208
+ select ExpertPatent ;
209
+ bool first = true ;
210
+ foreach ( var ep in eps )
211
+ {
212
+ if ( first != true )
213
+ papers = papers + "," ;
214
+ Dictionary < string , string > paperData = new Dictionary < string , string > ( ) ;
215
+ Patent paper = db . Patent . FirstOrDefault ( Patent => Patent . PatentID == ep . PatentID ) ;
216
+ paperData . Add ( "Id" , paper . PatentID . ToString ( ) ) ;
217
+ paperData . Add ( "Title" , paper . Title ) ;
218
+ paperData . Add ( "Abstract" , paper . Abstract ) ;
219
+ paperData . Add ( "Publisher" , paper . ApplyDate . ToString ( ) ) ;
220
+ papers = papers + serializer . Serialize ( paperData ) ;
221
+ first = false ;
222
+ }
223
+ data . Add ( "number" , paperCount . ToString ( ) ) ;
224
+ data . Add ( "Data" , papers ) ;
225
+ res . Add ( "Data" , serializer . Serialize ( data ) ) ;
226
+ return ConvertToJson ( res ) ;
227
+
228
+ }
229
+ }
230
+ }
0 commit comments