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())); }
async Task <IWatchList> IWatchListsClient.AddCustomAsync(WatchListDto watchList, string clientId) { var result = await HttpClient.WatchListAddCustomAsync(FromWatchListDto(watchList), clientId); var dto = FromWatchListResponse(result); return(dto); }
async Task <IWatchList> IWatchListsClient.AddPredefinedAsync(WatchListDto watchList) { var result = await HttpClient.WatchListAddPredefinedAsync(FromWatchListDto(watchList)); var data = FromWatchListResponse(result); return(data); }
private WatchList FromWatchListDto(WatchListDto item) { if (item == null) { return(null); } return(new WatchList(item.AssetIds, item.Id, item.Name, item.Order, item.ReadOnly)); }
public int CreateWatchList(WatchList watchList) { WatchListDto watchListDto = new WatchListDto(); watchListDto.MovieID = watchListDto.MovieID; int rowcount = db.CreateWatchList(watchListDto); return(rowcount); }
public int CreateWatchList(WatchListDto watchListDto) { using (MySqlConnection conn = GetConnection()) { conn.Open(); string command = "INSERT INTO watchlist (MovieID, UserID)" + "values ({0}, {1})"; MySqlCommand cmd = new MySqlCommand(string.Format(command, watchListDto.MovieID, 1), conn); int rowcount = cmd.ExecuteNonQuery(); return(rowcount); } }
public IHttpActionResult UpdateWatchList(int id, WatchListDto watchListDto) { //First we validate the object, and throw exception if model is not valid if (!ModelState.IsValid) { return(BadRequest()); } var watchListInDb = _context.WatchLists.SingleOrDefault(c => c.Id == id); //It's possible that the client sends an invalid Id so we need to check for the existence of the object. if (watchListInDb == null) { return(NotFound()); } Mapper.Map(watchListDto, watchListInDb); _context.SaveChanges(); return(Ok()); }
private async Task <IWatchList> FilterAssetPairsAsync(IWatchList watchList, List <string> availableAssetPairIds = null) { availableAssetPairIds = availableAssetPairIds ?? await GetAvailableAssetPairIdsAsync(); var filteredAssetPairIds = watchList.AssetIds .Where(x => availableAssetPairIds.Contains(x)) .ToList(); if (!filteredAssetPairIds.Any()) { return(null); } var result = new WatchListDto() { AssetIds = filteredAssetPairIds, Id = watchList.Id, Name = watchList.Name, Order = watchList.Order, ReadOnly = watchList.ReadOnly }; return(result); }
public async Task UpdateCustomWatchListAsync(string clientId, WatchListDto watchList) { await _assetsServiceUserDataClient.WatchLists.UpdateCustomWatchListAsync(clientId, watchList); }
async Task IWatchListsClient.UpdatePredefinedAsync(WatchListDto watchList) { await HttpClient.WatchListUpdatePredefinedAsync(FromWatchListDto(watchList)); }
async Task IWatchListsClient.UpdateCustomWatchListAsync(string clientId, WatchListDto watchList) { await HttpClient.WatchListUpdateCustomAsync(FromWatchListDto(watchList), clientId); }