public async Task <Unit> Handle(MapPatchCommand request, CancellationToken cancellationToken) { var canOperate = await clientAssetPermissionControlService.CanEditClientAsset(); if (!canOperate) { throw new HttpForbiddenException(); } var map = await mapRepository.FindAsync(request.Id); if (map == null) { throw new HttpResourceNotFoundException(commonLocalizer["HttpRespond.NotFound", "Map", request.Id]); } mapper.Map(map, request); request.ApplyPatch(); var modifier = identityService.GetUserId(); map.UpdateBasicInfo(request.Name, modifier); await mapRepository.UpdateAsync(map); return(Unit.Value); }
public async Task <MapIdentityQueryDTO> Handle(MapIdentityQuery request, CancellationToken cancellationToken) { var map = await mapRepository.FindAsync(request.Id); if (map == null) { throw new HttpResourceNotFoundException(commonLocalizer["HttpRespond.NotFound", "Map", request.Id]); } return(MapIdentityQueryDTO.From(map)); }
public async Task <ObjectResult> Handle(MapBatchDeleteCommand request, CancellationToken cancellationToken) { var canOperate = await clientAssetPermissionControlService.CanEditClientAsset(); if (!canOperate) { throw new HttpForbiddenException(); } var result = new MultiStatusObjectResult(); var operatorId = identityService.GetUserId(); var resourcePartUri = uriService.GetUriWithoutQuery().URIUpperLevel(); var idArr = request.Ids.Split(",", StringSplitOptions.RemoveEmptyEntries); for (int i = 0, len = idArr.Count(); i < len; i++) { var id = idArr[i]; var uri = $"{resourcePartUri}/{id}"; var data = await mapRepository.FindAsync(id); if (data == null) { result.AddResult(uri, 404, ""); continue; } //var query = await userManagedAccountService.GetManagedAccounts(operatorId); //var canOperat = await query.AnyAsync(x => x.Id == accountId); //if (!canOperat) //{ // result.AddResult(uri, 403, localizer["OperateForbidden"]); // continue; //} await mapRepository.DeleteAsync(data, operatorId); result.AddResult(uri, 200, ""); } return(result.Transfer()); }
/// <inheritdoc /> Task <Map> IRepository <int, Map> .FindAsync(int identifier) { IMapRepository self = this; return(self.FindAsync(identifier, CancellationToken.None)); }