Pass filtered data by GET request (params) controller (Asp Net c#)

  Uncategorised

I am trying to send filtered data according to what the front sends by parameter, but in doing so it is returning to me the entire value of the logic I put in the "var", not in the IFs that I pointed to

       public async Task<ActionResult> GetRelatorio(
        int? id = null,
        int[] situacao = null)
    {
        IQueryable<OrdemServico> qos = db.OrdemServico
                       .Include(os => os.ClienteNavigation)


        if (situacao != null && situacao.Length > 0)
        {
            qos = qos.Where(os => situacao.Contains(os.Situacao));
        }
        else
        {
            qos = qos.Where(os => os.Situacao != 6);
        }

        try
        {
            var emDia = db.OrdemServico.Where(o => (o.Situacao == 0 || o.Situacao == 1 || o.Situacao == 3 || (o.Situacao == 2 && o.StatusNegocio == 0))
            && o.DataSignificativa != null && (o.DataSignificativa.Value - DateTime.Now).TotalDays == 0).Count();

            var atrasadas = db.OrdemServico.Where(o => (o.Situacao == 0 || o.Situacao == 1 || o.Situacao == 3 || (o.Situacao == 2 && o.StatusNegocio == 0))
            && o.DataSignificativa != null && (o.DataSignificativa.Value - DateTime.Now).TotalDays < 0).Count();

            var noPrazo = db.OrdemServico.Where(o => (o.Situacao == 0 || o.Situacao == 1 || o.Situacao == 3 || (o.Situacao == 2 && o.StatusNegocio == 0))
            && o.DataSignificativa != null && (o.DataSignificativa.Value - DateTime.Now).TotalDays > 0).Count();

            return Json(new { emDia = emDia, atrasadas = atrasadas, noPrazo = noPrazo });      

        }
        catch (Exception)
        {
            return Json(new { error = "Erro ao consultar dados" });
        }
    }

The front asks for the request like this

 this.$axios.get("/Operacional/GetRelatorio", axiosParams)

Source: Visual Studio Questions

LEAVE A COMMENT