Webservice - Sending objects via Httpget

Asked

Viewed 38 times

1

I’m developing a service Get data with feedback in JSON, following the model below:

Survey:

{
[SchSISQST].[Qst]. QstAltDat
[SchSISQST].[Qst]. QstNom
[SchSISQST].[Qst]. QstAtvSit
[SchSISQST].[QstGrp]. QstGrpNom
[SchSISQST].[QstSbo]. QstSboNom
}

I already have following structures of my Entity Framework Core:

Classes:

Questionario.Cs

 public partial class Questionario
{
    public short QstCod { get; set; }
    public string QstNom { get; set; }
    public bool QstAtvSit { get; set; }
    public decimal QstCpfAltNum { get; set; }
    public DateTime QstAltDat { get; set; }
}

Grupoquestionario.Cs

public partial class GrupoQuestionario
{
    public short QstGrpCod { get; set; }
    public string QstGrpNom { get; set; }
    public decimal QstGrpCpfAltNum { get; set; }
    public DateTime QstGrpAltDat { get; set; }
}

Subgrupoquestionario.Cs

public partial class SubGrupoQuestionario
{
    public short QstSboCod { get; set; }
    public short QstGrpCod { get; set; }
    public string QstSboNom { get; set; }
    public decimal QstSboCpfAltNum { get; set; }
    public DateTime QstSboAltDat { get; set; }
}

Questionsubgroup.Cs

 public partial class QuestionarioSubGrupo
{
    public short QstCod { get; set; }
    public short QstSboCod { get; set; }
    public short QstGrpCod { get; set; }
}

Listarquestionariosrepository.Cs

public class ListarQuestionariosRepository
{
    public void ListarQuestionario()
    {
        using(SisquestDataContext Db = new SisquestDataContext())
        {
            //return Db.Set<Questionario>().ToList();

            var finalQuest = (from qst in Db.Questionario
                    join qstSubGrp in Db.QuestionarioSubGrupo on qst.QstCod equals qstSubGrp.QstCod
                    join qstGrup in Db.GrupoQuestionario on qstSubGrp.QstGrpCod equals qstGrup.QstGrpCod
                    join qstSubGrpQuest in Db.SubGrupoQuestionario on qstSubGrp.QstSboCod equals qstSubGrpQuest.QstSboCod
                    select new { qst.QstAltDat, qst.QstNom, qst.QstAtvSit, qstGrup.QstGrpNom, qstSubGrpQuest.QstSboNom }).ToList();

        }
    }

}

Equivalent to my query that brings the 5 fields I need to capture in format JSON, down:

   SELECT a.QstAltDat, a.QstNom, a.QstAtvSit, c.QstGrpNom, d.QstSboNom FROM SchSISQST.Qst a INNER JOIN SchSISQST.QstSboAsa b ON b.QstCod = a.QstCod INNER JOIN SchSISQST.QstGrp c ON c.QstGrpCod = b.QstGrpCod INNER JOIN SchSISQST.QstSbo d ON d.QstSboCod = b.QstSboCod

Ilistarquestionariosrepository.Cs

public interface IListarQuestionariosRepository
{
    IEnumerable<Questionario> ListarQuestionario { get; }
    //IEnumerable<GrupoQuestionario> GrupoQuestionario { get; }
    //IEnumerable<QuestionarioSubGrupo> QuestionarioSubGrupo { get; }
}

Listarquestionariosmodel.Cs

[Serializable]
public class ListarQuestionariosModel
{
    public DateTime QstAltDat { get; set; }
    public string QstNom { get; set; }
    public bool QstAtvSit { get; set; }
    public string QstGrpNom { get; set; }
    public string QstSboNom { get; set; }
}

Sisquestcontroller.Cs

[HttpGet]
    public ActionResult ListarQuestionarios()
    {
        //return _contextSisquest.Questionario.ToList();
        ListarQuestionariosModel listarQuestionariosModel = new ListarQuestionariosModel();
        try
        {


            //var listarQuestionariosRepository = new ListarQuestionariosRepository();
            //listarQuestionariosRepository.ListarQuestionario();
            foreach (var item in collection)
            {

            }
        }
        catch (Exception ex)
        {
            return BadRequest(ex);
        }
    }

I’m making a mistake in ActionResult ListarQuestionarios called 'not all code paths Return value' and would like to try to understand this, another point is to call the 5 members as return in my foreach following the ListarQuestionariosModel that I created, because I have here a question of taking two fields from other tables, that I had not yet done that are QstGrpNom and QstSboNom, when it is only 1 table I can mount the get service, there is some way using good practices to be able to return the fields based on the LINQ what have I put together and other parts of the rules? Thank you personally.

  • 1

    Leandro, your question is very vague. The error you put in the end itself says that your action does not return value. Your controller is very incomplete, it seems that you yourself do not know very well what to do there and not even a view of it presented with what/how you want to display. Try to improve the issue and make it more objective, it will be easier to find help.

  • Ok, thank you. I will analyze it better and return George Wurthmann

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.