Does mvc 4 application need another model to return aggregate data on an existing table and model - asp.net-mvc-4

I have a table (and model) with the following properties in an asp.net MVC 4 application:
TV Table
height
width
depth
type
brand
cost
When the user answes a question about the space that they have for the TV I then do an ajax call to determine which types are possible to fit into the space they have specified. Which type of TV type they want is the following question, so some options may need to be disabled. The SQL for what types fit in the space is "select distinct type from TV where height < #height and width < #width and depth < #depth".
Should I:
1. create a new model that I call from the TV controller just to return the distinct types
2. add a method to the TV model that I call from the TV controller that just returns a list of string with the types that fit

Depends on what you want to display to the user based on her selection' e. g.
If you want to display TV name + its description then returning a list of TV model will make sense.
If you are just going to display a list of TV names in combo box, then returning a list of string will suffice.
Calling a new action make sense in both cases IMHO.
EDIT:
For 2 - I want to return a list of string - should I create a new data model for this, or add a method in the existing TV data model that returns a list of string?
To expand on above query, since its not clear (at least I do not visualize it) from your question i will assume few things.
Case 1: You are displaying a view say "TVSelection" to the user that does not contain list of TVModels. In this view you are expecting user to enter three values i.e. Width, Height, Depth. Now when user enter these values, she can submit the form or you can fetch the TV Brand name list on Lost Focus event as well. In any case, the question would be are you updating existing view by populating the combo box or you are displaying a new view. I am assuming you are updating existing "TVSelection" view by the means of making an AJAX call. In that case you can just call a method on your controller (which displayed the "TVSelection" view) that returns a list of TV Brand names.
Case 2: You are displaying "TVSelection" view that already has a list of TVModel objects and you update it dynamically on selection of required field (filtering). In this case you can add a method in the TVModel itself to filter names only that matches the user selection.
I found these links relevant 1 & 2.
Hope that make sense.
Please add more details to your question if this does not answer your question.

Related

How to obtain the record ID of the selected item in a dropdown list in google app-maker

Summary
Obtaining the record ID of the selected item in a drop-down list or radio-button UI appears to be a common question, but I have not found the answer for Google AppMaker despite months of searching.
The example use case: is I wish to edit a product that belongs to a family:
Product - (N:1) --> Family
Product - (M:N) --> FeatureValues
Example
The product belongs to the family Credit Card.
The credit-card family has the following features: |Contactles
|Near field
|Rates
|Chip & Pin|
In the edit form if I change the family the product belongs to then the list of features will change and new values for the features will need to be entered. (Dynamic form)
Hierarchy table
The family, features and permitted values are held in a single hierarchy table:
Family
|
Features
|
Values
newValue._key appears to only work for text-box UI items.
Dropdown list:
widget.datasource.item.Id or _key
provides the Product ID of the parent data source, ProductById (because I am editing a single product)
widget.datasource.selectKey(newValue._key); returns undefined
Sample code
Drop-down-list
OnValueChange event:
//update the features drop-down based on the taxonomy family selected
app.datasources.TaxonomyChildren.query.parameters.parent_fk = app.datasources.TaxonomyFamilies.item.Id;
app.datasources.TaxonomyChildren.load();
If I can pick up the record ID for the selected family in the dropdown list I can set a query.filter.parameter to show the features and values for the newly selected family.
Note: if it is a case you cannot create 'dynamic' forms in Google app-maker, then I'll stop as this has exhausted a lot of time.
Markus wrote:
So leave the options and value settings but in the onValueEdit run your query against TaxonomyChildren by passing in newValue.id to the query
Great Markus, that worked. On the drop-down ValueEdit event I call the function loadTaxonomyChildById(newValue.Id); passing it the Id of the selected TaxonomyFamily, changing the features displayed.

The method getKids() is undefined for the type PDField

https://issues.apache.org/jira/browse/PDFBOX-2148
When there are multiple copies with the same field name, the getFullyQualifiedName for each kid in the list of PDField objects returns the name of the parent, followed by .null. So if the parent field is called Button2 and it has 4 instances the result of printing out all the names will be:
Button2.null
Button2.null
Button2.null
Button2.null
According to the comments to the question, the OP refers to PDFBox 2.0.x versions, in particular 2.0.6.
getKids()
The method getKids() is undefined for the type PDField
In PDFBox 2.0.6 there are two immediate sub-classes of PDField. Different variants of the former (1.8.x) getKids() method are implemented in there:
PDNonTerminalField - the method retrieving the kids in this class is getChildren() and returns a List<PDField>, a list of form fields.
PDTerminalField - the method retrieving the kids in this class is getWidgets and returns a List<PDAnnotationWidget>, a list of widget annotations.
name of the parent, followed by .null
When there are multiple copies with the same field name, the getFullyQualifiedName for each kid in the list of PDField objects returns the name of the parent, followed by .null
This is not the case in PDFBox 2.0.x.
In the sample document attached to the PDFBox issue PDFBOX-2148 PDFBox now correctly finds only a single field which appropriately is named "Button2". This field is a PDTerminalField and has 4 widget annotations. The class of the latter, PDAnnotationWidget, has no getFullyQualifiedName method, so there are no ".null" names.
Thus, this problem is gone.
FQN of duplicate fields
(from the OP's comment responding to "What exactly is your question?")
how to get Fully Qualified Name of duplicate fields in pdfbox
There are no duplicate fields in (valid) PDFs, for a given name there is at most a single field which may have multiple widgets. Widgets do not have individual FQNs.
Thus, what you call "duplicate fields" in your example document actually is a single field with multiple widgets; the name of that field is "Button2" and can be retrieved using getFullyQualifiedName().
which page which form field
(from the OP's comments to this answer)
but how to get current page no in pdfbox.. for example there are 3 page and in page 2 there is a form field so how can i get which page which form field ?
All PDAnnotation classes, among them PDAnnotationWidget, have a getPage() method returning a PDPage instance.
BUT: As specified in ISO 32000-1, annotations (in particular form field widgets) are not required to have a link to the page on which they are drawn (except for screen annotations associated with rendition actions).
Thus, the above mentioned method getPage() may return null (probably more often than not).
So to determine the respective pages of your widgets, you have to approach the problem the other way around: Iterate over all pages and look for the annotation widgets in the respective annotation array.
For PDFBox 1.8.x you can find example code in this stackoverflow answer. With the information given in the previous parts of this answer it should be easy to port the code to PDFBox 2.0.x.
checkbox and radio button
(also from the OP's comments to this answer)
one more issue if i am using checkbox and radio button both then field.getFieldType() output is Btn for both. how to identify it?
You can identify them by inspecting the field flags which you retrieve via fields.getFieldFlags():
If the Pushbutton flag is set (PDButton.FLAG_PUSHBUTTON), the field is a regular push button.
Otherwise, if the Radio flag is set (FLAG_RADIO), the field is a radio button.
Otherwise, the field is a check box.
Alternatively you can check the class of the field object which for Btn may be PDPushButton, PDRadioButton, or PDCheckBox.
Beware: If a check box field has multiple widgets with differently named on states, this check box field and its widgets act like a radio button group! And not only in theory, I've seen PDFs with such check box fields in the wild.
To really be sure concerning the behavior of the fields, you therefore also should compare the names of the on states of all the widgets of a given check box.

MVC Complex ViewModel

I need to build a sample MVC UI app using Kendo UI.
I have 2 multiselect widgets for airline names and airport names respectively and below I have a grid with airline airport data.
Now when I select airlines or airports in the multiselect, upon clicking a Fetch button, the grid should refresh.
I created a ViewModel named AirlineAirportViewModel for containing List<Airlines>, List<Airports> and List<AirlineAirports>.
I instantiate the List<AirlineAirports> in the Get action method of the controller and fill the other two lists getting distinct airline and airport values from the List<AirlineAirports>.
While posting on filter button click, I am able to get action parameters as 2 List<string> types which contain only the selected multiselect items
Instead of that, I want this action parameter of type AirlineAirportViewModel so that in future, I will be able to add more filter widgets and the number of parameters stay one only.
Now, am I approaching this in the right way ? If I need the ViewModel as action parameter, where should I store the selected items from the multiselects ?

Titanium get current view on scrollableView and add an item

I have a scrollableView with several views inside and I'd like to add item to some of these view if they meet a certain criteria, like if they have data attached or not. Also I'm using Alloy, here's my markup
<ScrollableView id="scrollableView">
<View id="view" class='coolView'></View>
...
</ScrollableView>
To know if there are data attached I check the currentPage attribute like so:
function updateCurrentView(e) {
currentView = e.currentPage;
}
But I have no idea how to add an item to the current View.
Edit: To add some clarification, I have a label which when clicked allow me to choose two currencies, when chosen these currency pairs are saved in the database and should be displayed instead of the label. So my guess was to check whether the current view has currency pair saved.
There are 2 things to take care of here:
1.Whenever a currency is selected,immediately label on that particular view will change.
2.Whenever the scrollableView is loaded,it must always refer to the database if a currency is selected.
First one can be done as:
1.Get the instance of scrollableView using the getView method of alloy controller.Pass the id of the scrollableView to it.Lets call it myScrollableView.Refer this for more info.
http://docs.appcelerator.com/titanium/latest/#!/api/Alloy.Controller
2.Use var currentView=myScrollableView.getCurrentPage() to the get the current page which will be a number.
3.Now use the scrollableView instance to get all the views.
var viewArray=myScrollableView.getViews();
4.viewArray[currentView] will give you the view of current page.After you have got the view you can change the desired label using:
viewArray[currentView].children[positionOfTheView]
The "positionOfTheView" can be obtained by printing the viewArray[i].children array using Ti.API.info.
Second thing can be accomplished as follows:
1.Get the instance of scrollableView using the getView method of alloy controller.Pass the id of the scrollableView to it.Lets call it myScrollableView.Refer this for more info.
http://docs.appcelerator.com/titanium/latest/#!/api/Alloy.Controller
2.Now use the scrollableView instance to get all the views.
var viewArray=myScrollableView.getViews();
3.This is a JavaScript array of all the views in the scrollableView. Now iterate through this array and according to the data in the database,change the concerned view using:
viewArray[i].children[positionOfTheView]
The "positionOfTheView" can be obtained by printing the viewArray[i].children array using Ti.API.info.

how to detect which cell is clicked then generate next view according to it in iphone uitableview?

hello all i am new to iphone development i am working on a application called flash cards...
my problem is i want to generate flash cards from database...
here is some code to explain
home screen----
index View
categoryView
TileView
bookmarks
search
download
indexView is a uitableView
category1(section header title)
flashCard1
flashcard2
flashcard3
category2(section header title)
flashcard4
flashcard5
flashcard6
now i want to pass the flashcard's from categoryid so in different category flashcards related to the category should be shown. and when click on first flash card the flashcardid should be passed to the query from which i can generate the questions.and also the flashCradsmust be distinct by category type..for example..if categorytype=1 the the flash cards should be of type multiple choice if categorytype=2 the flashcards should be of type vocabulary if type=3 flashcards= graphics observation
here is some database info----
cardCategoryInfo(table)
categoryId
categoryName
CategoryType
flashCardInfo(table)
flashCardId
categoryId
flashCardName
flashCardQuestionInfo(table)
questionId
flashCardId
questionText
questionTotalOption
isAudioAvailable
questionAnswer
flashCardMultipleAnswer(table)
questionId
optionId
optionText
someone help me
You need to implement tableView:didSelectRowAtIndexPath: in your UITableViewDelegate. The second argument is the index path, which will give enough information to identify the specific flashcard you want to show.
You will find further information in the Table View Programming Guide and the View Controller Programming Guide.
Basically you get the information from indexPath parameter of tableView:didSelectRowAtIndexPath: in your implementation of UITableViewDelegate.
Furthermore, you can tag your elements and then pass that tag to your query method. Set tag on element when it is created and then in the handler get the tag first and do work accordingly.