Skip to content

Commit 7a5f2fa

Browse files
author
Xing Zhihuan
committed
增加ExpertInfo相关接口,增加上传专利接口
1 parent 816aa5f commit 7a5f2fa

File tree

3 files changed

+369
-4
lines changed

3 files changed

+369
-4
lines changed
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
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+
}

WebApplication1/Controllers/PapersController.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private long GenPaperID()
3737
/// </summary>
3838
/// <returns>上传paper后生成的paperID或失败</returns>
3939
[HttpPost]
40-
[Route("expert/UploadPaper")]
40+
[Route("Expert/UploadPaper")]
4141
public async Task<HttpResponseMessage> UploadPaper(string title)
4242
{
4343
long paperID = GenPaperID();
@@ -92,7 +92,7 @@ public async Task<HttpResponseMessage> UploadPaper(string title)
9292
/// 如: post [www.xxx.com]/expert/UpdatePaper?paperID=61234539523
9393
/// </param>
9494
/// <returns>Message: "success"或"failed" Details: 错误具体信息</returns>
95-
[HttpPost, Route("expert/UpdatePaper")]
95+
[HttpPost, Route("Expert/UpdatePaper")]
9696
public async Task<HttpResponseMessage> UpdatePaper(long paperID)
9797
{
9898
Dictionary<string, string> res = new Dictionary<string, string>();
@@ -147,13 +147,25 @@ public async Task<HttpResponseMessage> UpdatePaper(long paperID)
147147
/// </summary>
148148
/// <param name="newPaper">Paper的各项需要手动提供的数据</param>
149149
/// <returns>"success"或"failed"</returns>
150-
[Route("expert/ModifyPaperInfo")]
150+
[Route("Expert/ModifyPaperInfo")]
151151
public HttpResponseMessage ModifyPaperInfo(Paper newPaper)
152152
{
153153
Dictionary<string, string> res = new Dictionary<string, string>();
154154
try
155155
{
156+
var cookie = HttpContext.Current.Request.Cookies["account"];
157+
if(cookie == null)
158+
{
159+
res.Add("Message", "failed");
160+
res.Add("Details", "cookie error");
161+
return ConvertToJson(res);
162+
}
156163
Paper find = db.Paper.Find(newPaper.PaperID);
164+
if (long.Parse(cookie["UserID"]) != find.UpID)
165+
{
166+
res.Add("Message", "forbidden");
167+
return ConvertToJson(res);
168+
}
157169
find.Abstract = newPaper.Abstract;
158170
find.IPC = newPaper.IPC;
159171
find.Type = newPaper.Type;
@@ -181,7 +193,7 @@ public HttpResponseMessage ModifyPaperInfo(Paper newPaper)
181193
/// </summary>
182194
/// <param name="p">PaperID</param>
183195
/// <returns>"forbidden"无权限 "failed" 失败 "success" 成功</returns>
184-
[HttpPost, Route("expert/DeletePaper")]
196+
[HttpPost, Route("Expert/DeletePaper")]
185197
public HttpResponseMessage DeletePaper(Paper p)
186198
{
187199
Dictionary<string, string> res = new Dictionary<string, string>();

0 commit comments

Comments
 (0)