0

In existing LOB app, I added new Web API project. Because of existing layers in app (Domain objects,DAL-ADO.NET-DataReader, BLL), I decided to use the Web API by holding the existing logic.

First question: Is this a right way?

There is a method in BLL which return list of object, and receives 4 parameters. All of this input parameters can be NULL, and in that case,the method returns full list of objects.

Second question: How to design WEB api controller for the aforementined method?

public static List<DomainObject> GetTata(int? param1,int? param2, int? param3, int? param4)
{
    List<DomainObject> return = new List<DomainObject>();

    using (Context context = new Context())
    {
        return = MyDAL.GetData(param1,param2,param3,param4, context);
    }

    return return ;
}

1 Answer 1

1

Don't know what Data means, but when designing a WebApi you should think in "Resources" (instead of thinking in "Actions").

I don't like the method to be static (honestly, never tested it and i don't know if works), but methods that serve responses should be instance methods (and sooner or later you will probably need to access some instance field).

Don't know what the four parameters are, but you should think about the URL for accessing this controller. Lets assume that this controller returns something like "Customers". So the URLs i think are like:

/api/Customers -> Get ALL customers
/api/Customers/{id} -> Get Customer of this id

Additional filters and clausules (order by, pagination if needed) are usually passed through querystring (i.e. take a look on how OData do this). Something like:

/api/Customers?name=foo -> Get ALL customers which its name starts with foo
/api/Customers?name=x&order=birthDate -> Get ALL customers which its name starts with x and ordered by birhDate.

So, your controller should translate between the URL parameters (route and querystring) to the parameters expected by the DAL classes. But exposing the same parameters that DAL classes expect to the WebApi most of times is not a good idea.

Hope this helps... For more info you should give some more info (what the parameters means, and so on). ;)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.