Ejemplo n.º 1
0
    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);
    }
Ejemplo n.º 2
0
        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)
            });
Ejemplo n.º 3
0
    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)));
    }
Ejemplo n.º 4
0
    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;
        }