Last post May 24, 2015 03:04 AM by Krunal Parekh
May 22, 2015 05:36 AM|eguneys|LINK
I have to include this code in order to figure out the user and room the user is acting upon on each hub method:
public void ReadyPlay(string roomId)
string userId = Context.User.GetUserId();
GameUser user = _repository.GetUserById(userId);
GameRoom room = _repository.GetRoomById(roomId);
Is there a better way to manage this situation?
May 24, 2015 03:04 AM|Krunal Parekh|LINK
You could store the users and rooms in the cache and then create public property for current user in getter you can write logic that user is already fetched then get from cache otherwise get from database to avoid multiple calls to the database. You don't
need to pass anything because in getter you can directly get the user id from current context. For room you can use a static method that returns the room by id but here also you can get from cache if already fetched otherwise get from database. If you need
both on every method then for user you can just user public property but for room since it varies on roomid you will have to call the method.