using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using AutoMapper; using Datory; using GxPress.Common.AppOptions; using GxPress.Common.Tools; using GxPress.Repository.Interface.VipEquity; using GxPress.Request.VipEquity; using GxPress.Result.VipEquity; using Microsoft.Extensions.Options; namespace GxPress.Repository.Implement.VipEquity { public class VipEquityRepository : IVipEquityRepository { private readonly Repository _repository; private readonly IMapper _mapper; private readonly string _connectionString; private readonly string _databaseTypestr; public VipEquityRepository(IOptionsMonitor dbOptionsAccessor, IMapper mapper) { _databaseTypestr = dbOptionsAccessor.CurrentValue.DatabaseType; _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString; var databaseType = StringUtils.ToEnum(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql); var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString); _repository = new Repository(database); _mapper = mapper; } public IDatabase Database => _repository.Database; public string TableName => _repository.TableName; public List TableColumns => _repository.TableColumns; public async Task> GetAllAsync() { var result = await _repository.GetAllAsync(Q.OrderByDesc(nameof(Entity.tede2.VipEquity.VipEquity.CreatedDate))); var items = result.Select(n => _mapper.Map(n)).ToList(); foreach (var item in items) { item.VipTypeValue = ((GxPress.EnumConst.VipCardTypeConst)item.VipType).GetDescriptionOriginal(); } return items; } public async Task UpdateAsync(VipEquityUpdateRequest request) { var model = await _repository.GetAsync(request.Id); if (request.IosPrice > 0) model.IosPrice = request.IosPrice; if (request.OtherPrice > 0) model.OtherPrice = request.OtherPrice; if (request.VipType > 0) model.VipType = request.VipType; return await _repository.UpdateAsync(model); } public async Task InsertAsync(Entity.tede2.VipEquity.VipEquity model) { return await _repository.InsertAsync(model) > 0; } /// /// 根据Id删除 /// /// /// public async Task DeleteAsync(int id) { return await _repository.DeleteAsync(id); } /// /// 查询 /// /// /// public async Task GetAsync(int id) { return await _repository.GetAsync(id); } /// /// 查询1 月 2 季度 3 年 4连续月 /// /// /// public async Task GetByVipTypeAsync(int vipType) { return await _repository.GetAsync(Q.Where(nameof(Entity.tede2.VipEquity.VipEquity.VipType),vipType)); } } }