public user modelToEntity(User user)
 {
     var userData = new user();
     userData.UserID = user.UserID;
     userData.UserName = user.UserName;
     userData.Password = user.Password;
     return userData;
 }
        public int registerUser(string username, string password, string connectionID)
        {
            try
            {
                using (var entities = new SignalREntities())
                {
                    var check = entities.users.Where(o => o.UserID.Equals(username));
                    if (!check.Any())
                    {
                        var user = new User();
                        user.UserID = username;
                        user.UserName = username;
                        user.Password = password;
                        entities.users.AddObject(new EMUser().modelToEntity(user));

                        entities.SaveChanges();
                    }
                    var rand = new Random();
                    var index = rand.Next(0, img.Image.Count - 1);

                    var activity = new UserActivity();
                    activity.UserID = username;
                    activity.ConnectionID = connectionID;
                    activity.Status = "Online";
                    activity.Avater = img.Image[index];

                    entities.useractivities.AddObject(new EMUserActivity().modelToEntity(activity));
                    entities.SaveChanges();
                    var useractivities = entities.useractivities.ToList();
                    chatHub.notifyOnlineUser(useractivities.Select(o => new EMUserActivity().entityToModel(o)).ToList());
                }
                return 1;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }