/// <summary> /// 删除 /// </summary> /// <param name="id">部门id</param> /// <returns></returns> public async Task RemoveBranch(Guid id) { using BranchService branchService = new BranchService(); if (await branchService.GetAllAsync().AnyAsync(i => i.Id == id)) { var branch = branchService.GetAllAsync().FirstOrDefault(i => i.Id == id); if (branch != null) { await branchService.RemoveAsync(branch); } } }
/// <summary> /// 修改 /// </summary> /// <param name="id">部门id</param> /// <param name="branchName">部门名称</param> /// <returns></returns> public async Task EditBranch(Guid id, string branchName) { using BranchService branchService = new BranchService(); if (await branchService.GetAllAsync().AnyAsync(i => i.Id == id)) { var branch = branchService.GetAllAsync().FirstOrDefault(i => i.Id == id); if (branch != null) { branch.BranchName = branchName; } await branchService.EditAsync(branch); } }
// private readonly IBranchService _branchService; // /// <summary> // /// 重写实现 // /// </summary> // /// <param name="branchService"></param> // public BranchManage(IBranchService branchService) // { // _branchService = branchService; // } public async Task <List <BranchDto> > GetAllBranch() { using BranchService branchService = new BranchService(); return(await branchService.GetAllAsync().Select(i => new BranchDto() { BranchId = i.Id, BranchName = i.BranchName }).ToListAsync()); }