POST Complex objects to controller - asp.net

I am working on an enterprise scale project where I have a self referencing table called categories as below. Also in my current model I am using following table associations to fetch data. ( using EF6).
I have M-M mapping tables in DB for above M-M relationships.
In my controller GET action result returns the model which has Ilist(all parent categories). Then when the user is selecting items (in view) I am using Ajax to retrieve Ilist for next subset of categories (by passing to controller by Id - return Json result) and dynamically show next to the parent select list as below. ( and I have up to 4 subsets)
As the user is selecting categories, I am using Ajax call to load related categories and create selectlist or dropdownlist dynamically as below:
My question is Since all these data is loaded through Ajax, how can I bind them to my parent model. How can I capture user selected data into one parent model when user is posting the from to controller.
I know I can use Ajax and use Json to capture & transfer to contoller , But I need to use modelview , Can I use partiview to overcome this ?
Please advise the available options..

The key is making sure the name values match the object hierarchy accepted by the post operation. This is certainly doable; it's difficult because several AJAX operations build the UI, but one operation processes it, so you have to ensure the data expressions match the object being posted back.
You can use Html.NameFor() as a workaround to ensuring the naming paths work OK. Collections can make this difficult.

Related

Get request data (GET) in a Symfony (5) formType without using data_class

I'm building a formType to filter products on a collection page. You can set multiple select boxes which makes other auto filled or unnecessary. I want to be able to manipulate the formType based on the data like when using a data_class object. I'm not using data_class because the search isn't a persisted object which is saved to the database. I'm using a GET form.
For example 2 select boxes:
category
productType
When setting a category makes some of the productTypes unnecessary. So i want to not show it.
To do so in the formType I need the data of the request (GET) but I can't find a way to do so.
To retrieve data from the form, you can use $form->getData().
As you're in a GET context, I suspect you can take advantage from FormEvents (take a closer look to POST_SET_DATA event) and get rid of values you don't need.
One other thing I would like to point out, is that you still can use some kind of object that's not persisted to DB, like DTO or whatever.
Forms and entities are not related anyhow, neither in the usage nor in the intentions.

Symfony axios pass only id or entire object?

I have a Booking entity which has a ManyToOne relationship with my Car entity. I use axios to post my data for creating a Booking. I'm not sure if it's better practice to pass my whole Car object to my create function inside my Controller or to only pass the Car's id to the route of the function (which then fetches the Car from my database thanks to Symfonys param converter). Or is there another way which is considered "best practice"?
It depends on your scenario and the way you want to use.
Whenever you have to create an object / row inside the database then you will have to pass the whole object. assuming that the cars has already been created inside the database and you only have to link the booking object with the car than i will prefer you to bind it using ids rather than placing the whole object.
If you place the whole car object than it will increase the retrieval performance but if someday the information of car is changed than you will have to change the information on every booking object in which you placed the car object but if you just bind it with the Car Id than it will always give user the latest information even if the info of Car has been changed.
I thought that it will reduce the performance of the application if we used Id but that is not the case the DBMS use indexing to manage the search and search through id takes not time. It performance is not an issue and yes if you pass a whole object than it will also consume more data (since a large amount of data will be uploaded).

What is the syntax to add a column to the Custom Form list that shows where in WF it is used?

Super simple.
When viewing the list of Custom Forms in Setup, I want to add a column that shows where those Custom Forms are in use (or null if used nowhere).
This is similar in principle to viewing the list of fields, which has a list of forms on which those fields are used.
What is the syntax I can use to add the appropriate column(s) to the view?
As far as I know, there is no linkage in the backend that connects categories (custom forms) to their host objects. This is probably because the list could be massive and the query would take quite a while to execute as it would have to traverse every object in Workfront or each form would store every parent object ID.
Unfortunately, you can't even search for objects by associated category IDs, so if you wanted to build this yourself you would need to query each object and search its categories to see if your custom form appeared.

Displaying data in a datagrid in an Alfresco task form

I have a json array variable defined in my activity workflow definition. Now, I need to present the data of the json array in a datagrid inside a form task. One of those columns should be a check entry filed so that the user may select some rows. After that, I need to get back that data in a subsequent form task (so I need the data to be updated in the json variable so I can read it back, mainly the user selected checks).
Any example to accomplish this? I didnt find almos nothing relating with using datagrids in Alfresco task forms.
thank you!
Miguel

Complex data structure in ViewModel layer of the MVVM

I have large collection of MyFile objects which are linked in all kind of ways between each other like spaghetti.
In addition, from this collection I create smaller subcollections of some items that are equal by some criteria.
(for example all files with the extension .txt, all files that belong to certain directory etc...)
Basically I have complex structure of linked lists in my business logic. Now I want to create ViewModel for this
in order to prepare it for View and this is where I hit the wall. I just can't figure out how to prepare this mess
and still keep everything efficient and organized.
First problem is that wrapping each collection in collectionViewModel by enumerating item by item and creating itemViewModel
will create duplicate itemViewModel for each item (since one item can be contained in several collections)
Second problem is how to keep everything updated? If for example an item1 in business logic changes its reference from item2
to item3, then ViewModels should update them accordingly.
I am really tempted to break from the MVVM pattern here even though I dont want it, and put bussines + presentation logic
in one object/class since this spaghetti structure seems a bit too much for my level of understanding of MVVM.
Thanks
Maybe I'm barking up the wrong tree here, but here goes.
You could have a Model which acts as a repository for all your file objects, and that also exposes an ItemAdded and ItemRemoved event, plus a Query method. You can then have a common ViewModel type that represents your view on this model (a ViewModel), but specializes by composing a query. In this way you can have ViewModel+Query (e.g. all files with extension txt) instance for each view you need to represent. The ViewModel would be responsible for executing the query on your Model (by calling the query method) and then turning the results into an observable collection of file items (or what-have-you). You can update your ViewModel in response to Model changes by subscribing to ItemAdded and ItemRemoved events. If on an ItemRemoved event your ViewModel file items collection contains the item, then remove it. If on an ItemAdded event the item matches the query condition for that ViewModel instance, then add it to the collection.
This allows you to have a single Model for all your files, and then a ViewModel(+Query) instance for each type of view you wish to represent. The ItemAdded and ItemRemoved event allow you to update your ViewModel. As the items in the ViewModels are observable collections, your databound views will update themselves.

Resources