using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication2.Models
{
public class Detail
{
public int ID { get; set; }
public string Name { get; set; }
public string Address { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WebApplication2.Models;
namespace WebApplication2.Controllers
{
public class DetailsController : ApiController
{
Detail[] details = new Detail[]
{
new Detail{ID=1, Name="Employee1", Address="Address1"},
new Detail{ID=2, Name="Employee2", Address="Address2"},
new Detail{ID=3, Name="Employee3", Address="Address3"},
new Detail{ID=4, Name="Employee4", Address="Address4"},
new Detail{ID=5, Name="Employee5", Address="Address5"},
new Detail{ID=6, Name="Employee6", Address="Address6"}
};
public IEnumerable<Detail> GetAllDetail()
{
return details;
}
public IHttpActionResult GetDetailByID(int id)
{
var detail = details.FirstOrDefault((p) => p.ID == id);
if(detail==null)
{
return NotFound();
}
return Ok(detail);
}
}
}