2

I have a UI that needs lots of information. Most of the information has been identified as separate entities in database. For example, displaying the details of an Employee. The UI page might be Employee details with various sections regarding Employee Information such as Personal Details, Address, Contact details, Project Details etc.

So if we derive the entities for the same requirement, we will have following tables

Employee

Address

Contact

Project

We will be implementing repository pattern in DA layer, and ASP.Net Web API as our restful service layer.

So, now if i need to display Employee details in the UI, what should be the best approach. What i was thinking is mentioned below.

Approach

There will be a single call to Web Api to get the Employee details. Internally it will connect to database multiple times to get Employee details, Address information, Contact information, Projects information etc and populate into one EmployeeDetailsModel (a kind of viewmodel) and return this as a JSON.

Is this a good approach ? If there is any other better approach please suggest

Ravi Sankar Rao
  • 1,050
  • 11
  • 26
  • What you are really asking is if its better to have the client make multiple request to gather information from the respective models or assemble the view model on the server side and return it using one single Web API endpoint - I think the answer depends a lot on your client technology (is it an Angular SPA? Android/iOS app? WCF client?). Generally I would say that a Web API should not work with view models, it should work with the actual domain concepts where a view model does not accurately represent the real world object. An Employee does but an EmployeeView does not. – Marcus Aug 31 '16 at 08:20
  • @Marcus Client will be Web client purely based on Angular JS, HTML, CSS and additional Javascript. – Ravi Sankar Rao Aug 31 '16 at 08:32
  • For me applying async is easier at client side. In my projects I have controllers for every entity. They are as simple as possible and return JSON only. When the page/partial page of SPA loads I kick off many Angular service calls parallel (every entity has its own call) to collect the data from the server to be displayed. At the moment it is working fine, later I can apply lazy load if it is needed. – AndrasCsanyi Aug 31 '16 at 09:23
  • @SayusiAndo All the data should be loaded after a single CTA. Employee details CTA should show me all at once. And the data which i am talking will be in KBs. Should i still do async/lazy loading looking at the size of data – Ravi Sankar Rao Sep 07 '16 at 15:20

1 Answers1

0

Going with your approach might prove as a poor user experience as users will wait for all the data to be assembled. I suggest you divide your web page into sections. First call employee data, and then on a different client event (say click the employee's project cell) call the employee's project detail (supposing it is another table)

Moutabreath
  • 184
  • 1
  • 6
  • 19
  • All the data should be loaded after a single CTA. Employee details CTA should show me all at once. And the data which i am talking will be in KBs. – Ravi Sankar Rao Sep 07 '16 at 15:20