Question:

Can I customise the code of the modules and pages generated by M#?


Answer:

Yes, anything to the last bit!

You can customise the Markup and C# code generated by M# for any module, page, entity class, etc to get your application a 100% exact match to your requirements. That includes:

  • Adding custom properties, form elements, list columns, buttons, links
  • 3rd party Control Integration (Telerik, DevExpress, ...) and Javascript plug-ins.
  • Positioning and layout of items such as adding, removing or re-ordering elements, grouping them together with visual effects, etc.
  • Adding bits of custom HTML, C# or Javascript code at any place in the generated code.
  • Replacing M# implementation of any element, sub-element o even tiny bits related to elements with your own implementation.
  • ...

 

When working with M# you define things initially at a high level (semantically) with the minimum amount of "code" that is theoretically possible.
M# will then assume the implementation details thanks to hundreds of rules, conventions and "common sense" scenarios built into its intelligent engine.

Then if you are not happy with any aspect of the generated code, you can specify your own implementation for that , without having to replace the whole module or element with you own code (unless you want to!).

Example

Let's say you have a Product class associated to a Category class with a property named "Category".

Imagine you might have a data entry form on Product which has a form element on the Category property.

If you just add the form element, without saying anything else, M# will make several assumptions and generate the relevant code:

  • You need a form element in the HTML markup to represent this element.
  • As part of that you need a LABEL control which should have text of "Category".
  • You need some markup code to define a DropDownList control for user input.
  • You need C# code to populate the DropDownList control with all Category records in the database.
  • The DropDownList will need to initially show an empty line saying "---Please select---".
  • If your form supports Editing, then you need some code to set the current selected category from the Product record that is being edited.
  • You need code in your SAVE button click event handler, to read the selected Category record by the user.
  • You need some markup to enforce its RequiredValidation business rule.
  • The RequiredValidation control will need to have a text of "Please specify the category for this product.".
  • ...

It will generate all of that code for you without you having to specify any of it, because all of these can be inferred from the domain model that you have already defined.

Now lets say that in your particular case, you are not happy with some of these assumptions:

  • Instead of showing all Category records, you want the user to select only among categories that are assigned to him (based on a complex business logic).
  • You don't expect more than 3 or 4 categories to be relevant to each user at each point in time. So instead of a Drop-Down-List you want to show a RadioButtonList control.
  • You want the form label to show a smart text saying "Jack, select your category" where "Jack" should be replaced by the first name of the user who has logged in!

In order to implement such customisation, all you need to do is to set the relevant settings, and nothing more. In this case you will set the following settings on your form element in M#:

  • Set "Data Source" to "App.Context.User.GetPermittedCategories()"
  • Set "Control" to "DropDownList"
  • Set "Label Text" to c#:App.Context.User.FirstName + ", select your category"