NewGaoKaoApi/New_College.Services/Test_CycleTimeInfoServices.cs

59 lines
2.2 KiB
C#

using New_College.IServices;
using New_College.Model.Models;
using New_College.Services.BASE;
using New_College.IRepository.Base;
using New_College.IRepository;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace New_College.Services
{
public class Test_CycleTimeInfoServices : BaseServices<Test_CycleTimeInfo>, ITest_CycleTimeInfoServices
{
private readonly IBaseRepository<Test_CycleTimeInfo> _dal;
private readonly IV_VipCardTypeRepository v_VipCardTypeRepository;
private readonly ITest_CategoryInfoRepository test_CategoryInfoRepository;
public Test_CycleTimeInfoServices(IBaseRepository<Test_CycleTimeInfo> dal
, IV_VipCardTypeRepository IV_VipCardTypeRepository
, ITest_CategoryInfoRepository ITest_CategoryInfoRepository)
{
this._dal = dal;
v_VipCardTypeRepository = IV_VipCardTypeRepository;
test_CategoryInfoRepository = ITest_CategoryInfoRepository;
base.BaseDal = dal;
}
/// <summary>
/// 生成周期
/// </summary>
/// <returns></returns>
public async Task<bool> AutoCycleTime()
{
var cardtype = await v_VipCardTypeRepository.Query(x => x.IsDelete == false);
var category = await test_CategoryInfoRepository.Query(x => x.IsDelete == false && x.CreateId == 999);
List<Test_CycleTimeInfo> list = new List<Test_CycleTimeInfo>() { };
foreach (var item in cardtype)
{
var num = item.OrderSort;
foreach (var items in category)
{
for (int i = 1; i <= num; i++)
{
var cyclename = "第" + i + "次";
list.Add(new Test_CycleTimeInfo()
{
CategoryId = items.Id,
CycleName = cyclename,
IsOpen = 1,
VipCardTypeId = item.Id,
OrderSort = i
});
}
}
}
var result = await _dal.Add(list);
return result > 0 ? true : false;
}
}
}