1

I'm creating a SPA application with AngularJS at the client side and ASP.NET Web API as backend. My database is SQL Server 2012. There will be users which have a favourite sports team and a simple icon in the UI displaying the number of new articles/news/comments added or whatever connected to their favourite teams.

What I'd like to achieve is the following: Whenever a record about their team is inserted (record with TeamID column value for example equal to the user's favourite team ID), that notifications count icon should be updated immediately (just like Facebook's notifications - it's updated when a friend has posted on your wall or has tagged you and so on). How can I best achieve this?

What I'm thinking of for now is just setting an interval function in AngularJS to check every 30 seconds, let's say, if there are new records in the database making a request to a Web API controller. Of course this suggests a lot of checking for when the user is logging out - when was the last check, what will be the date to check against next time he/she logs in and so on.

Rosen Dimov
  • 1,055
  • 12
  • 32

2 Answers2

2

You can use signalR for this. It's a framework for real time communication. Check out this to get if you want to get started. It can easily be used together with angularJS.

Sjoerd222888
  • 3,228
  • 3
  • 31
  • 64
  • Yes SignalR is what you want to use. We use it for a very similar requirement than the original question. – Beyers Aug 23 '14 at 21:16
  • Thanks I will have a look a that, I hope it will integrate with Web API somehow and achieve that 'on record insert' event that I'm looking for. :) – Rosen Dimov Aug 23 '14 at 21:16
  • You can also talk from within the WebApi Controller to a signalR hub. This [question](http://stackoverflow.com/questions/16695975/calling-signalr-hub-from-webapi-controller-issues) might give you some hints. – Sjoerd222888 Aug 23 '14 at 21:24
0

What you are looking for is push

Sadly i never used it so i don't know much about it, but i think you should use technologies like pusher

Logar
  • 1,248
  • 9
  • 17
  • Thank you, I've heard about push notifications before and know what they are, but haven't used them in an application. – Rosen Dimov Aug 23 '14 at 21:17