Exemplo n.º 1
0
        public object ConnectUser(string userName)
        {
            try
            {
                using (var db = new FacebookDbContext())
                {
                    // Check if there if a connection for the specified user name have ever been made
                    var existingConnection = db.Connections.Where(x => x.UserName.ToLower() == userName.ToLower()).SingleOrDefault();

                    if (existingConnection != null)
                    {
                        // If there's an old connection only the connection id and the online status are changed.
                        existingConnection.ConnectionId = Context.ConnectionId;
                        existingConnection.IsOnline     = true;
                    }
                    else
                    {
                        // If not, then a new connection is created
                        db.Connections.Add(new Models.BaseEntity.Connection {
                            ConnectionId = Context.ConnectionId, UserName = userName, IsOnline = true
                        });
                    }

                    db.SaveChanges();
                }

                UsersOnline();

                return(new { Success = true });
            }
            catch (Exception ex)
            {
                return(new { Success = false, ErrorMessage = ex.Message });
            }
        }
Exemplo n.º 2
0
 public JsonResult VerifyUserNameInUse(string userName)
 {
     try
     {
         using (var db = new FacebookDbContext())
         {
             return(Json(new { Success = true, InUse = db.Connections.Where(x => x.UserName.ToLower() == userName.ToLower() && x.IsOnline).SingleOrDefault() != null }, JsonRequestBehavior.AllowGet));
         }
     }
     catch
     {
         return(Json(new { Success = false, ErrorMessage = "Something wrong happened." }, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 3
0
 public void UsersOnline()
 {
     try
     {
         using (var db = new FacebookDbContext())
         {
             Clients.All.UpdateUsersOnline(new { Success = true, UsersOnline = db.Connections.Where(x => x.IsOnline).Select(x => x.UserName).ToArray() });
         }
     }
     catch (Exception ex)
     {
         Clients.All.UpdateUsersOnline(new { Success = false, ErrorMessage = ex.Message });
     }
 }
Exemplo n.º 4
0
        public override Task OnReconnected()
        {
            using (var db = new FacebookDbContext())
            {
                var connection = db.Connections.Where(x => x.ConnectionId == Context.ConnectionId).SingleOrDefault();

                if (connection == null)
                {
                    throw new Exception("An attempt to reconnect a non tracked connection id have been made.");
                }

                connection.IsOnline = true;
                db.SaveChanges();
            }

            UsersOnline();

            return(base.OnReconnected());
        }
Exemplo n.º 5
0
        public void SendMessage(string userName, string message)
        {
            if (message.StartsWith("@"))
            {
                var pmUserName = message.Split(' ')[0].Substring(1);

                using (var db = new FacebookDbContext())
                {
                    var pmConnection = db.Connections.Where(x => x.UserName.ToLower() == pmUserName && x.IsOnline).SingleOrDefault();

                    if (pmConnection != null)
                    {
                        Clients.Clients(new List <string> {
                            Context.ConnectionId, pmConnection.ConnectionId
                        }).UpdateChat(userName, message, true);
                        return;
                    }
                }
            }
        }
Exemplo n.º 6
0
 public PostService(FacebookDbContext context, UserManager <User> userManager, IUserService userservice)
 {
     _context     = context;
     _userManager = userManager;
     _userService = userservice;
 }
Exemplo n.º 7
0
 public AbstractBaseRepository()
 {
     context = new FacebookDbContext();
 }
Exemplo n.º 8
0
 public BaseRepository()
 {
     _db = new FacebookDbContext();
 }
Exemplo n.º 9
0
 public UserDao()
 {
     db = new FacebookDbContext();
 }
Exemplo n.º 10
0
 public UserService(FacebookDbContext fbContext, UserManager <User> _userManager, SignInManager <User> _signInManager)
 {
     context       = fbContext;
     userManager   = _userManager;
     signInManager = _signInManager;
 }