Jump to content

C# Object Property halp

Hello i'm planning on making a website where you check the ingredients you have and it lists meals based on those ingredients
as well as risk of it being a trigger food (for people with IBS like myself)

But i'm stuck on a few properties of the ingredients and the meal objects, How do i set these up to work the way i'm imagining?
Mainly ibsRisk, fodMapRisk, rating and foodType. The first 3 should be 1-5 choices basically where a food can have a 1-5 rating (5 being high risk or high rating )

and the foodType should be values like: Meat. Carb, Spice, Veggie etc.that each object has and you have to select this when you create a Ingredient Object.

 

  • Ingredients Object
    • Int ID
    • String Name
    • Enum? ibsRisk
    • Enum? fodMapRisk
    • foodType ( Meat, Carb, Spice, Other)
    • Int kCal
    • Int fiber
    • Int carb
    • Int fat
  • Meal Object
    • int ID
    • String name
    • Enum Rating
    • Ingredients
    • String instructions
    • String timetocook

 

Thanks in forehand!

 

PS: I'm making this in ASP.NET using MVC

Redliquid~

Link to comment
Share on other sites

Link to post
Share on other sites

 

The way I would do it. (Hopefully this will help you)

 

Each recipe is a dictionary containing the ingredients required.

Each ingridient has a score (maybe 1 - 4 of how trigger it is)

When a checkingBox event happens search all dictionarys that contain the first selected ingridient (for a bit of optimization)
 

Show the combined trigger score of the dish next to the results.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, SwedudeOne said:

 

The way I would do it. (Hopefully this will help you)

 

Each recipe is a dictionary containing the ingredients required.

Each ingridient has a score (maybe 1 - 4 of how trigger it is)

When a checkingBox event happens search all dictionarys that contain the first selected ingridient (for a bit of optimization)
 

Show the combined trigger score of the dish next to the results.

But how do i setup the properties that have a score aswell as the foodType property?

I like the ideas though i will add them to the onenote i keep :)

Redliquid~

Link to comment
Share on other sites

Link to post
Share on other sites

There are svereal way to do this. But the most common one is to create a class wiht a property score (Or something like that)

Ex:

 

Class Ingridient{
public int score;
pblic String name
 

Ingridient (int score, String name){

this.score = score;

this.name = name;

 

    }

}

Link to comment
Share on other sites

Link to post
Share on other sites

30 minutes ago, SwedudeOne said:

There are svereal way to do this. But the most common one is to create a class wiht a property score (Or something like that)

Ex:

 

Class Ingridient{
public int score;
pblic String name
 

Ingridient (int score, String name){

this.score = score;

this.name = name;

 

    }

}

 

4bfbe94435.png

 

This is what i currently have but as you can see im not sure how to implement the enums or if i even should try to use them.
If not, what else should i use? I'm reluctant to use just an int because i want to limit the value from 1 to 5.

Thanks again for the help =)

Redliquid~

Link to comment
Share on other sites

Link to post
Share on other sites

You don't need to use enums. Try and make the application as small and basic as possible, and then add features and tidy it up.

Next you should make the dictionaries (recipies) and a function to search through them. 

 

One that's done then you should make it more usefull and easy to use, but you should start to focus on just making it all work.

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, SwedudeOne said:

You don't need to use enums. Try and make the application as small and basic as possible, and then add features and tidy it up.

Next you should make the dictionaries (recipies) and a function to search through them. 

 

One that's done then you should make it more usefull and easy to use, but you should start to focus on just making it all work.

I suppose it's a good idea to work on other things while i figure this out

Redliquid~

Link to comment
Share on other sites

Link to post
Share on other sites

I would suggest doing the search solely on DB and not in c#. It should be faster and likely easier.

 

But for the case in hand:

 

Instead of using enums (or dictionaries) create a risk class with the following properties: name:string, ibsRisk:bool, fodMapRis:bool, description:string.

 

Then your ingredients would be:

name:string, type:foodtype, calories:double, fiber:double, carb:double, fat:double, risks: risk[].

 

and meals:

name:string, rating:double, instructions:string, timetocook:timespan, ingredients:ingredient[]

 

You then have a foodtype class as well with whatever properties you need it to have.

 

Now you can create a method in ingredients to check if the igredient contains a risk that will search through the risks array to find a match and return the applicable values. Then you can create a method in the meal class to check if the meal contains a risk that will step through the ingredients and check if the ingredients has that risk. 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×