public async Task <IActionResult> Update(string id, [FromBody] WatchListUpdateModel model) { var watchList = await GetWatchList(id); if (watchList == null) { return(NotFound()); } if (watchList.ReadOnly || !await IsValidAsync(model.AssetPairIds) || string.IsNullOrEmpty(model.Name)) { return(BadRequest()); } var watchlists = await GetAllWatchlists(); if (watchlists.Any(item => item.Name == model.Name && item.Id != watchList.Id)) { return(BadRequest()); } var newWatchList = new WatchListDto() { Id = id, Name = model.Name, Order = model.Order, AssetIds = model.AssetPairIds.ToList() }; await _assetsHelper.UpdateCustomWatchListAsync(_requestContext.ClientId, newWatchList); return(Ok(newWatchList.ToApiModel())); }
public async Task <IActionResult> Update(string id, [FromBody] WatchListUpdateModel model) { try { WatchList watchList = await GetWatchList(id); if (watchList == null) { return(NotFound("Watch-list not found!")); } if (watchList.ReadOnlyProperty) { return(BadRequest("This watch-list is read only!")); } if (!await IsValidAsync(model.AssetIds)) { return(BadRequest("Wrong assets in 'AssetIds' list")); } if (string.IsNullOrEmpty(model.Name)) { return(BadRequest("Name can't be empty")); } var watchlists = await GetAllWatchlists(); if (watchlists.Any(item => item.Name == model.Name && item.Id != watchList.Id)) { return(BadRequest($"Watch-list with name '{model.Name}' already exists")); } var newWatchList = new WatchList { Id = id, Name = model.Name, Order = model.Order, AssetIds = model.AssetIds.ToList() }; await _assetsService.WatchListUpdateCustomAsync(newWatchList, _requestContext.ClientId); return(Ok(newWatchList)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void PutWatchlistInvalidTokenTest() { Step("Make PUT /api/watchlists/{id} and validate response", () => { var model = new WatchListUpdateModel { AssetPairIds = new List <string> { "BTCUSD" }, Name = "Autotest", Order = 0 }; var response = apiV2.Watchlists.PutWatchlistsById(model, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized)); }); }
public IResponse <WatchListModel> PutWatchlistsById(WatchListUpdateModel model, string id, string token) => Request.Put($"/watchlists/{id}").AddJsonBody(model).WithBearerToken(token).Build().Execute <WatchListModel>();