public async Task<IHttpActionResult> PutComments(int id, Comments comments) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != comments.Id) { return BadRequest(); } db.Entry(comments).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentsExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
private async void getPlaylists() { IsLoading = true; PrivateProfile = _spotifyWeb.GetPrivateProfile(); Playlists = _spotifyWeb.GetUserPlaylists(_privateProfile.Id); NewComment = new Comments() { Username = PrivateProfile.Id }; //GetAllComments(); var collaborativePlaylists = _playlists.Items.Where(e => e.Collaborative).ToList(); if (collaborativePlaylists.Any()) { string[] ids = collaborativePlaylists.Select(e => e.Id).ToArray(); Comments = await ServiceLocator.Current.GetInstance<DataService>().GetCommentsForPlaylistIdsAsync(ids); foreach (var playlist in collaborativePlaylists) { getTracksForPlaylist(playlist); } } CollaborativePlaylists = collaborativePlaylists; //var y = await ServiceLocator.Current.GetInstance<DataService>().PostCommentAsync(new Comments() //{ // Comment = "Test Dataservice", // PlaylistId = "1", // TrackId = "1", // Order = 1 //}); IsLoading = false; }
public async Task<Comments> PostCommentAsync(Comments comment) { try { var requestUrl = string.Format(BASE_URL, COMMENT_URL); var content = JsonConvert.SerializeObject(comment); var response = await RequestAsync<string>(requestUrl, HttpMethod.Post, content, CONTENT_TYPE_APPLICATION_JSON); if (response.IsSuccessStatusCode) { var comments = JsonConvert.DeserializeObject<Comments>(response.Content); return comments; } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } return new Comments(); }
public async Task<IHttpActionResult> PostComments(Comments comments) { if (!ModelState.IsValid) { return BadRequest(ModelState); } // set next order number var dbComments = db.Comments.Where(e => e.PlaylistId == comments.PlaylistId && e.TrackId == comments.TrackId); if (dbComments.Any()) { var lastOrder = dbComments.OrderByDescending(e => e.Order).First(); var newOrder = lastOrder.Order; comments.Order = newOrder++; } db.Comments.Add(comments); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = comments.Id }, comments); }