10/13/2017 - 8:56 AM


The client side expects sometimes objects with calculated properties rather than only the ones provided by the existing services, this is achieved server side with automapper and dynamic.

        public IActionResult GetVehicles()
            var vehicles = Authorization.GetDevices(Authorization.ClientToken);

            var vehiclesUpgraded = new Dictionary<int, dynamic>();

            foreach (var vehicle in vehicles)
                dynamic vehicleUpgraded = _mapper.Map<ExpandoObject>(vehicle.Value);
                vehicleUpgraded.DeviceTypeExpanded = vehicle.Value.DeviceType.ToString();
                vehiclesUpgraded.Add(vehicle.Key, vehicleUpgraded);

            return new JsonResult(
                    Vehicles = vehiclesUpgraded