Is there a way to update fields in the default ASP.NET MVC database directly from a SignalR hub?
As you know, by default on a new MVC template project, Visual Studio creates 3 controllers, Home
, Account
and Manage
. From those 3 it is easy to access the database like this:
using (var con = new ApplicationDbContext())
{
var userID = UserManager.FindById(User.Identity.GetUserId());
var userR = con.Users.FirstOrDefault(x => x.Id == userID.Id);
userR.Wins = 0;
userR.Loses = 0;
userR.Ties = 0;
con.SaveChanges();
}
where UserManager
is defined by default like this:
private ApplicationUserManager _userManager;
public ApplicationUserManager UserManager
{
get
{
return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
private set
{
_userManager = value;
}
}
I am looking for a way to do something like this in my SignalR Hub.