continued to work in comments

This commit is contained in:
limited_dev 2023-01-26 09:07:25 +01:00
parent 4b1f234f2a
commit f09722757a
4 changed files with 52 additions and 13 deletions

View file

@ -21,7 +21,7 @@ public class CommentData
public int UserID { get; set; } public int UserID { get; set; }
//[ForeignKey("UserID")] //[ForeignKey("UserID")]
public UserData User { get; set; } public virtual UserData User { get; set; }
//[ForeignKey("ImageID")] //[ForeignKey("ImageID")]
public virtual ImageData Image { get; set; } public virtual ImageData Image { get; set; }

View file

@ -36,6 +36,8 @@
NavigationManager.NavigateTo("/notfound"); NavigationManager.NavigateTo("/notfound");
return; return;
} }
if(post.Board != boardName)
NavigationManager.NavigateTo("/notfound");
if(post == null) if(post == null)
NavigationManager.NavigateTo("/notfound"); NavigationManager.NavigateTo("/notfound");
} }

View file

@ -11,7 +11,7 @@
@if (opened) @if (opened)
{ {
<div class="pd centered"> <div class="pd centered">
<span>Comment on @post.Title by @post.Username in @post.Board</span> <span>Comment on @post.Title in /@post.Board/</span>
<div class="pd centered marg"> <div class="pd centered marg">
<RadzenTextBox Placeholder="Username (Anonymous)" MaxLength="15" Change=@(args => OnChange(args, "username")) Class="w-100"/> <RadzenTextBox Placeholder="Username (Anonymous)" MaxLength="15" Change=@(args => OnChange(args, "username")) Class="w-100"/>
@ -22,6 +22,7 @@
</div> </div>
<div class="pd centered marg"> <div class="pd centered marg">
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/>
<RadzenButton class="pd" Click="@onPostClick" Text="Comment!"></RadzenButton> <RadzenButton class="pd" Click="@onPostClick" Text="Comment!"></RadzenButton>
</div> </div>
@ -69,6 +70,18 @@
Console.WriteLine($"Smth changed!: {value}"); 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() private async Task onPostClick()
{ {
var userToCreate = new UserData var userToCreate = new UserData
@ -79,16 +92,27 @@
}; };
int userID = await UsersRepository.createUserAsync(userToCreate); int userID = await UsersRepository.createUserAsync(userToCreate);
var commentToCreate = new CommentData() bool hasImage = false;
CommentData commentToCreate;
if (hasImage)
{
var imageToUpload = new ImageData
{
Board = post.Board,
Image = image
};
int imageID = await ImagesRepository.createImageAsync(imageToUpload);
commentToCreate = new CommentData()
{ {
PostID = post.PostID, PostID = post.PostID,
UserID = userID, UserID = userID,
ImageID = imageID,
Content = postContent, Content = postContent,
Username = postUsername, Username = postUsername,
Board = post.Board, Board = post.Board,
CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds() CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds()
/* /*
* UserID = userID, UserID = userID,
Post = post, Post = post,
Username = postUsername, Username = postUsername,
Content = postContent, Content = postContent,
@ -96,6 +120,20 @@
Board = post.Board Board = post.Board
*/ */
}; };
}
else
{
commentToCreate = new CommentData()
{
PostID = post.PostID,
UserID = userID,
Content = postContent,
Username = postUsername,
Board = post.Board,
CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds()
};
}
int commentId = await CommentsRepository.createCommentAsync(commentToCreate); int commentId = await CommentsRepository.createCommentAsync(commentToCreate);
if (commentId == -1) if (commentId == -1)
{ {

View file

@ -104,7 +104,6 @@
//TODO Add check if data is image //TODO Add check if data is image
var imageToUpload = new ImageData var imageToUpload = new ImageData
{ {
Board = board.Tag, Board = board.Tag,