public async Task <Unit> Handle(TexturePatchCommand request, CancellationToken cancellationToken) { var canOperate = await clientAssetPermissionControlService.CanEditClientAsset(); if (!canOperate) { throw new HttpForbiddenException(); } var texture = await textureRepository.FindAsync(request.Id); if (texture == null) { throw new HttpResourceNotFoundException(commonLocalizer["HttpRespond.NotFound", "Texture", request.Id]); } mapper.Map(texture, request); request.ApplyPatch(); var modifier = identityService.GetUserId(); texture.UpdateBasicInfo(request.Name, modifier); await textureRepository.UpdateAsync(texture); return(Unit.Value); }
public async Task <Unit> Handle(MaterialPatchCommand request, CancellationToken cancellationToken) { var canOperate = await clientAssetPermissionControlService.CanEditClientAsset(); if (!canOperate) { throw new HttpForbiddenException(); } var data = await materialRepository.FindAsync(request.Id); if (data == null) { throw new HttpResourceNotFoundException(commonLocalizer["HttpRespond.NotFound", "Material", request.Id]); } mapper.Map(data, request); request.ApplyPatch(); var modifier = identityService.GetUserId(); data.UpdateBasicInfo(request.Name, request.Description, request.Icon, modifier); data.UpdateCategory(request.CategoryId); await materialRepository.UpdateAsync(data); return(Unit.Value); }
public async Task <string> Handle(MapCreateCommand request, CancellationToken cancellationToken) { var canOperate = await clientAssetPermissionControlService.CanEditClientAsset(); if (!canOperate) { throw new HttpForbiddenException(); } var map = new Map(request.Name, request.Icon, identityService.GetOrganizationId(), identityService.GetUserId()); await mapRepository.AddAsync(map); return(map.Id); }
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()); }
public async Task <string> Handle(StaticMeshCreateCommand request, CancellationToken cancellationToken) { var canOperate = await clientAssetPermissionControlService.CanEditClientAsset(); if (!canOperate) { throw new HttpForbiddenException(); } var mesh = new StaticMesh(request.Name, request.Icon, identityService.GetOrganizationId(), identityService.GetUserId()); await staticMeshRepository.AddAsync(mesh); if (request.CreateProduct) { await mediator.Publish(new CreateStaticMeshRelatedProductEvent(mesh.Id, mesh.Name, mesh.OrganizationId, mesh.Creator)); } return(mesh.Id); }