/// <summary> /// Persists a given post to the database /// </summary> /// <param name="actualRequest">the client request to be handled</param> /// <returns>the response to the given request</returns> private async Task <ActualRequest> AddPostAsync(ActualRequest actualRequest) { Request request = actualRequest.Request; PostShortVersion post = JsonSerializer.Deserialize <PostShortVersion>(request.Argument.ToString()); post.HasImage = actualRequest.Images != null; Console.WriteLine("Post Sockets adding post " + post.Title); int result = await postRepo.AddPostAsync(post); Request responseRequest = new Request { ActionType = ActionType.POST_CREATE.ToString(), Argument = JsonSerializer.Serialize(result) }; if (result > 0) { if (post.HasImage) { try { ImagesUtil.WriteImageToPath(actualRequest.Images[0], $"{FILE_PATH}/Posts", $"/{result}.jpg"); } catch (Exception e) { Console.WriteLine("Could not add image to created post " + result); } } } return(new ActualRequest { Request = responseRequest, Images = null }); }
public async Task <IActionResult> OnPostPostingAsync(string postText, int?teamId, int?eventId) { if (string.IsNullOrEmpty(postText)) { return(Page()); } await LoadContextAsync(teamId, eventId); if (Event == null) { return(Page()); } Models.Post post = new Models.Post() { TeamId = Event.TeamId, PersonId = Me.Id, Date = DateTime.Now, Text = postText }; await postRepo.AddPostAsync(post); await mailService.SendPostMailAsync(post); return(RedirectToPage("./Index", new { teamId, eventId })); }