using Masuit.MyBlogs.Core.Infrastructure.Services.Interface;
using Masuit.MyBlogs.Core.Models.Entity;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;
namespace Masuit.MyBlogs.Core.Controllers
{
///
/// 快速分享
///
public class ShareController : AdminController
{
///
/// 快速分享
///
public IFastShareService FastShareService { get; set; }
///
/// 快速分享
///
///
public ActionResult Index()
{
var shares = FastShareService.GetAll(s => s.Sort).ToList();
return ResultData(shares);
}
///
/// 添加快速分享
///
///
///
[HttpPost]
public ActionResult Add(FastShare share)
{
bool b = FastShareService.AddEntitySaved(share) != null;
return ResultData(null, b, b ? "添加成功" : "添加失败");
}
///
/// 移除快速分享
///
///
///
[HttpPost]
public async Task Remove(int id)
{
bool b = await FastShareService.DeleteByIdSavedAsync(id) > 0;
return ResultData(null, b, b ? "删除成功" : "删除失败");
}
///
/// 更新快速分享
///
///
///
[HttpPost]
public async Task Update(FastShare model)
{
var b = await FastShareService.GetQuery(s => s.Id == model.Id).UpdateFromQueryAsync(s => new FastShare()
{
Title = model.Title,
Link = model.Link,
Sort = model.Sort
}) > 0;
return ResultData(null, b, b ? "更新成功" : "更新失败");
}
}
}