Customizing Json consumption - Web API

2

I have the following information in Json:

[
  {
    "$id": "1",
    "Cditemcontacli": 1.0,
    "Cdcontacli": 1.0,
    "Descricao": "Produto 1"
  },
  {
    "$id": "2",
    "Cditemcontacli": 2.0,
    "Cdcontacli": 2.0,
    "Descricao": "Produto 2"
  },
  {
    "$id": "3",
    "Cditemcontacli": 3.0,
    "Cdcontacli": 2.0,
    "Descricao": "Produto 3"
  },
  {
    "$id": "4",
    "Cditemcontacli": 4.0,
    "Cdcontacli": 3.0,
    "Descricao": "Produto 4"
  }]

Controller:

//GET: api/Itemcontaclis/5
        [ResponseType(typeof(Itemcontacli))]
        public async Task<IHttpActionResult> GetItemcontacli(decimal id)
        {
            Itemcontacli itemcontacli = await db.Itemcontacli.FindAsync(id);
            if (itemcontacli == null)
            {
                return NotFound();
            }

            return Ok(itemcontacli);
        }

Api web config:

config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{Action}/{id}",
                defaults: new { id = RouteParameter.Optional }

I want to bring only those who have Cdcontacli:2.0 . If you look at Cdcontacli:2.0 it repeats itself. Is it possible to find the two together somehow? Thank you.

    
asked by anonymous 22.09.2015 / 20:27

1 answer

0

Solved with the following code implemented in the controller:

// GET: api/Itemcontaclis/cdContaCli
        public async Task<IHttpActionResult> GetPelaConta(decimal idContaCli)
        {
            return Ok(await db.Itemcontacli.Where(x => x.Cdcontacli == idContaCli).ToListAsync());
        }
    
23.09.2015 / 16:56