-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathsample2.cs
More file actions
46 lines (39 loc) · 1.13 KB
/
sample2.cs
File metadata and controls
46 lines (39 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Http;
using StoreApp.Models;
namespace StoreApp.Controllers
{
public class SimpleProductController : ApiController
{
List<Product> products = new List<Product>();
public SimpleProductController() { }
public SimpleProductController(List<Product> products)
{
this.products = products;
}
public IEnumerable<Product> GetAllProducts()
{
return products;
}
public async Task<IEnumerable<Product>> GetAllProductsAsync()
{
return await Task.FromResult(GetAllProducts());
}
public IHttpActionResult GetProduct(int id)
{
var product = products.FirstOrDefault((p) => p.Id == id);
if (product == null)
{
return NotFound();
}
return Ok(product);
}
public async Task<IHttpActionResult> GetProductAsync(int id)
{
return await Task.FromResult(GetProduct(id));
}
}
}