using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using ProductApi.Models; namespace ProductApi.Controllers { [Route("productapi/[controller]")] public class ProductController : ControllerBase { private List productDtos = new List(); public ProductController() { productDtos.Add(new ProductDto { Id = 1,Name="酒精",Price=22.5m }); productDtos.Add(new ProductDto { Id = 2, Name = "84消毒液", Price = 19.9m }); productDtos.Add(new ProductDto { Id = 3, Name = "医用口罩", Price = 55 }); } /// /// 获取单个商品信息 /// /// 商品id /// [HttpGet("get/{id}")] public ProductDto Get(long id) { return productDtos.FirstOrDefault(i => i.Id == id); } /// /// 获取所有商品信息 /// /// [HttpGet("getall")] public IEnumerable GetAll() { return productDtos; } } }