Ejemplo n.º 1
0
        private UsersGroupsOnline IsGoupsUsersExistOrCreate(GroupsOnline group, MyUser user)
        {
            OpenMydbIfClose();
            if (group == null || user == null)
            {
                return(null);
            }
            var usersGrps = mydb.UsersGroupsOnline.FirstOrDefault(x => x.GroupsOnlineId == group.Id && x.MyUserId == user.Id);

            if (usersGrps == null)
            {
                usersGrps = new UsersGroupsOnline {
                    GroupsOnlineId = group.Id, MyUserId = user.Id
                };
                mydb.UsersGroupsOnline.Add(usersGrps);
                mydb.SaveChanges();
            }
            return(usersGrps);
        }
Ejemplo n.º 2
0
        public async Task JoinGroup(string GroupName)
        {
            if (Context.User.Identity.IsAuthenticated)
            {
                try
                {
                    OpenMydbIfClose();
                    var group    = IsGroupExistOrCrate(GroupName);
                    var userName = Context.User.Identity.Name;
                    var User     = IsUserExistOrCrate(userName);
                    UsersGroupsOnline groupUser = IsGoupsUsersExistOrCreate(group, User);
                }
                catch (Exception ex)
                {
                    var err = ex.Message;
                }

                await Groups.AddToGroupAsync(Context.ConnectionId, GroupName);

                Clients.Group(GroupName).SendAsync("RecOnline", $"{GetUserName()}", "Join Group : " + GroupName).Wait();
                await getGroupOnline();
            }
        }