using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using AutoMapper; using GxPress.Common.AppOptions; using GxPress.Common.Exceptions; using GxPress.Common.Tools; using GxPress.Entity; using GxPress.Repository.Interface; using GxPress.Request.App.GroupFolder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Options; using Datory; namespace GxPress.Repository.Implement { public class GroupFolderRepository:IGroupFolderRepository { private readonly Repository _repository; private readonly IMapper _mapper; private readonly IWebHostEnvironment _environment; public GroupFolderRepository(IOptionsMonitor dbOptionsAccessor, IMapper mapper, IWebHostEnvironment environment) { var databaseType = StringUtils.ToEnum(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql); var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString); _repository = new Repository(database); _environment = environment; _mapper = mapper; } public IDatabase Database => _repository.Database; public string TableName => _repository.TableName; public List TableColumns => _repository.TableColumns; /// /// 添加小组文件夹 /// /// /// public async Task InsertAsync(GroupFolderInRequest request) { if (string.IsNullOrEmpty(request.Name)) throw new BusinessException("文件夹名称不能为空"); if (request.ParentId < 0) throw new BusinessException("参数错误"); if (request.UserId <= 0) throw new BusinessException("参数错误"); var groupFolder = new GroupFolder { Name = request.Name, ParentId = request.ParentId, UserId = request.UserId }; return await _repository.InsertAsync(groupFolder) > 0; } /// /// 修改文件夹 /// /// /// public async Task UpdateAsync(GroupFolderUpRequest request) { var groupFolder = await _repository.GetAsync(request.Id); if (!string.IsNullOrEmpty(request.Name)) groupFolder.Name = request.Name; return await _repository.UpdateAsync(groupFolder); } /// /// 删除文件 /// /// /// public async Task DeleteAsync(int id) { return await _repository.DeleteAsync(id); } /// /// /// /// /// public async Task> FindGroupFoldersAsync(GroupFolderFindRequest request) { return await _repository.GetAllAsync(Q.Where(nameof(GroupFolder.ParentId), request.GroupFolderId) .Where(nameof(GroupFolder.UserId), request.UserId)); } } }