❔ Naming enum value for level or floor for a building
Hi, so, I've read some posts saying it is not descriptive at all to name enum values like "One", "Two", "Three", etc.. However, if it is used for a building where there's level/floor, wouldn't it make sense to name it as those aforementioned values? Or should it be like "LevelOne", "LevelTwo", etc...
18 Replies
This shouldn't be an enum. Either have a "level" property, an int like suggested, or something more descriptive that can be properly localized and adapted, imo. It's a reference data and should be treated as such I think.
Okay, so, I have a model already, say ClassroomLocation, and a location definitely have a floor/level in a building. So I thought of to create an enum for it and display it as a drop-down list, which it works as expected, till saving it in database and then displaying the details become an issue.
So that's current way of using enum for flood/level numbers. If not using enum, then wdym by "property". And where should this property goes if it's not enum and shouldn't be under "Enums" folder
you should be able to customize the value collections of your dropdowns
property means field and get or set, or both
public int Floor { get; set; }
enums don't have to be in enums folder, they can be anywhere
I'd define them closer to where I'd actually use themOkay, I have define this in my model like so
public int Level { get; set; }
. As for the dropdown value, in my razor view, I'll have to loop for the numbers?yeah probably
Is it possible to make it dynamic btw? Right now, I'm looping in my razor view, and that's hardcoding it already. How do I make it so that the dropdown value is retrieved from somewhere else that is set by, say an admin of the respective department using the dashboard? Like, they set the name of the block / floor numbers, and whoever is creating a new classroom location, the dropdown value is based on the value set by the admin.
you could make the max value of the loop a property on the model and retrieve it from the database when you generate the page
Hmm, wouldn't that also hardcoding it? Like for example if the management decided to expand the building, new floors getting added, then I'll have to go into the source code and increment the value instead of adding new floor in the dashboard?
you add it in the dashboard, it gets saved into the database. then in your code you query the database and render the page with the latest value
I'm assuming this does not require an additional model like a "Level" model or "Block" model right?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
more like
BuildingConfiguration
you do need to link the dashboad settings to somethingYeah I went with this initially, I had something like
Then when I save the data in the database (converting it to string), it would save "LevelOne". Since the floor number should be in integer, I figure maybe I shouldn't be using enum since I only need the integer to be saved into the database. So a simple loop maybe would do. I also know that I can just do
LevelOne = 1, LevelTwo = 2
when using enum, but again, wouldn't it be better to just loop?Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Is that a settings or a model? And when you say linking the dashboard settings, do you mean to link the values set for block / level by the admin to the dropdown?
I'm using EF Core. But yeah, I found enums to be easily understood, at least for me. But since I'm looking to dynamically add the block / levels, I think I might need to ditch enum as I'll be hardcoding the floor numbers
I'm just saying that the settings from the dashboard get saved in the database, from which it then will be pulled when rendering the page. How you implement it exactly is up to you
No it's not. What if you dig another floor. What if you add another floor? You need to open the source code just to edit the enum for a business reason while you should just insert a row in a database or in your configuration json .
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.