public async Task <Unit> Handle(FilePatchCommand request, CancellationToken cancellationToken) { var asset = await fileAssetRepository.FindAsync(request.Id); if (asset == null) { throw new HttpResourceNotFoundException(localizer["HttpRespond.NotFound", "File", request.Id]); } var operatorId = identityService.GetUserId(); mapper.Map(asset, request); request.ApplyPatch(); asset.UpdateBasicInfo(request.Name, request.Description, request.FileState, operatorId); await fileAssetRepository.UpdateAsync(asset); return(Unit.Value); }
public async Task <string> Handle(FileCreateCommand request, CancellationToken cancellationToken) { var file = await fileAssetRepository.FindAsync(request.MD5); if (file != null) { file.UpdateBasicInfo(request.Name, request.Description, request.FileState, identityService.GetUserId()); await fileAssetRepository.UpdateAsync(file); return(file.Id); } var url = $"/{OSSConst.AppRouteArea}/{OSSConst.ClientAssetFolder}/{request.MD5}.{request.FileExt}"; file = new FileAsset(request.Name, request.Description, request.FileExt, request.FileState, request.Size, url, identityService.GetUserId()); file.CustomizeId(request.MD5); await fileAssetRepository.AddAsync(file); return(file.Id); }