Need a hand with Asp.net MVC Net7.
I totally forgot that I had an assignment due to Wednesday (in 3 days) because I was prioritizing other subjects.
My teacher told me to create a forum-like website where users who are logged in will be able to post and their author name, posted date, etc will be visible. Also people who are logged in can comment on your post and their name and date of posting that comment will also be visible.
The firsttask is basically that I have to make use of three Models, and all of them three independently interact with each other.
-------------------
The other task is that I have to hash/encrypt any valuable data such as passwords which I already have completed.
As mentioned above, both the post and comments and names will be in the same view. I have been trying to find anything valuable as a starting point but with multiple models in a single view but none. Even GPT doesnt help. If anyone can help a brother out. Really struggling lmfao. I can share any info you want let me know.
33 Replies
What exactly is the issue?
I need to create a post/blog site consisting of minimum three models that interact with eachother. Must be a blog themed site he said,
So, how does your
Models
look like?
As I understand it, it's plain MVC OOP, determine which Models
to create and Properties
they gonna have.
User
, Comment
, etc.So a blog or a forum?
By my definition a site where everyone can post and comment on eachothers stuff.
He used the term "blog" but
If I understood you correctly I already got 1 Model for Login, the user stuff basically, 1 for posting (title, description, etc) and 1 for comments, commentId, comment,
That seems fine, yeah
User, Post, Comment
Post has author (User), Comment has author (User), Post has Comments
Ye
Thats the bare minimum for max score
I think that doesn't matter, what's meant is, how you create the classes in MVC. For instance, having a
Comment
class, what does it need? - Properties like, Value as string
, DateTime
posted on, and which user posted it, so UserId as int
. This Model correlate with the User
model which has properties like Id as int
, name as string
, etc. - also it has a 1:1 relationship involved, etc.Yeah exactly, i think he means as in, basically have 3 models in a single view and make sure they all have the same purpose i.e( They all build up the posting mechanism) 1 does the comments part, 1 does user (author), createDate, (1 does data display of Title, and description)
Maybe creating an ERM first, would help and giving some extra points.
What does that stand for
Entity Relationship Model
Yeah I understand.
I dont know where to start you get me?
I cant find anything
AS @ZZZZZZZZZZZZZZZZZZZZZZZZZ mentioned earlier, create things/classes like User, Post, Comment, and think of them as entities, what kind of properies and Comment can or should have. That's also how to write an ERM or ERD.
1. Make a folder named
Models
2. Add files for User
, Post
, Comment
classes
3. Add properties to those classes
For example, a Post
would be, say,
Yes but how do I come to even be able to use them all three in the same view.
My problems at the moment:
1. How to use 3 models in the same view.
(Google havent been able to help at all seriously) if you're a better google'er go for it.
2. Lets say I found out how to solve problem 1. How do I build a bridge between those models, so when the author creates a post and I as a viewer click on it how am i supposed to write the logic so it's bound to that specific post? I need to mark them with their ids, to identify for each post, and thats the part i suck at.
I understand the theoretical part but the physical is where im struggling at, because there is no info anywhere on how I can proceed.
I assume you use a database?
With Entity Framework?
Yes MSSQL
yes
Cool
Well, see how in my example the post has a property of type
User
?They have nothing to do with the view itself.
The Controller part of MVC will do the job.
That
It allows you to load related data
Yes
For example,
Is that User another model
This would be a quick and very dirty way to load the post, that post's author, and the comments to that post
which you reffered to
Yes
Three models: post, user, comment
Where is this supposed to be
Controller?
Imho, there is a thin line between those three patterns; there are not so different and most of the time mixed together,
If you take a look at these patterns, and your code, your entities/models, does it make sense, the connections?
It's the easiest way, yes
Alright, can I fix this in 2 days you reckon?
Because after all this i have still been trying to fix it but i dont know what code to write.
Maybe
my brain is so fried bro
Been on visual studio for 10 hours staring into the abyss
I need a sample or example so i can understand how its applied
Maybe i can send you repo
idk
take a look