Exemple #1
0
        public static int CreateChatGroup(ChatGroupInfo GroupInfo)
        {
            var _Context = new SystemContext();

            var entity = new ChatGroupEntity()
            {
                GroupName   = GroupInfo.GroupName,
                GroupDesc   = GroupInfo.GroupDesc,
                CreateDate  = DateTime.Now,
                CreateEmpID = GroupInfo.CreateEmpID,
                IsDelete    = false,
                IsPublic    = false
            };

            _Context.ChatGroupEntity.Add(entity);
            _Context.SaveChanges();

            // 将自己添加进组成员
            _Context.ChatGroupEmpsEntity.Add(new ChatGroupEmpsEntity()
            {
                GroupID = entity.GroupID,
                EmpID   = GroupInfo.CreateEmpID
            });

            foreach (var id in GroupInfo.Emps)
            {
                if (id != GroupInfo.CreateEmpID)
                {
                    _Context.ChatGroupEmpsEntity.Add(new ChatGroupEmpsEntity()
                    {
                        GroupID = entity.GroupID,
                        EmpID   = id
                    });
                }
            }

            _Context.SaveChanges();

            var notifySrv = UnityContainerHelper.GetServer <WSHandler>();

            notifySrv.Send(new
            {
                TargetGroup = entity.GroupID,
                MessageType = 104
            });

            return(entity.GroupID);
        }
Exemple #2
0
        public static void UpdateChatGroup(int GroupID, ChatGroupInfo GroupInfo)
        {
            var _Context = new SystemContext();

            var entity = _Context.ChatGroupEntity.Find(GroupID);

            entity.GroupName = GroupInfo.GroupName;
            entity.GroupDesc = GroupInfo.GroupDesc;

            _Context.Entry(entity).State = System.Data.Entity.EntityState.Modified;

            // 先清空小组成员
            var items = _Context.ChatGroupEmpsEntity.Where(g => g.GroupID == GroupID);

            foreach (var item in items)
            {
                _Context.ChatGroupEmpsEntity.Remove(item);
            }

            // 重新生成小组成员
            _Context.ChatGroupEmpsEntity.Add(new ChatGroupEmpsEntity()
            {
                GroupID = entity.GroupID,
                EmpID   = entity.CreateEmpID
            });

            foreach (var id in GroupInfo.Emps)
            {
                if (id != GroupInfo.CreateEmpID)
                {
                    _Context.ChatGroupEmpsEntity.Add(new ChatGroupEmpsEntity()
                    {
                        GroupID = entity.GroupID,
                        EmpID   = id
                    });
                }
            }

            _Context.SaveChanges();
            var notifySrv = UnityContainerHelper.GetServer <WSHandler>();

            notifySrv.Send(new
            {
                TargetGroup = entity.GroupID,
                MessageType = 104
            });
        }