using System.Collections.Generic;
using System.Threading.Tasks;
using GxPress.Auth;
using GxPress.EnumConst;
using GxPress.Repository.Interface.TrackLog;
using GxPress.Repository.Interface.VipEquity;
using GxPress.Request.VipEquity;
using GxPress.Result.VipEquity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using GxPress.Common.Tools;
namespace GxPress.Api.AdminControllers
{
///
/// VIP权益
///
[Route("api/admin/vip-equity")]
[ApiController]
[Authorize]
public class AdminVipEquityController : Controller
{
private readonly IVipEquityRepository vipEquityRepository;
private readonly ILoginContext _loginContext;
private readonly IHttpContextAccessor httpContextAccessor;
private readonly ITrackLogRepository trackLogRepository;
public AdminVipEquityController(IVipEquityRepository vipEquityRepository, ILoginContext _loginContext, IHttpContextAccessor httpContextAccessor, ITrackLogRepository trackLogRepository)
{
this.vipEquityRepository = vipEquityRepository;
this._loginContext = _loginContext;
this.httpContextAccessor = httpContextAccessor;
this.trackLogRepository = trackLogRepository;
}
///
/// 获取列表
///
///
[HttpGet]
public async Task> GetAllAsync()
{
return await vipEquityRepository.GetAllAsync();
}
///
/// 修改
///
///
///
[HttpPut]
public async Task UpdateAsync(VipEquityUpdateRequest request)
{
var success = await vipEquityRepository.UpdateAsync(request);
if (success)
{
var vipEquity = await vipEquityRepository.GetAsync(request.Id);
var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
var remark = $"修改Vip权益:{((VipCardTypeConst)vipEquity.VipType).GetDescriptionOriginal()}";
await trackLogRepository.InsertAsync(_loginContext.Name, _loginContext.AccountId, ip, remark);
}
return success;
}
///
/// 添加
///
///
///
[HttpPost]
public async Task InsertAsync(Entity.tede2.VipEquity.VipEquity model)
{
var success = await vipEquityRepository.InsertAsync(model);
if (success)
{
var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
var remark = $"添加Vip权益:{((VipCardTypeConst)model.VipType).GetDescriptionOriginal()}";
await trackLogRepository.InsertAsync(_loginContext.Name, _loginContext.AccountId, ip, remark);
}
return success;
}
///
/// 根据ID删除
///
///
///
[HttpDelete("{id}")]
public async Task DeleteAsync(int id)
{
var vipEquity = await vipEquityRepository.GetAsync(id);
var success = await vipEquityRepository.DeleteAsync(id);
if (success)
{
var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
var remark = $"删除Vip权益:{((VipCardTypeConst)vipEquity.VipType).GetDescriptionOriginal()}";
await trackLogRepository.InsertAsync(_loginContext.Name, _loginContext.AccountId, ip, remark);
}
return success;
}
}
}