using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; using System.Threading.Tasks; using Abp.Application.Services.Dto; using Abp.Authorization; using Abp.Domain.Repositories; using Abp.Extensions; using IwbZero.AppServiceBase; using IwbZero.IdentityFramework; using ShwasherSys.Authorization.Permissions; using ShwasherSys.BaseSysInfo; using ShwasherSys.BaseSysInfo.Functions.Dto; using ShwasherSys.BasicInfo.Region.Dto; using ShwasherSys.Lambda; namespace ShwasherSys.BasicInfo.Region { [AbpAuthorize] public class RegionsAppService : ShwasherAsyncCrudAppService, IRegionsAppService { public RegionsAppService(IRepository repository) : base(repository) { } protected override string GetPermissionName { get; set; } = PermissionNames.PagesBasicInfoRegions; protected override string GetAllPermissionName { get; set; } = PermissionNames.PagesBasicInfoRegions; protected override string CreatePermissionName { get; set; } = PermissionNames.PagesBasicInfoRegionsCreate; protected override string UpdatePermissionName { get; set; } = PermissionNames.PagesBasicInfoRegionsUpdate; protected override string DeletePermissionName { get; set; } = PermissionNames.PagesBasicInfoRegionsDelete; public override async Task Create(RegionCreateDto input) { CheckCreatePermission(); var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id); if (entity!=null) { CheckErrors(IwbIdentityResult.Failed("此编号已经被使用!请更换其它编号!")); } var loFather =await Repository.GetAsync(input.FatherRegionID); loFather.IsLeaf = "N"; input.FatherRegionID = loFather.Id; input.Depth = loFather.Depth + 1; input.IsLeaf = "Y"; input.Path = loFather.Path + input.Id+","; input.Sort = input.Sort; await Repository.UpdateAsync(loFather); return await CreateEntity(input); } public override async Task Delete(EntityDto input) { CheckDeletePermission(); var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id); if ((await Repository.GetAllListAsync(a => a.FatherRegionID == entity.Id&&a.IsLock=="N")).Any()) { CheckErrors(IwbIdentityResult.Failed("此菜单下还有子区域,不能删除")); } entity.IsLock = "Y"; await Repository.UpdateAsync(entity); await CurrentUnitOfWork.SaveChangesAsync(); } public async Task GetRegionSelectStrs() { var options = ""; var list = await Repository.GetAllListAsync(a => a.IsLock == "N"); foreach (var l in list) { string parent = l.FatherRegionID == "0" ? "" : $" parent=\"{l.FatherRegionID}\""; options += $"\r\n"; } return options; } /*public override async Task> GetAll(PagedRequestDto input) { CheckGetAllPermission(); var query = CreateFilteredQuery(input).Where(a => a.IsLock == "N"); if (input.SearchList != null && input.SearchList.Count > 0) { List objList = new List(); foreach (var o in input.SearchList) { if (o.KeyWords.IsNullOrEmpty()) continue; object keyWords = o.KeyWords; objList.Add(new LambdaObject { FieldType = (LambdaFieldType)o.FieldType, FieldName = o.KeyField, FieldValue = keyWords, ExpType = (LambdaExpType)o.ExpType }); } var exp = objList.GetExp(); query = query.Where(exp); } var totalCount = await AsyncQueryableExecuter.CountAsync(query); query = ApplySorting(query, input); query = ApplyPaging(query, input); var entities = await AsyncQueryableExecuter.ToListAsync(query); var dtos = new PagedResultDto( totalCount, ObjectMapper.Map>(entities) ); return dtos; }*/ } }