continued to work in comments
This commit is contained in:
parent
4b1f234f2a
commit
f09722757a
4 changed files with 52 additions and 13 deletions
|
@ -21,7 +21,7 @@ public class CommentData
|
|||
public int UserID { get; set; }
|
||||
|
||||
//[ForeignKey("UserID")]
|
||||
public UserData User { get; set; }
|
||||
public virtual UserData User { get; set; }
|
||||
|
||||
//[ForeignKey("ImageID")]
|
||||
public virtual ImageData Image { get; set; }
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
NavigationManager.NavigateTo("/notfound");
|
||||
return;
|
||||
}
|
||||
if(post.Board != boardName)
|
||||
NavigationManager.NavigateTo("/notfound");
|
||||
if(post == null)
|
||||
NavigationManager.NavigateTo("/notfound");
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
@if (opened)
|
||||
{
|
||||
<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">
|
||||
<RadzenTextBox Placeholder="Username (Anonymous)" MaxLength="15" Change=@(args => OnChange(args, "username")) Class="w-100"/>
|
||||
|
@ -22,6 +22,7 @@
|
|||
</div>
|
||||
|
||||
<div class="pd centered marg">
|
||||
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/>
|
||||
<RadzenButton class="pd" Click="@onPostClick" Text="Comment!"></RadzenButton>
|
||||
</div>
|
||||
|
||||
|
@ -69,6 +70,18 @@
|
|||
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
|
||||
|
@ -79,23 +92,48 @@
|
|||
};
|
||||
int userID = await UsersRepository.createUserAsync(userToCreate);
|
||||
|
||||
var commentToCreate = new CommentData()
|
||||
bool hasImage = false;
|
||||
CommentData commentToCreate;
|
||||
if (hasImage)
|
||||
{
|
||||
PostID = post.PostID,
|
||||
var imageToUpload = new ImageData
|
||||
{
|
||||
Board = post.Board,
|
||||
Image = image
|
||||
};
|
||||
int imageID = await ImagesRepository.createImageAsync(imageToUpload);
|
||||
commentToCreate = new CommentData()
|
||||
{
|
||||
PostID = post.PostID,
|
||||
UserID = userID,
|
||||
ImageID = imageID,
|
||||
Content = postContent,
|
||||
Username = postUsername,
|
||||
Board = post.Board,
|
||||
CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds()
|
||||
/*
|
||||
UserID = userID,
|
||||
Content = postContent,
|
||||
Username = postUsername,
|
||||
Board = post.Board,
|
||||
CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds()
|
||||
/*
|
||||
* UserID = userID,
|
||||
Post = post,
|
||||
Username = postUsername,
|
||||
Content = postContent,
|
||||
CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
|
||||
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);
|
||||
if (commentId == -1)
|
||||
{
|
||||
|
|
|
@ -104,7 +104,6 @@
|
|||
|
||||
//TODO Add check if data is image
|
||||
|
||||
|
||||
var imageToUpload = new ImageData
|
||||
{
|
||||
Board = board.Tag,
|
||||
|
|
Loading…
Reference in a new issue