public async Task <IActionResult> AddWatchlistEntry([FromBody] Model.WatchlistEntry entry) { //Check if the entry exists var watchlistEntryEntity = await _watchlistRepo.GetWatchListMediaEntry(Guid.Parse(entry.WatchlistId), Guid.Parse(entry.MediaId)); if (watchlistEntryEntity != null) { return(NoContent()); //If entry exists it means the operation was done successfully, just return No content. } else { watchlistEntryEntity = _mapper.Map <Entities.WatchlistMedia>(entry); //If entry doesn't exists, map entry to a new entity } //Add to watchlits await _watchlistRepo.AddWatchlistMediaEntryAsync(watchlistEntryEntity); var success = await _watchlistRepo.SaveChangesAsync(); if (!success) { return(BadRequest("Bad request")); } //Get Watchlist with updated entry var updatedList = await _watchlistRepo.GetWatchlistAsync(Guid.Parse(entry.WatchlistId)); var listResult = _mapper.Map <Model.WatchlistModel>(updatedList); //Return result return(Ok(listResult)); }
public async Task <IActionResult> RemoveWatchListEntry([FromBody] Model.WatchlistEntry entry) { var success = await _watchlistRepo.RemoveWatchlistEntryAsync(Guid.Parse(entry.WatchlistId), Guid.Parse(entry.MediaId)); if (!success) { return(NotFound()); } await _watchlistRepo.SaveChangesAsync(); return(NoContent()); }