Click here to Skip to main content
15,886,724 members
Articles / Web Development / HTML

A simple POC using ASP.NET Web API, Entity Framework, Autofac, Cross Domain Support

Rate me:
Please Sign up or sign in to vote.
4.92/5 (43 votes)
27 Oct 2012CPOL11 min read 339.3K   8.3K   154  
The purpose of this article is to create a proof of concept to demonstrate the feasibility of ASP.NET Web API Beta Version.
using Application.Common.Contracts;
using Application.Common.Filters;
using Application.Model.DTO;
using Application.Service.Contracts;
using System.Web.Http;

namespace Application.API.Controllers
{
    public class CustomersController : ApiController
    {
        ILogService loggerService;
        ICustomerService _customerService;

        public CustomersController(ILogService loggerService, ICustomerService customerService)
        {
            this.loggerService = loggerService;
            this._customerService = customerService;
        }

        /// <summary>
        /// To validate Customer
        /// </summary>
        /// <returns></returns>
        [EnableCors]
        [System.Web.Http.AcceptVerbs("GET", "POST")]
        [System.Web.Http.HttpGet]
        public CustomerDTO ValidateCustomer(int id, string password)
        {
            loggerService.Logger().Info("Calling with parameter as : id and password: " + id + " and " + password);
            return _customerService.ValidateCustomer(id, password);
        }

        /// <summary>
        /// To Save Customer
        /// </summary>
        /// <returns></returns>
        [EnableCors]
        public int PostCustomer(CustomerDTO customer)
        {
            loggerService.Logger().Info("Calling with parameter as : customer: " + customer);
            return _customerService.SaveOrUpdateCustomer(customer);
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions