using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MS.Services.membershipGroup;
using MS.Services.PosTrxService;
using MS.WebApi.stockdbModels;
using MS.WebApi.waynedbModels;
using MS.WebCore.Core;
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace MS.WebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class MiniProgramPaymentCancelController : ControllerBase
    {
        private readonly IMiniProgramPaymentCancelService _miniProgramPaymentCancelService;
        private readonly stockdbContext _context;
        private readonly waynedbContext _waynedbContext;
        public MiniProgramPaymentCancelController(IMiniProgramPaymentCancelService miniProgramPaymentCancelService, waynedbContext waynedbContext)
        {
            _miniProgramPaymentCancelService = miniProgramPaymentCancelService;
            _waynedbContext = waynedbContext;
        }
        [Route("CancelADeal")]
        [EnableCors("AllowSpecificOrigin")]
        [HttpPost]
        public async Task<ExecuteResult> CancelADealAsync(string startTime)
        {
            return await _miniProgramPaymentCancelService.CancelADealAsync(startTime);
        }
        [Route("ValidateUserCouponExpiredState")]
        [EnableCors("AllowSpecificOrigin")]
        [HttpPost]
        public async Task<ExecuteResult> ValidateUserCouponExpiredStateAsync()
        {
          var list = await _waynedbContext.MUserCoupons.Where(a => a.Status  == 1 && a.ValidateEnd <= DateTime.Now).ToListAsync();
            list.ForEach(_ => _.Status = 2);
            _waynedbContext.SaveChanges();
            return null;
        }
    }
}
