This was the question i posted in stack overflow , you can see in depth the whole thing and can understand through this link.
Dont know if some thing i am doing wrong or correct in my approach please explain.
What I have tried:
tried posting on stack overflow and got no response. The link is provided for futher details.