public async Task <IActionResult> Update(string key, [FromBody] UpdateCollectionRequest request) { try { var userKey = _contextAccessor.UserKeyFromContext(); bool userCanAccessCollection = await UserCanAccessCollection(userKey, key, _hiarcDatabase, AccessLevelGroup.ReadWriteOrHigher); if (userCanAccessCollection) { var updatedCollection = await _hiarcDatabase.UpdateCollection(key, request); return(Ok(updatedCollection)); } else { return(StatusCode(StatusCodes.Status403Forbidden)); } } catch (InvalidOperationException ex) { _logger.LogError(ex.Message); return(StatusCode(StatusCodes.Status403Forbidden)); } catch (Exception ex) { return(BuildErrorResponse(ex, _logger)); } }
public CreateCollectionResponse UpdateCollectiosWithObject(UpdateCollectionRequest request) { var body = JsonConvert.SerializeObject(request); FormAndWriteRequestBody(body); return(GetRequestResponse()); }
public async Task <Collection> UpdateCollection(string key, UpdateCollectionRequest request, string asUserKey = null, string bearerToken = null, bool logToConsole = true) { var updatedCollection = await Put <UpdateCollectionRequest, Collection>(request, $"collections/{key}", asUserKey, bearerToken); if (logToConsole) { Console.WriteLine($"Updated Collection: {ToJson(updatedCollection)}"); } ; return(updatedCollection); }
private void UpdateCollection() { Console.WriteLine(string.Format("\nCalling UpdateCollection()...")); UpdateCollectionRequest updateCollectionRequest = new UpdateCollectionRequest() { Name = _updatedCollectionName, }; var result = _discovery.UpdateCollection(_createdEnvironmentId, _createdCollectionId, updateCollectionRequest); if (result != null) { Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented)); } else { Console.WriteLine("result is null."); } }
public async Task <IActionResult> UpdateCollection([FromBody] UpdateCollectionRequest request) { MovieCollection collectionToUpdate = await this.movieCollections.GetById(request.Id); if (collectionToUpdate == null) { return(NotFound(new ErrorResponse { Error = "Invalid collection Id." })); } collectionToUpdate.Name = request.Name; collectionToUpdate.Description = request.Description; MovieCollection movieCollection = await this.movieCollections.Update(collectionToUpdate); MovieCollectionResponse response = this.mapper.Map <MovieCollectionResponse>(movieCollection); return(Ok(response)); }
public Collection UpdateCollection(string environmentId, string collectionId, UpdateCollectionRequest body = null) { try { var result = DiscoveryRepository.UpdateCollection(environmentId, collectionId, body); return(result); } catch (Exception ex) { Logger.Error("DiscoveryService.UpdateCollection failed", this, ex); } return(null); }
public Collection UpdateCollection(string environmentId, string collectionId, UpdateCollectionRequest body = null) { if (string.IsNullOrEmpty(environmentId)) { throw new ArgumentNullException(nameof(environmentId)); } if (string.IsNullOrEmpty(collectionId)) { throw new ArgumentNullException(nameof(collectionId)); } if (string.IsNullOrEmpty(VersionDate)) { throw new ArgumentNullException("versionDate cannot be null. Use 'DISCOVERY_VERSION_DATE_2016_12_01'"); } Collection result = null; try { result = this.Client.WithAuthentication(this.UserName, this.Password) .PutAsync($"{this.Endpoint}/v1/environments/{environmentId}/collections/{collectionId}") .WithArgument("version", VersionDate) .WithBody <UpdateCollectionRequest>(body) .As <Collection>() .Result; } catch (AggregateException ae) { throw ae.Flatten(); } return(result); }