Exemplo n.º 1
0
        public bool SendMsg(int sender, string ToMember, string subject, string toName, string content)
        {
            List<int> recipients = new List<int>();
            string[] ToMembers = ToMember.Split(',');
            BLL.Message msg = new BLL.Message();
            msg.AddNew();
            msg.Body = content;
            msg.SenderID = sender;
            msg.Subject = subject;
            msg.ToMembers = toName;
            msg.Save();
            MemberMessage memberMsg = new MemberMessage();
            //add to member sent items
            memberMsg.AddNew();
            memberMsg.MessageID = msg.ID;
            memberMsg.IsRead = true;
            foreach (string item in ToMembers)
            {
                if (!string.IsNullOrEmpty(item))
                {
                    int recipientID = Convert.ToInt32(item);
                    // check if friend don't block sender
                    BlockedMembers bllBlocked = new BlockedMembers();
                    bllBlocked.Where.MemberID.Value = recipientID;
                    bllBlocked.Where.BlockID.Value = sender;
                    bllBlocked.Query.Load();
                    bool cansend = !(bllBlocked.RowCount > 0);

                    if (recipientID > 0 && !recipients.Contains(recipientID) && cansend) // cansend - check if friend don't block sender
                    {
                        recipients.Add(recipientID);
                        memberMsg.AddNew();
                        memberMsg.MemberID = recipientID;
                        memberMsg.MessageID = msg.ID;
                    }
                    else
                    {
                        recipientID = recipientID * -1;
                        if (Enum.IsDefined(typeof(Helper.Enums.AdminMailAddressAlias), recipientID))
                        {
                            Member aliasMembers = new Member();
                            aliasMembers.GetByAliase((Helper.Enums.AdminMailAddressAlias)recipientID);
                            do
                            {
                                if (!recipients.Contains(aliasMembers.MemberID))
                                {
                                    recipients.Add(aliasMembers.MemberID);
                                    memberMsg.AddNew();
                                    memberMsg.MemberID = aliasMembers.MemberID;
                                    memberMsg.MessageID = msg.ID;
                                }
                            } while (aliasMembers.MoveNext());
                        }
                    }
                }
            }

            memberMsg.Save();
            if (recipients.Count > 0)
            {
                NotificationHub notifications = new NotificationHub();
                for (int i = 0; i < recipients.Count; i++)
                {
                    notifications.SendMailNotifications(recipients[i]);
                }
            }
            return true;
        }
Exemplo n.º 2
0
        public void toggleBlockMember(int mid, bool block)
        {
            try
            {
                BlockedMembers blockedMembers = new BlockedMembers();
                blockedMembers.Where.BlockID.Value = mid;
                blockedMembers.Where.MemberID.Value = BLL.Member.CurrentMemberID;
                if (blockedMembers.Query.Load())
                {
                    if (!block)
                    {
                        blockedMembers.DeleteAll();
                        blockedMembers.Save();
                    }
                }
                else
                {
                    if (block)
                    {
                        blockedMembers.AddNew();
                        blockedMembers.MemberID = BLL.Member.CurrentMemberID;
                        blockedMembers.BlockID = mid;
                        blockedMembers.CreateDate = DateTime.Now;
                        blockedMembers.Save();

                        BLL.Member bllMember = new BLL.Member();
                        bllMember.LoadByPrimaryKeyWithTypeSpec(mid);
                        var member = bllMember.DefaultView.Table.AsEnumerable().Select(m =>
                        new
                        {
                            MemberID = m[Member.ColumnNames.MemberID],
                            Name = m[Member.ColumnNames.Name],
                            TypeSpecID = m["MemberTypeSpecID"],
                            ProfilePic = (m[Member.ColumnNames.ProfilePic] == DBNull.Value ? defaultImg : m[Member.ColumnNames.ProfilePic]),
                            IsOnline = m[Member.ColumnNames.IsOnLine],
                            StatusMsg = m[Member.ColumnNames.StatusMsg],
                            Status = Helper.EnumUtil.ParseEnum<Helper.Enums.MemberStatus>(Helper.TypeConverter.ToInt32(m[Member.ColumnNames.Status])).ToString().ToLower(),
                        }
                        ).FirstOrDefault();
                        SetContentResult(member);
                    }
                }

                IHubContext _Rcontext = GlobalHost.ConnectionManager.GetHubContext<ChatRoomHub>();
                var blocked = ChatRoomHub.ConnectedUsers.FirstOrDefault(u => u.MemberID == mid);
                if (blocked != null)
                {
                    _Rcontext.Clients.Client(blocked.ConnectionId).toggleBlockedFromMember(new { MemberID = BLL.Member.CurrentMemberID }, block);
                }
            }
            catch { }
        }