using System.Collections.Generic; using System.Threading.Tasks; using AutoMapper; using Datory; using GxPress.Common.AppOptions; using GxPress.Common.Tools; using GxPress.EnumConst; using GxPress.Repository.Interface.AppChannel; using GxPress.Result.AppChannel; using Microsoft.Extensions.Options; namespace GxPress.Repository.Implement.AppChannel { public class AppChannelRepository : IAppChannelRepository { private readonly Repository _repository; private readonly IMapper _mapper; public AppChannelRepository(IOptionsMonitor dbOptionsAccessor, IMapper mapper) { 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 GetAsync(int id) { var result = await _repository.GetAsync(id); if (result != null) result.ImageUrls = StringUtils.AddDomain(result.ImageUrls); return result; } /// /// 查询 /// /// public async Task> GetAllAsync(AppChannelConst channelTypeValue) { var result = await _repository.GetAllAsync(Q.Where(nameof(Entity.tede2.AppChannel.AppChannel.ChannelTypeValue), channelTypeValue).OrderBy(nameof(Entity.tede2.AppChannel.AppChannel.Sort))); foreach (var item in result) item.ImageUrls = StringUtils.AddDomain(item.ImageUrls); return result; } /// /// 删除 /// /// /// public async Task DeleteAsync(int id) { return await _repository.DeleteAsync(id); } /// /// 修改 /// /// /// public async Task UpdateAsync(Entity.tede2.AppChannel.AppChannel request) { var model = await _repository.GetAsync(request.Id); if (!string.IsNullOrEmpty(request.ImageUrls)) model.ImageUrls = StringUtils.RemoveDomain(request.ImageUrls); model.IsDisable = request.IsDisable; model.TypeValue = request.TypeValue; model.Name = request.Name; model.Sort = request.Sort; model.IsDisable = request.IsDisable; return await _repository.UpdateAsync(model); } /// /// 添加 /// /// /// public async Task InsertAsync(Entity.tede2.AppChannel.AppChannel model) { if (!string.IsNullOrEmpty(model.ImageUrls)) model.ImageUrls = StringUtils.RemoveDomain(model.ImageUrls); return await _repository.InsertAsync(model) > 0; } } }