コード例 #1
0
        public void UpdateBrGroupContact(long userID, List<GroupDTO> contactGroups, long contactID)
        {
            //Find all already joinedGroups
            var contactsInThisGroup = _brGroupContactService.GetGroupsByContact(userID, contactID);

            var alreadyJoinedGroupsIDs = new List<long>();

            foreach (var item in contactsInThisGroup)
            {
                var itemID = item.GroupID;
                alreadyJoinedGroupsIDs.Add(itemID);
            }

            var newJoinedGroupsIDs = new List<long>();
            foreach (var item in contactGroups)
            {
                var itemID = item.GroupID;
                newJoinedGroupsIDs.Add(itemID);
            }

            var AddGroupsIDs = new List<long>();
            for (int i = 0; i < newJoinedGroupsIDs.Count; i++)
            {
                var containedThisGroup = alreadyJoinedGroupsIDs.Contains(newJoinedGroupsIDs[i]);
                if (containedThisGroup == false)
                {
                    var addID = newJoinedGroupsIDs[i];
                    AddGroupsIDs.Add(addID);
                }
            }
            
            var DeleteGroupsIDs = new List<long>();
            for (int i = 0; i < alreadyJoinedGroupsIDs.Count; i++)
            {
                var containedThisGroup = newJoinedGroupsIDs.Contains(alreadyJoinedGroupsIDs[i]);
                if (containedThisGroup == false)
                {
                    var deleteID = alreadyJoinedGroupsIDs[i];
                    DeleteGroupsIDs.Add(deleteID);
                }
            }

            //insertNewGroups fro this Contact
            var listGroups = new List<Br_GroupContact>();
            if (AddGroupsIDs.Count != 0)
            {
                foreach (var item in AddGroupsIDs)
                {
                    var brGroupContact = new Br_GroupContact();
                    brGroupContact.GroupID = item;
                    brGroupContact.ContactID = contactID;
                    brGroupContact.UserID = userID;
                    listGroups.Add(brGroupContact);
                }
                _brGroupContactService.InsertRange(listGroups);
            }

            //Delete Groups from this user


            if (DeleteGroupsIDs.Count != 0)
            {
                foreach (var item in DeleteGroupsIDs)
                {
                    var deleteUpdateGroup = _brGroupContactService.FindbyGroupIDAndContactID(userID, contactID, item);
                    deleteUpdateGroup.ContactInThisGroupIsDeleted = true;
                    _brGroupContactService.Update(deleteUpdateGroup);
                }
            }
        }
コード例 #2
0
        public List <GroupDTO> GetAllGroupsForCertainContact(long userID, long contactID)
        {
            var contactsForGroup = _brGroupContactService.GetGroupsByContact(userID, contactID);

            return(Mapper.Map <List <GroupDTO> >(contactsForGroup));
        }