using System.Collections.Generic; using System.Threading.Tasks; using AutoMapper; using Datory; using GxPress.Common.AppOptions; using GxPress.Common.Tools; using GxPress.Repository.Interface.AppStartPage; using GxPress.Request.AppStartPage; using Microsoft.Extensions.Options; namespace GxPress.Repository.Implement.AppStartPage { public class AppStartPageRepository : IAppStartPageRepository { private readonly Repository _repository; private readonly IMapper _mapper; private readonly string _connectionString; private readonly string _databaseTypestr; public AppStartPageRepository(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; /// /// 获取 APP启动 1IOS 2Android /// /// /// public async Task GetAsync(int appTypeId) { return await _repository.GetAsync(Q.Where(nameof(Entity.tede2.AppStartPage.AppStartPage.AppTypeId), appTypeId).Where(nameof(Entity.tede2.AppStartPage.AppStartPage.IsDisable), false).OrderByDesc(nameof(Entity.tede2.AppStartPage.AppStartPage.CreatedDate))); } /// /// 查询 /// /// public async Task> GetAllAsync() { var result= await _repository.GetAllAsync(Q.OrderByDesc(nameof(Entity.tede2.AppStartPage.AppStartPage.CreatedDate))); foreach (var item in result) { item.ImageUrl=StringUtils.AddDomain(item.ImageUrl); } return result; } /// /// 删除 /// /// /// public async Task DeleteAsync(int id) { return await _repository.DeleteAsync(id); } /// /// 修改 /// /// /// public async Task UpdateAsync(AppStartPageUpdateRequest request) { var model = await _repository.GetAsync(request.Id); if (!string.IsNullOrEmpty(request.ImageUrl)) model.ImageUrl = StringUtils.RemoveDomain(request.ImageUrl); if (request.IsDisable > 0) model.IsDisable = request.IsDisable == 1; if (request.Second > 0) model.Second = request.Second; if (!string.IsNullOrEmpty(request.Title)) model.Title = request.Title; if (request.TypeId > 0) model.TypeId = request.TypeId; if (!string.IsNullOrEmpty(request.Url)) model.Url = request.Url; if (request.AdminId > 0) model.AdminId = request.AdminId; if (request.AppTypeId > 0) model.AppTypeId = request.AppTypeId; if (!string.IsNullOrEmpty(request.Creator)) model.Creator = request.Creator; if (request.DataId > 0) model.DataId = request.DataId; if (request.DataTypeId > 0) model.DataTypeId = request.DataTypeId; return await _repository.UpdateAsync(model); } /// /// 添加 /// /// /// public async Task InsertAsync(Entity.tede2.AppStartPage.AppStartPage model) { return await _repository.InsertAsync(model) > 0; } } }