|
@@ -0,0 +1,56 @@
|
|
|
+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<Entity.tede2.VipEquity.VipEquity> _repository;
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+ private readonly string _connectionString;
|
|
|
+ private readonly string _databaseTypestr;
|
|
|
+ public VipEquityRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
|
|
|
+ {
|
|
|
+ _databaseTypestr = dbOptionsAccessor.CurrentValue.DatabaseType;
|
|
|
+ _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
|
|
|
+ var databaseType = StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
|
|
|
+ var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
|
|
|
+ _repository = new Repository<Entity.tede2.VipEquity.VipEquity>(database);
|
|
|
+ _mapper = mapper;
|
|
|
+ }
|
|
|
+ public IDatabase Database => _repository.Database;
|
|
|
+ public string TableName => _repository.TableName;
|
|
|
+ public List<TableColumn> TableColumns => _repository.TableColumns;
|
|
|
+
|
|
|
+ public async Task<IEnumerable<VipEquityResult>> GetAllAsync()
|
|
|
+ {
|
|
|
+ var result = await _repository.GetAllAsync(Q.OrderByDesc(nameof(Entity.tede2.VipEquity.VipEquity.CreatedDate)));
|
|
|
+ return result.Select(n => _mapper.Map<VipEquityResult>(n));
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<bool> 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<bool> InsertAsync(Entity.tede2.VipEquity.VipEquity model)
|
|
|
+ {
|
|
|
+ return await _repository.InsertAsync(model) > 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|