@using Radzen @using System.ComponentModel.DataAnnotations @using System.IO.Pipelines @using System.Net.Mime @using System.Reflection @using System.Runtime.CompilerServices @using ImageBoardServerApp.Data @using ImageBoardServerApp.Data.Repository @inject NavigationManager NavigationManager
[ @toggleText ]
@if (opened) {
Post to /@board.Tag/ - @board.Topic
OnChange(args, "username")) Class="w-100"/>
OnChange(args, "title")) Class="w-100"/>
OnChange(args, "Content")) Class="w-100"/>
} @code { private bool opened = false; private string toggleText = "Open Post Formula"; private void ToggleOpened() { opened = !opened; toggleText = opened ? "Close Post Formula" : "Open Post Formula"; } [Parameter] [Required] public BoardData board { get; set; } = new BoardData(); string postUsername = "Anonymous"; string postTitle = ""; string postContent = ""; void OnChange(string value, string name) { switch (name) { case "title": postTitle = value; break; case "username": postUsername = value; break; case "content": postContent = value; break; default: Console.WriteLine("not found."); break; } Console.WriteLine($"Smth changed!: {value}"); } private async Task SingleUpload(InputFileChangeEventArgs e) { MemoryStream ms = new MemoryStream(); await e.File.OpenReadStream().CopyToAsync(ms); var bytes = ms.ToArray(); image = bytes; Console.WriteLine("File has been selected!"); ms.Close(); } private Byte[] image; private async Task onPostClick() { var userToCreate = new UserData { Ipv4Address = "192.168.178.101", Banned = false, lastActionTimeStamp = DateTime.Now.Millisecond }; int userID = await UsersRepository.createUserAsync(userToCreate); //TODO Add check if data is image var imageToUpload = new ImageData { Board = board.Tag, Image = image }; int imageID = await ImagesRepository.createImageAsync(imageToUpload); var postToPost = new PostData { UserID = userID, ImageID = imageID, Username = postUsername, Title = postTitle, Content = postContent, Interactions = 0, CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Board = board.Tag }; int postId = await PostsRepository.createPostAsync(postToPost); if (postId != -1) { //Open post successfull NavigationManager.NavigateTo("/SuccessfulPost"); Console.WriteLine("Post created"); } else { //Open post unsucessfull NavigationManager.NavigateTo("/UnSuccessfulPost"); Console.WriteLine("Shit sucks and did not work."); } } }