I am trying to insert sections in a Database, to the whole insert I use with C # in controllers (My project is a WebApi). What I want is for you to make an insert in each cycle of the for. But the controller goes only once, and that's when the whole angular is finished (I do not know if I explain myself well). This is what I want to do because I want to save all the sections with a single button. (Not for each section that I want to create that there is a button and that from there go to the controller)
My code in angularJs is:
for (var i = 0; i < $scope.ListaTempProductos.length; i++) {
var Seccion = new Object();
var idUlt = $scope.SeccionUltima;
var idSeccionObtenida = idUlt[0]['idSeccion'];
DetalleSeccion.idSeccion = idSeccionObtenida;
DetalleSeccion.idProducto = $scope.ListaTempProductos[i]['idProducto'];
CrearDetalleSeccion(JSON.stringify(DetalleSeccion));
}
for (var i = 0; i < $scope.ListaTempPlatos.length; i++) {
var Seccion = new Object();
var idUlt = $scope.SeccionUltima;
var idSeccionObtenida = idUlt[0]['idSeccion'];
DetalleSeccion.idSeccion = idSeccionObtenida;
DetalleSeccion.idPlato = $scope.ListaTempPlatos[i]['idPlato'];
CrearDetalleSeccion(JSON.stringify(DetalleSeccion));
}
function CrearDetalleSeccion(detalle) {
//Crea detalle tercero
var idDetalle = $http.post('/api/DetalleSeccion/PostDetalleSeccion', detalle).then(function (response) {
alert("guardado");
});
}
My html is:
<form class="form-inline" id="formSeccionDetalle" style="margin:10px; visibility:hidden; background-color:azure;">
<div class="form-group" style="margin:10px;">
<label for="nombre">Seleccione los productos que iran en esta sección:</label>
<div>
<select class="form-control" id="listaProductosParaDetalle">
<option ng-repeat="dto in productos"> {{dto.nombreProducto}} </option>
</select>
</div>
<div>
<button type="submit" class="btn btn-toolbar btn-circle" id="AgregarProducto"><i class="fa fa-plus fa-2x" aria-hidden="true"></i></button>
</div>
</div>
<div class="form-group" style="margin:10px;">
<label for="nombre">Seleccione los platos que iran en esta sección:</label>
<div>
<select class="form-control" id="listaPlatosParaDetalle">
<option ng-repeat="dto in platos"> {{dto.nombrePlato}} </option>
</select>
</div>
<div>
<button type="submit" class="btn btn-toolbar btn-circle" id="AgregarPlato"><i class="fa fa-plus fa-2x" aria-hidden="true"></i></button>
</div>
</div>
<div class="form-group" style="margin:10px;">
<div>
<ul>
<li ng-repeat="x in ListaTempProductos">
{{ x.nombreProducto }}
<button class="btn btn-danger" id="btnBorrar" ng-click="EliminarProducto($index)">
<i class="fa fa-times" aria-hidden="true"></i>
</button>
</li>
</ul>
<ul>
<li ng-repeat="x in ListaTempPlatos">
{{ x.nombrePlato }}
<button class="btn btn-danger" id="btnBorrar" ng-click="EliminarPlato($index)">
<i class="fa fa-times" aria-hidden="true"></i>
</button>
</li>
</ul>
<button class="btn btn-danger" id="guardarTodo">
<i class="fa fa-2x fa-save" aria-hidden="true"></i>
</button>
</div>
</div>
</form>
Could someone explain to me in a summarized way how I can alter the order of this?