Demo entry 6663299

mc_3

   

Submitted by mc_3 on Nov 29, 2017 at 21:36
Language: C#. Code size: 491 Bytes.

private readonly IServiceProvider _serviceProvider;

public ClothesController(IServiceProvider serviceProvider)
{
    _serviceProvider = serviceProvider;
}

[HttpGet("")]
public IActionResult Get()
{
    using (var repository = new ClothesRepository(_serviceProvider.GetService<DbContext>()))
    {
        var clothes = repository.GetAll(cloth => cloth.Id);
        if (clothes.Any())
        {
            return Ok(clothes);
        }
        return NotFound();
    }
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).