Two DropDownList and EntityFramework - drop-down-menu

I need to create the methods (or another that you recommended I) so as to filter the data in two dropdownlist. The scenario I have is as follows:
1) Business Class for database access (CRUD)
2) Two DropDownList (inside a GridView)
The first presents the Groups Article while the second items, according to the choice made in the first the second is populated.
The database tables consist of the following:
1) Table Groups
2) Table of Related Items
The reports of the tables are one-to-many, or one group can have many articles, both have their own primary key.
What suggestions do you give me?
Thank you all,
Ricardo.

i think you just need two methods:
- GetAllGroups(): That call Entity framework to get all groups from db
- GetArticlesByGroupID(<<groupID>>): that get articles from db based on what groups was chosen
the main flow of your program will be:
- after form is initialized, you can method GetAllGroups() and populate into first dropdownlist
- in event selected changed of first dropdownlist and call method GetArticleByGroupID(...) and populate into second dropdownlist
that all.
from Entity Framework view: you need to create any needed Object or DTO, such as groupDTO, ArticleDTO, GroupRespository... or something like that
hope can help you

Related

Readeonly property in kendo mvc project, and not work when sorting or filtering this column

I have two table in my database.
first has a id and description and second table has a id, description and first table key, i create a relation between this. after that i create a readonly property in models of second table and get the description of first table by query. i save 100 row of data in second table and 10000 in first table, and each 100 row of first table for one of the row of second table. now when i sort or filter my kendo grid on this column , this take a long time to load! i test this by a more data and see this is not work! i know this in controller whit out read only property but i want to say me a way to use readonly property!! please guide me.
Your question is a little vague but if I understand correctly, it seems you are having problems dealing with large datasets, you may want to look into using serverFiltering and serverSorting.
Not sure if you have implemented your grid through Razor (.cshtml) or client (.js) however these links should get you on the right track.
A few more tutorial links:
Razor
Javascript

How do I create a UI for a Many-to-Many relationship?

Can anyone advise on the best way to create a UI for establishing Many-to-Many relationships ?
Lets use an example from a previous question List <<-->> Patient.
I can create two separate Table Views, one for Lists and another for Patients which will allow the user to create Lists and Patients using two separately created Array Controllers (Lists and Patients), one linked to the List entity and other linked to the Patient entity.
Now I would like to be able to add/remove Patients from a List by creating an Table View that shows only Patients in the selected List. To do this I create a Array Controller (ListPatients) linked to the entity Patient with a Content Set binding to Lists.selection.patients.
Now things stop working nicely from here on....
If I bind a button to the ListPatients.add method then a NEW Patient gets created - there seems to be no way to simply add a NEW relationship between an existing Patient and the List.
Ideally what I would like to be able to do is to have a drop down list to select the Patient from.
Does anyone have any suggestions as to how best to do this without needing to create a new entity to represent this relationship.
What you need is a swapping Master-Detail view where either the List table or the Patient table is the Master or the Detail at any particular time.
When the List is the Master view, selecting a row will cause the Detail view to display all the Patient objects in the rowList.patients relationship. When the Patient is the Master view, selecting a row will cause the Detail view to display all the List objects in the rowPatient.lists relationship.
You really do want to break up the UI so the users always have a clear idea what the relationship is between the two tables. I would recommend a set of four tables, two each for each Master-Detail setup. That way, the user will also understand what they are looking at.
That will also make it easy to add new objects. Just put an add new button under the detail table and the user will understand that clicking it will add a new object to the relationship of the object selected in the Master view.

ASP.NET MVC 3 how to implement many to many relationship in Create View

I have quite a complex class that has three one-to-many relationships and two many-to-many relationships with other classes. What I would like to do is to enable the user to fill all the details one by one - in one step or even better in multiple steps (wizard).
My class is called PeriodicTask - user has to select one Server object (which represents SQL Server instance ) and depending on the selection I need to present the user with the ability to select which databases he wants to use ( the best option would be to use checkboxes). I don't really know how to achieve this.
I would start with creating an action that returns JSON with databases for the selected server. It'll be invoked by jQuery. So far so good, but what to do then?
Should I add <input type="checkbox"> to the form for every database or maybe create another form and post to some other action? How to parse that when the form is submitted? Can I split it somehow into smaller steps ? HTTP is stateless so I somehow need to pass or remember the data that was previously submitted - how?
PS> I'm using Entity Framework here, so part of the class hierarchy is as follows:
You could do it like this:
User selects server instance from
dropdownlist.
After selection dropdownlist fires "change "event, handler of
which loads databases list to form using ajax (your action can provide JSON or html with checkboxes)
User selects checkboxes and presses
submit button
On submit you collect
checked item and post to action
using javascript
I would look at creating helpers for each of the options that would be self contained, they could maintain the state themselves.
Another cool option would be to create a tree view, where the root level is your server and next level is database. Load the data into a ViewModel so that it can be used as the data source for a tree view. It seems like a nice interface for what you have.
Believe it or not the Microsoft site is a great place to start when learning MVC
http://www.asp.net/mvc

database driven form controls

How to do databse driveen jsp page,
Suppose i have 5 text fields,if user wants to put one of the form field as select box.JSp should identify and return the select box if it define in db as select box.
I dont know how to achieve this,can anyone suggest this.
Regards,
Raju komaturi
There are multiple tasks if you want to do this completely. The world at large has not gone this way and so there are not many tools (if any) for this. But basically here are the main ideas.
1) You want a "data dictionary", a collection of meta-data that tells you what the types and sizes of each column are, and the primary and foreign keys are.
2) For your example of "knowing" that a field should be a drop-down, this almost always means that column value is a foreign key to another table. Your code detects this and builds a listbox out of the values in the parent table.
3) You can go so far as to create a complete form generator for simple tables, where all of the HTML is generated, but you always need a way to override this for the more complex forms. If you do this, your data dictionary should also have column descriptions or captions.
There are many many more ideas, but this is the starting point for what you describe.

Model Data Type versus View Control

I have having a little trouble wrapping my head around the design pattern for MVC when the data type of the model property is very different than what I wish to display in a form. I am unsure of where the logic should go.
Realizing that I am not really sure how to ask the question I think I will explain it as a concrete example.
I have a table of Invoices with a second table containing the InvoiceDetails. Each of the InvoiceDetail items has an owner who is responsible for approving the charge. A given invoice has one or more people that will eventually sign off on all the detail rows so the invoice can be approved. The website is being built to provide the approval functionality.
In the database I am storing the employee id of the person who approved the line item. This schema provides me a model with a String property for the Approved column.
However, on the website I wish to provide a CheckBox for the employee to click to indicate they approve the line item.
I guess my question is this -- how do I handle this? The Model being passed to the View has a String property but the form value being passed back to the Controller will be of the CheckBox type. I see two possible ways...
1) Create a new Model object to represent the form fields...say something like FormInvoiceDetails...and have the business logic query the database and then convert the results to the other type. Then after being submitted, the form values need to be converted back so the original Model objects can be updated.
2) Pass the original InvoiceDetails collection to the View and have code there create render the CheckBox based on the value of the String property. I am still not sure how to handle the submission since I still need to map back the form values to the underlying database object.
Maybe there is a third way if not one of these two approaches?
To make the situation a bit more complicated (or maybe it doesn't), I am rendering the form to allow for the editing of multiple rows (i.e. collection).
Thanks for any insight anybody can provide.
You need a ViewModel, like #Justn Niessner suggests.
Your controller loads the complete model from the database, copies just the fields it needs into a ViewModel, and then hands the ViewModel off to the view for rendering.
I'd use Automapper to do the conversion from Model to ViewModel. It automates all the tedious thingA.x = thingY.x; code.
Here is an additional blog post going over in detail the use of ViewModels in the Nerd Dinner sample.
I believe what you are looking for is the ViewModel.
In cases where you are using a ViewModel, you design the ViewModel to match the exact data you need to show on your page.
You then use your Controller to populate and map your data from your Model in to your ViewModel and back again.
The Nerd Dinner ASP.NET MVC Example has some very good examples of using ViewModels.

Resources