How to mount a message array and send to a Badrequest

Asked

Viewed 41 times

1

I understood in the previous post the badrequest. I need to assemble a message for it as follows. If a commodity does not have a Serial Number, I must assemble a message and send it. Let’s say my query returns me 7 items and these two do not have Serial Number. These two should compose the Badrequest message. Type like this:

if(Num.SerialNumber == nul)
{
  //aqui vai a mensagem. Veja que é um array, pois tenho dois caras sem o SN
}

then, in the result of my Action do

return BadRequest(mensagem);

where message would be the guys without the SN.

1 answer

0

If you are using WebApi can return a list of objects, follow example:

Class:

    public class Aparelho
    {
        public int ID { get; set; }
        public string SN { get; set; }
        public string Nome { get; set; }
    }

Controller

    [HttpGet]
    [Route("MyEndPoint")]
    public HttpResponseMessage MyEndPoint()
    {

        List<Aparelho> aparelhos = new List<Aparelho>
        {
            new Aparelho{ID=1, SN= null, Nome= "Aparelho 1"},
            new Aparelho{ID=2, SN= null, Nome= "Aparelho 2"},
            new Aparelho{ID=3, SN= null, Nome= "Aparelho 3"},
        };

        return Request.CreateResponse(HttpStatusCode.BadRequest, aparelhos);
    }

Browser other questions tagged

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