Access a variable from another method in c #

0

I want to access the variable datos

private CustomValidator ActualizarBodega(decimal idDetPedido, string proceso)
        {
            var error = new CustomValidator();

                var datos = (from GridViewRow row in bodegasGridView.Rows
                let bodega = (Label) row.FindControl("bodegaLabel")
                let cantidad = (TextBox) row.FindControl("cantidadTextBox")
                let disponible = (Label) row.FindControl("disponibleLabel")
                let idArticuloBodega = (Label) row.FindControl("idArticuloBodegaLabel")
                let idBodega = (Label) row.FindControl("idBodegaLabel")
                select new DistribucionBodega
                       {
                           Bodega = bodega.Text,
                           Cantidad = Convert.ToInt32(string.IsNullOrEmpty(cantidad.Text) ? "0" : cantidad.Text),
                           Disponible = Convert.ToInt32(disponible.Text),
                           IdArticuloBodega = Convert.ToInt32(idArticuloBodega.Text),
                           IdBodega = Convert.ToDecimal(idBodega.Text)
                       }).ToList();

            if (datos.Sum(t => t.Cantidad) != Convert.ToInt32(TextBoxCantidad.Text))
            {
                error.ErrorMessage = "La cantidad distribuida no concuerda con la cantidad del articulo.";
                return error;
            }
}

How do I access it or how could I declare it to access it from another method?

    
asked by Andrex_11 02.11.2018 в 15:05
source

1 answer

0

You could return both data as a response if you create a class such as

public class ActualizarBodegaResult
{
    public List<DistribucionBodega> datos {get;set;}
    public CustomValidator error {get;set;}
}

and then you return this as an answer

private ActualizarBodegaResult ActualizarBodega(GridView bodegasGridView, decimal idDetPedido, string proceso)
{
    var error = new CustomValidator();

    var datos = (from GridViewRow row in bodegasGridView.Rows
                    let bodega = (Label) row.FindControl("bodegaLabel")
                    let cantidad = (TextBox) row.FindControl("cantidadTextBox")
                    let disponible = (Label) row.FindControl("disponibleLabel")
                    let idArticuloBodega = (Label) row.FindControl("idArticuloBodegaLabel")
                    let idBodega = (Label) row.FindControl("idBodegaLabel")
                select new DistribucionBodega
                   {
                       Bodega = bodega.Text,
                       Cantidad = Convert.ToInt32(string.IsNullOrEmpty(cantidad.Text) ? "0" : cantidad.Text),
                       Disponible = Convert.ToInt32(disponible.Text),
                       IdArticuloBodega = Convert.ToInt32(idArticuloBodega.Text),
                       IdBodega = Convert.ToDecimal(idBodega.Text)
                   }).ToList();

    if (datos.Sum(t => t.Cantidad) != Convert.ToInt32(TextBoxCantidad.Text))
    {
        error.ErrorMessage = "La cantidad distribuida no concuerda con la cantidad del articulo.";
    }

    return new ActualizarBodegaResult()
    {
        datos = datos,
        error = error
    }
}

Analyze the return as it returns data and error using that class, you must also pass the grid as parameter

then when you invoke the functionality you would use

ActualizarBodegaResult result = ActualizarBodega(...);

and you will have access to error and data

    
answered by 02.11.2018 / 15:15
source