public useractivity modelToEntity(UserActivity uactivity)
 {
     var activity = new useractivity();
     activity.UserID = uactivity.UserID;
     activity.ConnectionID = uactivity.ConnectionID;
     activity.Status = uactivity.Status;
     activity.Avater = uactivity.Avater;
     // msgData.MessageID = msg.MessageID;
     return activity;
 }
 public UserActivity entityToModel(useractivity activity)
 {
     var uactivity = new UserActivity();
     uactivity.OnlineID = activity.OnlineID;
     uactivity.UserID = activity.UserID;
     uactivity.ConnectionID = activity.ConnectionID;
     uactivity.Status = activity.Status;
     uactivity.Avater = activity.Avater;
     return uactivity;
 }
        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;
            }
        }