C
C#2y ago
KooriByte

✅ How would you search this?

Hey guys, I need help not with a direct answer, but I want to know how would you search the answer online for this. I have a MVC Project for a FilmReviewer (like IMDb, MyAnimeList, etc) I need to create a button in Film Detail View, that: puts this film in the users favorited list, puts the user in the film's favoritedby list, and afterwards, changes color, so the user can know that he already favorited this specific film. I know many of you may have an answer for this problem, and I would also appreciate a direct answer, but my main problem is that I'm finding it difficult to search online how to do this, so that is my question... How would you search this online, if you had this doubt?
17 Replies
Angius
Angius2y ago
"asp core mvc how to send data without reloading" For example The answer is Javascript by the by Or, more precisely, a bit of fetch() and element.classList stuff
canton7
canton72y ago
Start by breaking the problem down. There's a lot there. Which bit are you having trouble with? Presumably you're OK handling the button click... So the first part is about adding a user to the film's favourite list. Do you already that modelled in your database? If not, I'd start by searching how to use EF (or whatever) to let one entity own a collection of another entity, and how to add to that
Angius
Angius2y ago
That too, in even more general terms. "Divide and conquer" Split a problem into smaller problems
canton7
canton72y ago
For the colour... You need to start by checking whether the user has favourited the film -- back to EF and collections and queries. Once you've got that, we're into how to set data from the controller which is available in the view -- fairly basic MVC stuff if this is a page load, or a bit more javascripty if you're making the request with javascript. Then how to change the colour of a button in HTML, which might lead you into how to add a class to an element
KooriByte
KooriByteOP2y ago
model and everything is already done, I had some problem with the relations, but already learned how to solve them
canton7
canton72y ago
(I'm not trying to actually answer the question as requested, but trying to show how to break it down into sub-problems and come up with the more general form of the problem, rather than searching for your specific complex case)
KooriByte
KooriByteOP2y ago
this really helps already, you almost said a step by step in general terms, thank you very much!! ok, so trying to break a bigger problem into smaller ones and trying to understand those smaller problems before solving the whole thing it really makes sense, idk why I didn't thought of this in first place lol tks everyone! I'll leave this open, because I'm curious for other people's answer too
canton7
canton72y ago
Yeah, and don't search for your specific thing. Don't google how to change the colour of a button to blue, but just how to change it (simple example, but applies to other things too). Noone's going to do a write-up on how to add favourites to your film list, but there'll be lots of stuff on the more general adding an entity to another entity's list of related entities And also, breaking the problem down means you get to solve it bit-by-bit, which is more satisfying as you get to see each bit working in turn, and makes it quicker as you're not trying to get everything working at once
KooriByte
KooriByteOP2y ago
so now that raises a second question, how do you usually break down a problem that you don't understand? Don't you need to have previous knowledge on the content to understand the parts of the problem and divide it?
canton7
canton72y ago
Common sense, I guess? You need to have some knowledge of the domain to even know what you're trying to build Figuring out the general flow of button click --> handle on the server --> update database --> respond to browser --> update button colour I guess requires that you know the different bits of a web application and how they relate to each other. And if you don't, you should probably be looking at a more general question, like how to build a web application If you don't know anything about an area, then tutorials are a good place to start. They'll introduce you to the different bits and how they work together, tell you what you don't know you don't know E.g. I don't do much web stuff these days. If I had to start a new MVC application, I'd start with the MS tutorial, to introduce me to the different moving parts
RockyDf01
RockyDf012y ago
What I would do if I want to add something into favorites without updating the page I would use Onclick in the js section where it will store the current item into Cookies And then from there you can just make checking if you got that change color and etc Would be cool to make another page to checkout all your favorites that you saved into cookie
Angius
Angius2y ago
Why cookies tho, that won't persist the data
RockyDf01
RockyDf012y ago
Well he can make a form where it can execute reload his page and save it to db, but it will just take space Most people I see who save data like carts or favorites they use cookies or local storage
Angius
Angius2y ago
It will take a few bytes of space, yes, but your favorites will be the same across all devices Browser storage might make sense for a cart, something ephemeral, but not for favorites IMHO
RockyDf01
RockyDf012y ago
It’s like the same thing😭 Hmm
Espionage
Espionage2y ago
I don't see anyone really giving you a direct answer.... I would be searching two separate things, assuming you want to persist it: How to change link color when clicked? (IMO the answer is just CSS based on a DB entry) 'How to use conditional logic to change text color C# MVC ' 'How to add/retrieve a record in a database C# MVC?' If you don't understand relational databases it might not be obvious to you, but regarding adding to a users favorited list, displaying the favorited by and changing the color, this can all be achieved by one database entry which would link two separate tables. Then using conditional logic, modifying how it is output to the page either by directly applying a style to the html output, or using a class to achieve the same.
KooriByte
KooriByteOP2y ago
Thanks everyone, I almost figured out what to do... the problem now is that idk how to pass the object id to my controller should I open another question on help, or I can still ask related stuff here on this one? no more need for this too, already solved 😄 man, I'm feeling so smart rn
Want results from more Discord servers?
Add your server