I just uploaded anew version of that sample which uses a multiple select.
Here is what was needed:
- Retrieve all products
- Retrieve the order details that belong to the current order - invoke the
getOrderDetailsmethod and filter by OrderID equal to${parameters.Id}.
Set the $expand parameter toProduct. Set the filter from the query builder
- Handle the Then event of the
getOrderDetailsmethod and set a new page property with NamecurrentProductsand Value${result.value.map(orderDetail => orderDetail.Product)}.
Now that all needed data is in retrieve it is time to add the multiple select dropdown.
- Add a new form field with type
lookup. - Convert the Form to TemplateForm.
- Configure the DropDownList like this:
This will display the currentProducts page property and also update it if the user checks/unchecks items from the dropdown.
To handle the server-side updates you need to create a custom server method.
- Add a help class that will be used to pass the parameters - the OrderID and current products.
public class SetProductsRequest { public Product[] Products { get; set; } public int OrderID { get; set; } } - Inject the Entity Framework Context in the constructor of the ServerMethodsController.
private readonly SampleContext context; public ServerMethodsController(SampleContext context) { this.context = context; } - Add a new method that updates the database.
[HttpPost] public IActionResult UpdateProducts([FromBody]SetProductsRequest request) { var order = context.Orders .Where(o => o.Id == request.OrderID) .Include(o => o.OrderDetails) .FirstOrDefault(); if (order != null) { try { // First remove all OrderDetails foreach (var orderDetail in order.OrderDetails) { context.Remove(orderDetail); } // Then add new ones foreach (var product in request.Products) { var orderDetail = new OrderDetail() { OrderId = request.OrderID, ProductId = product.Id }; context.Add(orderDetail); } // Persist changes context.SaveChanges(); return Ok(); } catch (Exception ex) { return BadRequest(new { error = new { message = ex.Message } }); } } return NotFound(); }
The complete code is available here.
Finally invoke that method in Radzen by handling the Submit event of the TemplateForm. The request parameter is set to { orderId: ${parameters.Id}, products: ${currentProducts} }






