示例#1
0
        public async Task <IActionResult> Put(string id, DownloadRequest request)
        {
            var download = await _downloads.GetByIdAsync(id);

            if (download == null)
            {
                return(NotFound(new ErrorResponse("The download does not exist.")));
            }

            var result = await _authorizationService.AuthorizeAsync(User, download, new UpdateOperationAuthorizationRequirement());

            if (!result.Succeeded)
            {
                return(Forbid(new ErrorResponse("Not authorized to modify download.")));
            }

            if (!Version.TryParse(request.Version, out Version version))
            {
                return(BadRequest(new ErrorResponse("Invalid version string.")));
            }

            var updated = await _downloads.UpdateAsync(id, _mapper.Map <Download>(request));

            return(Ok(_mapper.Map <DownloadResponse>(updated)));
        }