Пример #1
0
        public System.Threading.Tasks.Task DisConnect(bool stopCalled, HubCallerContext Context2, Microsoft.AspNet.SignalR.Hubs.IHubCallerConnectionContext <dynamic> Clients2)
        {
            ChatUserDetailRepository <ChatUserDetail> chatud = new ChatUserDetailRepository <ChatUserDetail>();
            //using (Surajit_TestEntities dc = new Surajit_TestEntities())
            //{
            var item = chatud.GetList(new { ConnectionId = Context2.ConnectionId }).FirstOrDefault();

            //var item = dc.ChatUserDetails.FirstOrDefault(x => x.ConnectionId == Context.ConnectionId);
            if (item != null)
            {
                chatud.Delete(item.Id); //dc.ChatUserDetails.Remove(item);
                //dc.SaveChanges();

                var id = Context2.ConnectionId;
                Clients2.All.onUserDisconnected(id, item.UserName);
            }
            //}
            return(base.OnDisconnected(stopCalled));
        }
Пример #2
0
        public void Connect(string userName, string email, Microsoft.AspNet.SignalR.Hubs.IHubCallerConnectionContext <dynamic> Clients2, string id)
        {
            emailIDLoaded = email;
            //var id = Context.ConnectionId;
            //using (DB_102707_zonaflEntities dc = new DB_102707_zonaflEntities())
            //{
            ChatUserDetailRepository <ChatUserDetail> chatud = new ChatUserDetailRepository <ChatUserDetail>();
            OfferRepository <Offer>           offerrepo      = new OfferRepository <Offer>();
            OfferUserRepository <OfferUser>   offeurrepo     = new OfferUserRepository <OfferUser>();
            OfferUserRepository <AspNetUsers> userrepo       = new OfferUserRepository <AspNetUsers>();
            ChatUserDetail item = chatud.GetList(new { EmailID = email }).FirstOrDefault();

            //ChatUserDetail item=chatud.GetList("where EmailID='" + email+"'").FirstOrDefault();
            //var item = dc.ChatUserDetails.FirstOrDefault(x => x.EmailID == email);
            if (item != null)
            {
                chatud.Delete(item.Id);
                //dc.ChatUserDetails.Remove(item);
                //dc.SaveChanges();

                // Disconnect
                Clients2.All.onUserDisconnectedExisting(item.ConnectionId, item.UserName);
            }



            AspNetUsers user = userrepo.GtUserByEmail(email);

            if (chatud.GetList(new { EmailId = user.Email }).FirstOrDefault() == null)
            {
                var userdetails = new ChatUserDetail
                {
                    ConnectionId = id,
                    UserName     = userName,
                    EmailID      = email
                };
                chatud.Insert(userdetails);
            }

            List <ChatUserDetail> Users = new List <ChatUserDetail>();

            if (!user.Freelance)
            {
                List <Offer> offertsuser = offerrepo.GetOffertsByContractorEmail(email);
                string       valueoffer  = string.Join(",", offertsuser.Select(e => e.Id).ToArray());
                Users = chatud.GetUsersByOfferContractorid(valueoffer);
            }
            else
            {
                List <OfferUser> offertsuser = offeurrepo.GetOffersUser(user.Id);
                string           valueoffer  = string.Join(",", offertsuser.Select(e => e.IdOffer).ToArray());
                Users = chatud.GetContractorsByOffers(valueoffer);
            }

            //var Users = chatud.GetList().ToList();
            if (Users.Where(x => x.EmailID == email).ToList().Count == 0)
            {
                //var userdetails = new ChatUserDetail
                //{
                //    ConnectionId = id,
                //    UserName = userName,
                //    EmailID = email
                //};
                //chatud.Insert(userdetails);
                //dc.SaveChanges();

                // send to caller
                var connectedUsers = chatud.GetList();
                ChatMessageDetailRepository <ChatMessageDetail> chatmd = new ChatMessageDetailRepository <ChatMessageDetail>();
                var CurrentMessage = chatmd.GetList();//dc.ChatMessageDetails.ToList();
                Clients2.Caller.onConnected(id, userName, connectedUsers, CurrentMessage);
                // }

                // send to all except caller client
                Clients2.AllExcept(id).onNewUserConnected(id, userName, email);
            }
        }