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 Microsoft.Extensions.Options; using System.Transactions; using GxPress.Request.Navigation; namespace GxPress.Repository.Implement.Navigation { public class MiddleLableNexusRepository : IMiddleLableNexusRepository { private readonly Repository _repository; private readonly IMapper _mapper; public MiddleLableNexusRepository(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 InsertAsync(List middleLableNexusUpRequests) { try { using (var transactionScope = new TransactionScope()) { foreach (var item in middleLableNexusUpRequests) { await _repository.InsertAsync(_mapper.Map(item)); } transactionScope.Complete(); } } catch { return false; } return true; } /// /// 查询 /// /// /// public async Task> GetAllTaskAsync(int middleLableId) { var query = Q.NewQuery(); query.Where(nameof(Entity.Navigations.MiddleLableNexus.MiddleLableId), middleLableId); query.OrderByDesc(nameof(Entity.Navigations.MiddleLableNexus.Sort)); return await _repository.GetAllAsync(query); } public async Task DeleteByMiddleLableIdAsync(int middleLableId) { return await _repository.DeleteAsync(Q.Where(nameof(Entity.Navigations.MiddleLableNexus.MiddleLableId), middleLableId)) > 0; } public async Task UpdateAsync(int middleLableId, List middleLableNexusUpRequests) { try { await DeleteByMiddleLableIdAsync(middleLableId); await InsertAsync(middleLableNexusUpRequests); } catch { return false; } return true; } } }