Skip to content

Commit 67be326

Browse files
author
v-anzha
committed
continue to api
1 parent 8cb92c5 commit 67be326

File tree

6 files changed

+58
-21
lines changed

6 files changed

+58
-21
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,7 @@ ASALocalRun/
331331
.mfractor/
332332

333333
# Local History for Visual Studio
334-
.localhistory/
334+
.localhistory/
335+
336+
# wwwroot/images
337+
*images/

Blog.Core.Model/MessageModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ public class MessageModel<T>
1212
/// <summary>
1313
/// 操作是否成功
1414
/// </summary>
15-
public bool Success { get; set; }
15+
public bool Success { get; set; } = false;
1616
/// <summary>
1717
/// 返回信息
1818
/// </summary>
19-
public string Msg { get; set; }
19+
public string Msg { get; set; } = "服务器异常";
2020
/// <summary>
2121
/// 返回数据集合
2222
/// </summary>
23-
public List<T> Data { get; set; }
23+
public T Response { get; set; }
2424

2525
}
2626
}

Blog.Core.Model/Models/TopicDetail.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public TopicDetail()
2020
public int TopicId { get; set; }
2121

2222
[SugarColumn(Length = 200, IsNullable = true)]
23-
public string tdLogo { get; set; }
23+
public string tdLogo { get; set; }
2424

2525
[SugarColumn(Length = 200, IsNullable = true)]
2626
public string tdName { get; set; }
@@ -34,7 +34,7 @@ public TopicDetail()
3434
[SugarColumn(Length = 200, IsNullable = true)]
3535
public string tdSectendDetail { get; set; }
3636

37-
public bool tdIsDelete { get; set; }
37+
public bool tdIsDelete { get; set; } = false;
3838
public int tdRead { get; set; }
3939
public int tdCommend { get; set; }
4040
public int tdGood { get; set; }

Blog.Core/Blog.Core.Model.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Blog.Core/Controllers/ImgController.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Linq;
55
using System.Threading.Tasks;
6+
using Blog.Core.Model;
67
using Microsoft.AspNetCore.Hosting;
78
using Microsoft.AspNetCore.Http;
89
using Microsoft.AspNetCore.Mvc;
@@ -30,9 +31,9 @@ public string Get(int id)
3031

3132
[HttpPost]
3233
[Route("Pic")]
33-
public async Task<PicData> InsertPicture([FromServices]IHostingEnvironment environment)
34+
public async Task<MessageModel<string>> InsertPicture([FromServices]IHostingEnvironment environment)
3435
{
35-
var data = new PicData();
36+
var data = new MessageModel<string>();
3637
string path = string.Empty;
3738
string foldername = "images";
3839
var files = Request.Form.Files;
@@ -60,11 +61,11 @@ public async Task<PicData> InsertPicture([FromServices]IHostingEnvironment envir
6061
await file.CopyToAsync(stream);
6162
}
6263

63-
data = new PicData()
64+
data = new MessageModel<string>()
6465
{
65-
Url = strpath,
66+
Response = strpath,
6667
Msg = "上传成功",
67-
Suc = true,
68+
Success = true,
6869
};
6970
return data;
7071
}
@@ -101,10 +102,5 @@ public void Delete(int id)
101102
{
102103
}
103104
}
104-
public class PicData
105-
{
106-
public string Url { get; set; } = "";
107-
public string Msg { get; set; } = "上传失败";
108-
public bool Suc { get; set; } = false;
109-
}
105+
110106
}

Blog.Core/Controllers/TopicDetailController.cs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55
using Blog.Core.IServices;
6+
using Blog.Core.Model;
67
using Blog.Core.Model.Models;
78
using Microsoft.AspNetCore.Http;
89
using Microsoft.AspNetCore.Mvc;
@@ -50,15 +51,52 @@ public async Task<object> Get(int page = 1, string tname = "")
5051

5152
// GET: api/TopicDetail/5
5253
[HttpGet("{id}")]
53-
public string Get(int id)
54+
public async Task<MessageModel<TopicDetail>> Get(int id)
5455
{
55-
return "value";
56+
var data = new MessageModel<TopicDetail>();
57+
data.Response = await _topicDetailServices.QueryByID(id);
58+
if (data.Response != null)
59+
{
60+
data.Success = true;
61+
data.Msg = "";
62+
}
63+
64+
return data;
5665
}
5766

5867
// POST: api/TopicDetail
5968
[HttpPost]
60-
public void Post([FromBody] string value)
69+
public async Task<MessageModel<string>> Post([FromBody] TopicDetail topicDetail)
6170
{
71+
var data = new MessageModel<string>();
72+
73+
if (topicDetail != null && topicDetail.Id > 0)
74+
{
75+
data.Success = await _topicDetailServices.Update(topicDetail);
76+
if (data.Success)
77+
{
78+
data.Msg = "更新成功";
79+
data.Response = topicDetail?.Id.ObjToString();
80+
}
81+
}
82+
else
83+
{
84+
topicDetail.tdCreatetime = DateTime.Now;
85+
topicDetail.tdRead = 0;
86+
topicDetail.tdCommend = 0;
87+
topicDetail.tdGood = 0;
88+
topicDetail.tdTop = 0;
89+
90+
var id = (await _topicDetailServices.Add(topicDetail));
91+
data.Success = id > 0;
92+
if (data.Success)
93+
{
94+
data.Response = id.ObjToString();
95+
data.Msg = "添加成功";
96+
}
97+
}
98+
99+
return data;
62100
}
63101

64102
// PUT: api/TopicDetail/5

0 commit comments

Comments
 (0)