AdminVipEquityController.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using GxPress.Auth;
  4. using GxPress.EnumConst;
  5. using GxPress.Repository.Interface.TrackLog;
  6. using GxPress.Repository.Interface.VipEquity;
  7. using GxPress.Request.VipEquity;
  8. using GxPress.Result.VipEquity;
  9. using Microsoft.AspNetCore.Authorization;
  10. using Microsoft.AspNetCore.Http;
  11. using Microsoft.AspNetCore.Mvc;
  12. using GxPress.Common.Tools;
  13. namespace GxPress.Api.AdminControllers
  14. {
  15. /// <summary>
  16. /// VIP权益
  17. /// </summary>
  18. [Route("api/admin/vip-equity")]
  19. [ApiController]
  20. [Authorize]
  21. public class AdminVipEquityController : Controller
  22. {
  23. private readonly IVipEquityRepository vipEquityRepository;
  24. private readonly ILoginContext _loginContext;
  25. private readonly IHttpContextAccessor httpContextAccessor;
  26. private readonly ITrackLogRepository trackLogRepository;
  27. public AdminVipEquityController(IVipEquityRepository vipEquityRepository, ILoginContext _loginContext, IHttpContextAccessor httpContextAccessor, ITrackLogRepository trackLogRepository)
  28. {
  29. this.vipEquityRepository = vipEquityRepository;
  30. this._loginContext = _loginContext;
  31. this.httpContextAccessor = httpContextAccessor;
  32. this.trackLogRepository = trackLogRepository;
  33. }
  34. /// <summary>
  35. /// 获取列表
  36. /// </summary>
  37. /// <returns></returns>
  38. [HttpGet]
  39. public async Task<IEnumerable<VipEquityResult>> GetAllAsync()
  40. {
  41. return await vipEquityRepository.GetAllAsync();
  42. }
  43. /// <summary>
  44. /// 修改
  45. /// </summary>
  46. /// <param name="request"></param>
  47. /// <returns></returns>
  48. [HttpPut]
  49. public async Task<bool> UpdateAsync(VipEquityUpdateRequest request)
  50. {
  51. var success = await vipEquityRepository.UpdateAsync(request);
  52. if (success)
  53. {
  54. var vipEquity = await vipEquityRepository.GetAsync(request.Id);
  55. var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
  56. var remark = $"修改Vip权益:{((VipCardTypeConst)vipEquity.VipType).GetDescriptionOriginal()}";
  57. await trackLogRepository.InsertAsync(_loginContext.Name, _loginContext.AccountId, ip, remark);
  58. }
  59. return success;
  60. }
  61. /// <summary>
  62. /// 添加
  63. /// </summary>
  64. /// <param name="model"></param>
  65. /// <returns></returns>
  66. [HttpPost]
  67. public async Task<bool> InsertAsync(Entity.tede2.VipEquity.VipEquity model)
  68. {
  69. var success = await vipEquityRepository.InsertAsync(model);
  70. if (success)
  71. {
  72. var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
  73. var remark = $"添加Vip权益:{((VipCardTypeConst)model.VipType).GetDescriptionOriginal()}";
  74. await trackLogRepository.InsertAsync(_loginContext.Name, _loginContext.AccountId, ip, remark);
  75. }
  76. return success;
  77. }
  78. /// <summary>
  79. /// 根据ID删除
  80. /// </summary>
  81. /// <param name="id"></param>
  82. /// <returns></returns>
  83. [HttpDelete("{id}")]
  84. public async Task<bool> DeleteAsync(int id)
  85. {
  86. var vipEquity = await vipEquityRepository.GetAsync(id);
  87. var success = await vipEquityRepository.DeleteAsync(id);
  88. if (success)
  89. {
  90. var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
  91. var remark = $"删除Vip权益:{((VipCardTypeConst)vipEquity.VipType).GetDescriptionOriginal()}";
  92. await trackLogRepository.InsertAsync(_loginContext.Name, _loginContext.AccountId, ip, remark);
  93. }
  94. return success;
  95. }
  96. }
  97. }