ShareController.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Masuit.MyBlogs.Core.Infrastructure.Services.Interface;
  2. using Masuit.MyBlogs.Core.Models.Entity;
  3. using Microsoft.AspNetCore.Mvc;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. namespace Masuit.MyBlogs.Core.Controllers
  7. {
  8. /// <summary>
  9. /// 快速分享
  10. /// </summary>
  11. public class ShareController : AdminController
  12. {
  13. /// <summary>
  14. /// 快速分享
  15. /// </summary>
  16. public IFastShareService FastShareService { get; set; }
  17. /// <summary>
  18. /// 快速分享
  19. /// </summary>
  20. /// <returns></returns>
  21. public ActionResult Index()
  22. {
  23. var shares = FastShareService.GetAll(s => s.Sort).ToList();
  24. return ResultData(shares);
  25. }
  26. /// <summary>
  27. /// 添加快速分享
  28. /// </summary>
  29. /// <param name="share"></param>
  30. /// <returns></returns>
  31. [HttpPost]
  32. public ActionResult Add(FastShare share)
  33. {
  34. bool b = FastShareService.AddEntitySaved(share) != null;
  35. return ResultData(null, b, b ? "添加成功" : "添加失败");
  36. }
  37. /// <summary>
  38. /// 移除快速分享
  39. /// </summary>
  40. /// <param name="id"></param>
  41. /// <returns></returns>
  42. [HttpPost]
  43. public async Task<ActionResult> Remove(int id)
  44. {
  45. bool b = await FastShareService.DeleteByIdSavedAsync(id) > 0;
  46. return ResultData(null, b, b ? "删除成功" : "删除失败");
  47. }
  48. /// <summary>
  49. /// 更新快速分享
  50. /// </summary>
  51. /// <param name="model"></param>
  52. /// <returns></returns>
  53. [HttpPost]
  54. public async Task<ActionResult> Update(FastShare model)
  55. {
  56. var b = await FastShareService.GetQuery(s => s.Id == model.Id).UpdateFromQueryAsync(s => new FastShare()
  57. {
  58. Title = model.Title,
  59. Link = model.Link,
  60. Sort = model.Sort
  61. }) > 0;
  62. return ResultData(null, b, b ? "更新成功" : "更新失败");
  63. }
  64. }
  65. }