public IHttpActionResult Post(int distritoId, int baseId, [FromBody] OrderSelectionModel orderSelectionModel) { var routeCode = BuildRouteCode(orderSelectionModel.StartDateTime, orderSelectionModel.IdVehicle, orderSelectionModel.IdVehicleType, orderSelectionModel.LogisticsCycleType, distritoId, baseId); // Agrupo por OrderId var odByOrderId = orderSelectionModel.OrderDetailList.Where(od => od.Cuaderna != 0).GroupBy(od => od.OrderId); // foreach (var group in odByOrderId) { var order = EntityDao.FindById(group.Key); group.ToList().ForEach(od => { // Se asigna el ajuste y la cuaderna asignada var orderDetail = order.OrderDetails.Single(item => item.Id == od.Id); orderDetail.Ajuste = od.Ajuste; orderDetail.Cuaderna = od.Cuaderna; orderDetail.Estado = OrderDetail.Estados.Ruteado; }); // Programo por Orden RoutingService.Programming(order, routeCode, orderSelectionModel.IdVehicle, orderSelectionModel.StartDateTime, orderSelectionModel.LogisticsCycleType, orderSelectionModel.IdVehicleType); } return(Ok()); }