using System.Collections.Generic; using System.Threading.Tasks; using AutoMapper; using Datory; using GxPress.Common.AppOptions; using GxPress.Common.Tools; using GxPress.Repository.Interface.Navigation; using GxPress.Request.Navigation; using Microsoft.Extensions.Options; namespace GxPress.Repository.Implement.Navigation { public class MiddleLableRepository : IMiddleLableRepository { private readonly Repository _repository; private readonly IMapper _mapper; private readonly string _connectionString; private readonly string _databaseTypestr; public MiddleLableRepository(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 GetAsync(int id) { return await _repository.GetAsync(id); } public async Task GetAsync(string name) { return await _repository.GetAsync(Q.Where(nameof(Entity.Navigations.MiddleLable.Name), name)); } public async Task DeleteAsync(int id) { return await _repository.DeleteAsync(id); } public async Task InsertAsync(Entity.Navigations.MiddleLable note) { return await _repository.InsertAsync(note); } public async Task UpdateAsync(MiddleLableUpRequest request) { if (request.Id > 0) { var model = await GetAsync(request.Id); if (request.IsDisable > 0) model.IsDisable = request.IsDisable == 1; if (!string.IsNullOrEmpty(request.Name)) model.Name = request.Name; if (request.Sort > 0) model.Sort = request.Sort; if (request.IsSearch > 0) model.IsSearch = request.IsSearch == 1; if (request.IsSlide > 0) model.IsSlide = request.IsSlide == 1; if (request.TypeId > 0) model.TypeId = request.TypeId; return await _repository.UpdateAsync(model); } return false; } public async Task UpdateAsync(SqlKata.Query query) { return await _repository.UpdateAsync(query) > 0; } public async Task> GetAllAsync() { return await _repository.GetAllAsync(Q.Where(nameof(Entity.Navigations.MiddleLable.IsDisable), false).OrderByDesc(nameof(Entity.Navigations.MiddleLable.Sort))); } } }