mirror of
https://github.com/anjoy8/Blog.Core.git
synced 2024-09-20 23:48:27 +08:00
continue to api
This commit is contained in:
parent
8cb92c578e
commit
67be326ef4
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -331,4 +331,7 @@ ASALocalRun/
|
|||
.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
.localhistory/
|
||||
.localhistory/
|
||||
|
||||
# wwwroot/images
|
||||
*images/
|
|
@ -12,15 +12,15 @@ namespace Blog.Core.Model
|
|||
/// <summary>
|
||||
/// 操作是否成功
|
||||
/// </summary>
|
||||
public bool Success { get; set; }
|
||||
public bool Success { get; set; } = false;
|
||||
/// <summary>
|
||||
/// 返回信息
|
||||
/// </summary>
|
||||
public string Msg { get; set; }
|
||||
public string Msg { get; set; } = "服务器异常";
|
||||
/// <summary>
|
||||
/// 返回数据集合
|
||||
/// </summary>
|
||||
public List<T> Data { get; set; }
|
||||
public T Response { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace Blog.Core.Model.Models
|
|||
public int TopicId { get; set; }
|
||||
|
||||
[SugarColumn(Length = 200, IsNullable = true)]
|
||||
public string tdLogo { get; set; }
|
||||
public string tdLogo { get; set; }
|
||||
|
||||
[SugarColumn(Length = 200, IsNullable = true)]
|
||||
public string tdName { get; set; }
|
||||
|
@ -34,7 +34,7 @@ namespace Blog.Core.Model.Models
|
|||
[SugarColumn(Length = 200, IsNullable = true)]
|
||||
public string tdSectendDetail { get; set; }
|
||||
|
||||
public bool tdIsDelete { get; set; }
|
||||
public bool tdIsDelete { get; set; } = false;
|
||||
public int tdRead { get; set; }
|
||||
public int tdCommend { get; set; }
|
||||
public int tdGood { get; set; }
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
返回信息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Blog.Core.Model.MessageModel`1.Data">
|
||||
<member name="P:Blog.Core.Model.MessageModel`1.Response">
|
||||
<summary>
|
||||
返回数据集合
|
||||
</summary>
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Blog.Core.Model;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -30,9 +31,9 @@ namespace Blog.Core.Controllers
|
|||
|
||||
[HttpPost]
|
||||
[Route("Pic")]
|
||||
public async Task<PicData> InsertPicture([FromServices]IHostingEnvironment environment)
|
||||
public async Task<MessageModel<string>> InsertPicture([FromServices]IHostingEnvironment environment)
|
||||
{
|
||||
var data = new PicData();
|
||||
var data = new MessageModel<string>();
|
||||
string path = string.Empty;
|
||||
string foldername = "images";
|
||||
var files = Request.Form.Files;
|
||||
|
@ -60,11 +61,11 @@ namespace Blog.Core.Controllers
|
|||
await file.CopyToAsync(stream);
|
||||
}
|
||||
|
||||
data = new PicData()
|
||||
data = new MessageModel<string>()
|
||||
{
|
||||
Url = strpath,
|
||||
Response = strpath,
|
||||
Msg = "上传成功",
|
||||
Suc = true,
|
||||
Success = true,
|
||||
};
|
||||
return data;
|
||||
}
|
||||
|
@ -101,10 +102,5 @@ namespace Blog.Core.Controllers
|
|||
{
|
||||
}
|
||||
}
|
||||
public class PicData
|
||||
{
|
||||
public string Url { get; set; } = "";
|
||||
public string Msg { get; set; } = "上传失败";
|
||||
public bool Suc { get; set; } = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Blog.Core.IServices;
|
||||
using Blog.Core.Model;
|
||||
using Blog.Core.Model.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -50,15 +51,52 @@ namespace Blog.Core.Controllers
|
|||
|
||||
// GET: api/TopicDetail/5
|
||||
[HttpGet("{id}")]
|
||||
public string Get(int id)
|
||||
public async Task<MessageModel<TopicDetail>> Get(int id)
|
||||
{
|
||||
return "value";
|
||||
var data = new MessageModel<TopicDetail>();
|
||||
data.Response = await _topicDetailServices.QueryByID(id);
|
||||
if (data.Response != null)
|
||||
{
|
||||
data.Success = true;
|
||||
data.Msg = "";
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// POST: api/TopicDetail
|
||||
[HttpPost]
|
||||
public void Post([FromBody] string value)
|
||||
public async Task<MessageModel<string>> Post([FromBody] TopicDetail topicDetail)
|
||||
{
|
||||
var data = new MessageModel<string>();
|
||||
|
||||
if (topicDetail != null && topicDetail.Id > 0)
|
||||
{
|
||||
data.Success = await _topicDetailServices.Update(topicDetail);
|
||||
if (data.Success)
|
||||
{
|
||||
data.Msg = "更新成功";
|
||||
data.Response = topicDetail?.Id.ObjToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
topicDetail.tdCreatetime = DateTime.Now;
|
||||
topicDetail.tdRead = 0;
|
||||
topicDetail.tdCommend = 0;
|
||||
topicDetail.tdGood = 0;
|
||||
topicDetail.tdTop = 0;
|
||||
|
||||
var id = (await _topicDetailServices.Add(topicDetail));
|
||||
data.Success = id > 0;
|
||||
if (data.Success)
|
||||
{
|
||||
data.Response = id.ObjToString();
|
||||
data.Msg = "添加成功";
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// PUT: api/TopicDetail/5
|
||||
|
|
Loading…
Reference in New Issue
Block a user