using System.Collections.Generic; using System.Threading.Tasks; using Datory; using GxPress.Common.AppOptions; using GxPress.Common.Tools; using GxPress.Entity.WorkCar; using GxPress.Repository.Interface.WorkCar; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Options; namespace GxPress.Repository.Implement.WorkCar { public class CarRepository : ICarRepository { private readonly Repository _repository; public CarRepository(IOptionsMonitor dbOptionsAccessor, IDistributedCache cache) { var databaseType = StringUtils.ToEnum(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql); var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString); _repository = new Repository(database, cache); } public IDatabase Database => _repository.Database; public string TableName => _repository.TableName; public List TableColumns => _repository.TableColumns; public async Task InsertAsync(Car item) { return await _repository.InsertAsync(item); } public async Task UpdateAsync(Car item) { await _repository.UpdateAsync(item); } public async Task GetAsync(int carId) { return await _repository.GetAsync(carId); } public async Task> GetListAsync(int typeId) { if (typeId > 0) { return await _repository.GetAllAsync(Q.Where(nameof(Car.TypeId), typeId).OrderByDesc(nameof(Car.Taxis))); } return await _repository.GetAllAsync(Q.OrderByDesc(nameof(Car.Taxis))); } public async Task DeleteAsync(int carId) { return await _repository.DeleteAsync(carId); } public async Task GetAvailableCarId(int typeId, IEnumerable orderedCarIds) { return await _repository.GetAsync(Q .Select(nameof(Car.Id)) .Where(nameof(Car.TypeId), typeId) .WhereNotIn(nameof(Car.Id), orderedCarIds) ); } } }