using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TmplWebApiDemo.Models;
namespace TmplWebApiDemo.Controllers
{
/// <summary>
/// 学生资源集合
/// </summary>
public class StudentsController : ApiController
{
//c r u d
/// <summary>
/// GET / Students/
/// </summary>
public IEnumerable<Student> Get()
{
return Storages.Students;
}
/// <summary>
/// GET / students/zhangsan return entity
/// </summary>
/// <returns></returns>
public Student Get(string name)
{
return Storages.Students.FirstOrDefault(s => s.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
}
/// <summary>
/// 增加post
/// </summary>
/// <param name="entity"></param>
public void Post(Student entity)
{
IList<Student> list = Storages.Students as IList<Student>;
entity.Id = Storages.Students.Max(s => s.Id) + 1;
list.Add(entity);
}
/// <summary>
/// 修改post
/// </summary>
/// <param name="entity"></param>
public void Put([FromUri]string item, [FromBody] Student entity)
{
Delete(item);
Post(entity);
}
/// <summary>
/// 删除
/// </summary>
/// <param name="entity"></param>
public void Delete([FromUri]string item)
{
var entity = Get(item);
IList<Student> list = Storages.Students as IList<Student>;
list.Remove(entity);
}
}
}


然后再使用get

调用 public Student Get(string name)


再Get


再Get,发现 Id:8已经被删除了
