locked
How to consume Web Api for Get method RRS feed

  • Question

  • User1979860870 posted

    Hi

       I have Data Access Layer Solution  , Api Solution , Client Solution. I want to display list of Employees to Client in Datatable.

    Also i want to display Department Name not Id in Datatable

    namespace ProjectManagement.Controllers
    {
        public class EmployeesController : ApiController
        {
            private PMDbEntities db = new PMDbEntities();
    
            // GET: api/Employees
            public IHttpActionResult GetEmployees()
            {
                var results = db.Employees.ToList();
                return Ok(results);
            }
    ---------------------------------
    public partial class Employee
        {
            public int ID { get; set; }
            public string Name { get; set; }
            public string Email { get; set; }
            public string Gender { get; set; }
            public Nullable<int> Salary { get; set; }
            public Nullable<int> DepartmentId { get; set; }
            public string Active { get; set; }
            public Nullable<System.DateTime> CreatedOn { get; set; }
            public Nullable<System.DateTime> UpdatedOn { get; set; }
        
            public Department Department { get; set; }
        }
    
    ---------------------------------
    namespace Client.Controllers
    {
        public class EmployeeController : Controller
        {
            private static RestClient client = new RestClient("http://localhost:40991/api/");
            // GET: Employee
            public ActionResult Index()
            {
                RestRequest request = new RestRequest("Default",Method.GET);
                IRestResponse<List<string>> response = client.Execute<List<string>>(request);
                return View();
            }
        }
    }

    Thanks

    Wednesday, February 17, 2021 5:08 PM

All replies