public async Task EditPostAsync(PlayerPostDTO post) { using HttpRequestMessage request = new(HttpMethod.Put, $"{EndpointCategory}"); request.Content = JsonContent.Create(post, new("application/json"), ApiSerializerOptions); using HttpResponseMessage response = await Client.SendAsync(request); await EnsureSuccessfulResponseAsync(response); }
public async Task <PlayerPostDTO> GetPostDTOAsync(Guid id) { Post post = GetPost(id); PlayerPostDTO postDTO = post?.Adapt <PlayerPostDTO>(); return(post?.ReplayId is null ? postDTO : postDTO with { Replay = await _replayService.GetReplayDTOAsync(post.ReplayId.Value) });
public async Task <Guid> SubmitNewPostAsync(PlayerPostDTO post, IBrowserFile replayFile = null, CancellationToken ct = default) { using MultipartFormDataContent form = new(); using StreamContent replayFileStream = replayFile is null ? null : form.AddReplayFile(replayFile, ct); form.Add(JsonContent.Create(post, new("application/json"), ApiSerializerOptions), "postDto"); using HttpRequestMessage request = new(HttpMethod.Post, $"{EndpointCategory}") { Content = form }; using HttpResponseMessage response = await Client.SendAsync(request, ct); await EnsureSuccessfulResponseAsync(response); return(new((await response.Content.ReadAsStringAsync(ct)).Replace("\"", null))); }
public async Task SubmitPostModActionAsync(PostModActionDTO modAction) { EntityEntry <PostModAction> entityEntry = await _context.PostModActions.AddAsync(modAction.Adapt <PostModAction>()); switch (modAction.ActionType) { case ModActionType.Deletion: await _postService.DeletePostAsync(modAction.PostId, true); await _notifications.SendNewNotification(PostModDeletedNotification.FromModAction(entityEntry.Entity)); break; case ModActionType.Update: PlayerPostDTO current = _postService.GetPost(modAction.PostId).Adapt <PlayerPostDTO>(); await _postService.EditPostAsync(modAction.PostId, current with { Content = modAction.UpdatedPost.Content ?? current.Content, Flairs = modAction.UpdatedPost.Flairs }); break; }