How to mount a message array and send in a BadRequest [duplicate]

1

I understood in the previous post the badrequest. I need to put a message to him as follows. If a merchandise does not have a Serial Number, I must put together 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. 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 I do

return BadRequest(mensagem);

where message would be the guys without the SN.

    
asked by anonymous 16.03.2018 / 19:57

1 answer

0

If you are using WebApi you can return a list of objects, following 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);
    }
    
16.03.2018 / 20:11