Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

MVC API

I have the codes below inside of the Controllers in MVC project. This is API project that I tried to learn.
My question is: how can I create end point for Get(int id)? Should I create a VIEW?

My goal is to create end point, and I will have another website project to call the end point so the website can consume the API service.


  public class LeadController : Controller
    {
        [HttpGet]
        public IEnumerable<CrmModels.Lead> Get(int id)
        {
            CrmModels.Lead l = new CrmModels.Lead();
            List<CrmModels.Lead> li = new List<CrmModels.Lead>();
            if (id == 1)
            {
                l.firstName = "John";
                li.Add(l);
            }
            else
            {
                l.firstName = string.Empty;
                li.Add(l);
            }
            return li;
        }
        //Get api/lead details
        [HttpGet]
        public IEnumerable<string> Get()
        {
            //call crm controllers 
            return new string[] { "", "" };
        }
        //create
        [HttpPost]
        public void Post(CrmModels.Lead l)
        {
            //call crm controllers 
        }
        //update
        [HttpPut]
        public void Put(int id)
        {
            //call crm controllers 
        }
        //delete
        [HttpDelete]
        public void Delete(CrmModels.Lead l)
        {
            //call crm controllers 
        }
    }

Open in new window

Avatar of ITsolutionWizard
ITsolutionWizard
Flag of United States of America image

ASKER

any helps?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial