using System.Collections.Generic; using System.Threading.Tasks; using AutoMapper; using Datory; using GxPress.Common.AppOptions; using GxPress.Common.Page; using GxPress.Common.Tools; using GxPress.Repository.Interface.Teacher; using GxPress.Request.TeacherRequest; using Microsoft.Extensions.Options; using SqlKata; namespace GxPress.Repository.Implement.Teacher { public class TeacherRepository : ITeacherRepository { private readonly Repository _repository; private readonly IMapper _mapper; private readonly string _connectionString; private readonly string _databaseTypestr; public TeacherRepository(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 DeleteAsync(int id) { return await _repository.DeleteAsync(id); } public async Task> GetAllAsync(TeacherRequest request) { var result = new PagedList(); var query = Q.NewQuery(); result.Items = await _repository.GetAllAsync(query.ForPage(request.Page, request.PerPage)); result.Total = await _repository.CountAsync(query); return result; } public async Task> GetSearchAllAsync(TeacherRequest request) { var query = Q.NewQuery(); query.Where(Q.WhereLike(nameof(Entity.tede2.Teacher.Teacher.Name),$"%{request.KeyWord}%")); var result = await _repository.GetAllAsync(query); return result; } public async Task GetAsync(int id) { return await _repository.GetAsync(id); } public async Task InsertAsync(Entity.tede2.Teacher.Teacher note) { return await _repository.InsertAsync(note); } public async Task UpdateAsync(Entity.tede2.Teacher.Teacher note) { return await _repository.UpdateAsync(note); } public async Task UpdateAsync(Query query) { return await _repository.UpdateAsync(query) > 0; } } }