using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Mvc; namespace Basic.Controllers { /// /// Summary for CrudActionsController /// [Route("/products")] [Produces("application/json")] [ApiExplorerSettings(GroupName = "v1")] public class CrudActionsController { /// /// Creates a /// /// /// ## Heading 1 /// /// POST /products /// { /// "id": "123", /// "description": "Some product" /// } /// /// /// /// [HttpPost(Name = "CreateProduct")] public Product Create([FromBody, Required] Product product) { return product; } /// /// Searches the collection of products by description key words /// /// A list of search terms /// [HttpGet(Name = "SearchProducts")] public IEnumerable Get([FromQuery(Name = "kw")] string keywords = "foobar") { return new[] { new Product { Id = 1, Description = "A product" }, new Product { Id = 2, Description = "Another product" }, }; } /// /// Returns a specific product /// /// The product id /// [HttpGet("{id}", Name = "GetProduct")] public Product Get(int id) { return new Product { Id = id, Description = "A product" }; } /// /// Updates all properties of a specific product /// /// /// [HttpPut("{id}", Name = "UpdateProduct")] public void Update(int id, [FromBody, Required] Product product) { } /// /// Updates some properties of a specific product /// /// /// [HttpPatch("{id}", Name = "PatchProduct")] public void Patch(int id, [FromBody, Required] IDictionary updates) { } /// /// Deletes a specific product /// /// [HttpDelete("{id}", Name = "DeleteProduct")] public void Delete(int id) { } } public enum ProductStatus { All = 0, OutOfStock = 1, InStock = 2 } /// /// Represents a product /// public class Product { /// /// Uniquely identifies the product /// public int Id { get; set; } /// /// Describes the product /// public string Description { get; set; } public ProductStatus Status { get; set; } public ProductStatus? Status2 { get; set; } } }