public Task CreateGroupAsync(IGroupModel groupModel)
        {
            try
            {
                var result = _groupService.CreateGroupAsync(groupModel);
                _logger.Debug("User created group");

                return result;
            }
            catch (ArgumentNullException)
            {
                _logger.Info("Group is null");
                throw new ArgumentNullException();
            }
            catch (ModelValidationException)
            {
                _logger.Info("Model of group is not valid");
                throw new ModelValidationException();
            }
            catch (SecurityException)
            {
                _logger.Info("User doesn't have enough permission for creating group");
                throw new SecurityException();
            }
            catch (GroupNotFoundException)
            {
                _logger.Info("Group not found");
                throw new GroupNotFoundException();
            }
            catch (Exception)
            {
                _logger.Error("User has not created a group.");
                throw new Exception();
            }
        }
        public void TestExists()
        {
            //string name = _uniqueNames.Pop();
            string name;

            _uniqueNames.TryPop(out name);
            IGroupModel group = _modelFactory.GetGroupModel(name, UniversalConstants.CountSize);

            Assert.IsFalse(_groupStore.Exists(x => x.Name == name));
            _groupStore.Add(group);
            Assert.IsTrue(_groupStore.Exists(x => x.Name == name));
            _groupStore.Delete(group);
        }
示例#3
0
        public void Delete(IGroupModel model)
        {
            string   name  = model.GetName();
            Grouping group = _db.Groupings.FirstOrDefault(x => x.Name == name);

            if (group == null)
            {
                throw new ArgumentException("Cannot delete group because it does not exist in the database.");
            }
            Disassociate(group);
            _db.Groupings.Remove(group);
            _db.SaveChanges();
        }
        public void TestAddGroupToChildOfChild()
        {
            ArgumentException expectedException = null;
            string            name1;

            _uniqueNames.TryPop(out name1);
            IGroupModel group1 = _modelFactory.GetGroupModel(name1, UniversalConstants.CountSize);

            _groupStore.Add(group1);
            string name2;

            _uniqueNames.TryPop(out name2);
            IGroupModel group2 = _modelFactory.GetGroupModel(name2, UniversalConstants.CountSize);

            _groupStore.Add(group2);
            _groupStore.AddItem(group1, group2);
            string name3;

            _uniqueNames.TryPop(out name3);
            IGroupModel group3 = _modelFactory.GetGroupModel(name3, UniversalConstants.CountSize);

            _groupStore.Add(group3);
            _groupStore.AddItem(group2, group3);
            try
            {
                _groupStore.AddItem(group3, group1);
            }
            catch (ArgumentException ex)
            {
                expectedException = ex;
            }
            finally
            {
                if (_groupStore.Contains(group3, group1))
                {
                    _groupStore.RemoveItem(group2, group1);
                }
                _groupStore.RemoveItem(group2, group3);
                _groupStore.RemoveItem(group1, group2);
                _groupStore.Delete(group3);
                _groupStore.Delete(group2);
                _groupStore.Delete(group1);
            }
            if (expectedException != null)
            {
                throw expectedException;
            }
        }
示例#5
0
        public void AddItemToGroup(string groupName, string itemName)
        {
            if (groupName == itemName)
            {
                throw new ArgumentException("Cannot add a group to itself.");
            }
            IGroupModel parent = _groupStore.GetOne(x => x.Name == groupName);

            if (parent == null)
            {
                throw new ArgumentException($"Can't add item to group named {groupName} since it doesn't exist.");
            }
            ITextModel  childText  = _textStore.GetOne(x => x.Name == itemName);
            IGroupModel childGroup = _groupStore.GetOne(x => x.Name == itemName);

            if (childText == null)
            {
                if (childGroup == null)
                {
                    throw new ArgumentException($"Can't add item named {itemName} to group since it doesn't exist.");
                }
                if (_groupStore.Contains(childGroup, parent))
                {
                    throw new ArgumentException("Can't add a group as a child to its own parent or a parent of its parent or ...");
                }
                if (_groupStore.Contains(parent, childGroup))
                {
                    throw new ArgumentException("Cannot add item to group since it is already a member of that group.");
                }
                parent.Add(childGroup);
                _groupStore.AddItem(parent, childGroup);
            }
            else
            {
                if (childGroup != null)
                {
                    throw new ArgumentException("The database has a text and group with the same name. That shouldn't happen.");
                }
                if (_groupStore.Contains(parent, childText))
                {
                    throw new ArgumentException("Cannot add item to group since it is already a member of that group.");
                }
                parent.Add(childText);
                _groupStore.AddItem(parent, childText);
            }
        }
        public void TestAdd()
        {
            string name;

            _uniqueNames.TryPop(out name);
            IGroupModel model = _modelFactory.GetGroupModel(name, UniversalConstants.CountSize);

            _groupStore.Add(model);
            Grouping result = _db.Groupings.FirstOrDefault(x => x.Name == name);

            Assert.IsNotNull(result);
            if (result != null)
            {
                _db.Groupings.Remove(result);
                _db.SaveChanges();
            }
        }
示例#7
0
        public void Add(IGroupModel model)
        {
            string name = model.GetName();

            if (_db.Groupings.Any(x => x.Name == name))
            {
                throw new ArgumentException($"Cannot add model since a model already exists in the database with name {model.GetName()}.");
            }
            Grouping group = new Grouping()
            {
                Name = model.GetName(),
            };

            _db.Groupings.Add(group);
            _db.SaveChanges();
            //AddItems(model, model.GetMembers().Select(x => (ITextOrGroupModel)x));
        }
示例#8
0
        public IGroupDto Map(IGroupModel group)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group");
            }

            return new GroupDto
            {
                ContactEmail = group.ContactEmail,
                ContactName = group.ContactName,
                ContactPhone = group.ContactPhone,
                GroupId = group.GroupId,
                GroupNumber = group.GroupNumber,
                Year = group.Year
            };
        }
        public void TestGetOne()
        {
            //string name = _uniqueNames.Pop();
            string name;

            _uniqueNames.TryPop(out name);
            IGroupModel group = _modelFactory.GetGroupModel(name, UniversalConstants.CountSize);

            _groupStore.Add(group);
            group = _groupStore.GetOne(x => x.Name == name);
            Assert.IsNotNull(group);
            Assert.AreEqual(group.GetName(), name);
            _groupStore.Delete(group);
            //name = _uniqueNames.Pop();
            _uniqueNames.TryPop(out name);
            group = _groupStore.GetOne(x => x.Name == name);
            Assert.IsNull(group);
        }
示例#10
0
        public void UpdateGroup(string oldName, string newName)
        {
            IGroupModel model = _groupStore.GetOne(x => x.Name == oldName);

            if (model == null)
            {
                throw new ArgumentException("Cannot update group since it doesn't exist.");
            }
            if (string.IsNullOrWhiteSpace(newName))
            {
                throw new ArgumentException("Name cannot be null.");
            }
            if (_groupStore.Exists(x => x.Name == newName) || _textStore.Exists(x => x.Name == newName))
            {
                throw new ArgumentException($"Cannot create group because another item in the database already has the name {newName}.");
            }
            _groupStore.ModifyName(model, newName);
            model.SetName(newName);
        }
示例#11
0
        private IDictionary <Guid, IEnumerable <Guid> > GetAssignedUserInGroup(IEnumerable <IDayAssign> weekDayAssigns)
        {
            var result = new Dictionary <Guid, IEnumerable <Guid> >();

            Dictionary <Guid, Guid> dayAssignIds = weekDayAssigns.Where(d => d.GroupId.HasValue).ToDictionary(k => k.Id, v => v.GroupId.Value);

            IEnumerable <Guid> groupsIds = dayAssignIds.Select(g => g.Value).Distinct();
            List <IGroupModel> groups    = groupService.GetByIds(groupsIds).ToList();

            foreach (var dayAssign in dayAssignIds)
            {
                IGroupModel        group   = groups.First(g => g.Id == dayAssign.Value);
                IEnumerable <Guid> members = group.MemberIds;

                result.Add(dayAssign.Key, members);
            }

            return(result);
        }
示例#12
0
        public void RemoveItem(IGroupModel model, ITextOrGroupModel item)
        {
            string   parentName = model.GetName();
            Grouping parent     = _db.Groupings.FirstOrDefault(x => x.Name == parentName);

            if (parent == null)
            {
                throw new ArgumentException("Cannot add to group since the group does not exist.");
            }
            string   childName  = item.GetName();
            Text     childText  = _db.Texts.FirstOrDefault(x => x.Name == childName);
            Grouping childGroup = _db.Groupings.FirstOrDefault(x => x.Name == childName);

            if (childText == null)
            {
                if (childGroup == null)
                {
                    throw new ArgumentException("Cannot remove item from group since the item does not exist.");
                }
                Grouping_Grouping association = _db.Grouping_Grouping.FirstOrDefault(x => x.ParentId == parent.Id && x.ChildId == childGroup.Id);
                if (association == null)
                {
                    throw new ArgumentException("Cannot remove item from group since it is not a member of that group.");
                }
                _db.Grouping_Grouping.Remove(association);
                _db.SaveChanges();
            }
            else
            {
                if (childGroup != null)
                {
                    throw new InvalidOperationException("The database contains both a text and a group with the same name. That's not good.");
                }
                Text_Grouping assocation = _db.Text_Grouping.FirstOrDefault(x => x.TextId == childText.Id && x.GroupingId == parent.Id);
                if (assocation == null)
                {
                    throw new ArgumentException("Cannot remove item from group since it is not a member of that group.");
                }
                _db.Text_Grouping.Remove(assocation);
                _db.SaveChanges();
            }
        }
示例#13
0
        public Task CreateGroupAsync(IGroupModel groupModel)
        {
            if (groupModel == null)
            {
                throw new ArgumentNullException("groupModel");
            }

            EntityValidationResult result = _entityValidator.ValidateEntity(groupModel);
            if (result.IsValid == false)
            {
                throw new InvalidGroupException(result.ValidationResults);
            }
            if (_groupRepository.GetGroups().Any(g => g.GroupNumber == groupModel.GroupNumber && g.Year == groupModel.Year))
            {
                throw new GroupNotFoundException();
            }
            _groupRepository.CreateGroup(_groupnDtoMapper.Map(groupModel));

            return Task.FromResult<int>(0);
        }
        public Task CreateGroupAsync(IGroupModel groupModel)
        {
            if (groupModel == null)
            {
                throw new ArgumentNullException("group");
            }

            EntityValidationResult result = _entityValidator.ValidateEntity(groupModel);
            if (result.IsValid == false)
            {
                throw new InvalidGroupException(result.ValidationResults);
            }

            if (!_authorizationManager.CheckAccess(new AuthorizationContext(_principal, "Group", "Create")))
            {
                throw new SecurityException("User doesn't have enough permission for creating group");
            }

            return _groupService.CreateGroupAsync(groupModel);
        }
示例#15
0
        public void ModifyName(IGroupModel model, string newName)
        {
            if (string.IsNullOrWhiteSpace(newName))
            {
                throw new ArgumentException("Cannot update group name to null or white space.");
            }
            string   name  = model.GetName();
            Grouping group = _db.Groupings.FirstOrDefault(x => x.Name == name);

            if (group == null)
            {
                throw new ArgumentException("Cannot update group name because group does not exist in the database.");
            }
            if (_db.Groupings.Any(x => x.Name == newName))
            {
                throw new ArgumentException("Cannot change groups name, since that name is already in use.");
            }
            group.Name = newName;
            _db.SaveChanges();
        }
        public void TestModifyName()
        {
            //string name = _uniqueNames.Pop();
            string name;

            _uniqueNames.TryPop(out name);
            IGroupModel model = _modelFactory.GetGroupModel(name, UniversalConstants.CountSize);

            _groupStore.Add(model);
            model = _groupStore.GetOne(x => x.Name == name);
            //string name2 = _uniqueNames.Pop();
            string name2;

            _uniqueNames.TryPop(out name2);
            Assert.IsTrue(_groupStore.Exists(x => x.Name == name));
            Assert.IsFalse(_groupStore.Exists(x => x.Name == name2));
            _groupStore.ModifyName(model, name2);
            Assert.IsFalse(_groupStore.Exists(x => x.Name == name));
            Assert.IsTrue(_groupStore.Exists(x => x.Name == name2));
            model = _groupStore.GetOne(x => x.Name == name2);
            _groupStore.Delete(model);
        }
        public void TestAddDuplicateText()
        {
            ArgumentException expectedException = null;
            //string groupName = _uniqueNames.Pop();
            string groupName;

            _uniqueNames.TryPop(out groupName);
            IGroupModel groupModel = _modelFactory.GetGroupModel(groupName, UniversalConstants.CountSize);

            _groupStore.Add(groupModel);
            //string textName = _uniqueNames.Pop();
            string textName;

            _uniqueNames.TryPop(out textName);
            StreamReader text      = new StreamReader("../../SampleTextFiles/WordSpanningMultipleLines.txt");
            ITextModel   textModel = _modelFactory.GetTextModel(textName, text, UniversalConstants.CountSize);

            _textStore.Add(textModel);
            _groupStore.AddItem(groupModel, textModel);
            groupModel = _groupStore.GetOne(x => x.Name == groupName);
            try
            {
                _groupStore.AddItem(groupModel, textModel);
            }
            catch (ArgumentException ex)
            {
                expectedException = ex;
            }
            finally
            {
                _groupStore.RemoveItem(groupModel, textModel);
                _textStore.Delete(textModel);
                _groupStore.Delete(groupModel);
            }
            if (expectedException != null)
            {
                throw expectedException;
            }
        }
        public void TestAddDuplicateGroup()
        {
            ArgumentException expectedException = null;
            //string groupName = _uniqueNames.Pop();
            string groupName1;

            _uniqueNames.TryPop(out groupName1);
            IGroupModel groupModel1 = _modelFactory.GetGroupModel(groupName1, UniversalConstants.CountSize);

            _groupStore.Add(groupModel1);
            //string textName = _uniqueNames.Pop();
            string groupName2;

            _uniqueNames.TryPop(out groupName2);
            IGroupModel groupModel2 = _modelFactory.GetGroupModel(groupName2, UniversalConstants.CountSize);

            _groupStore.Add(groupModel2);
            _groupStore.AddItem(groupModel1, groupModel2);
            groupModel1 = _groupStore.GetOne(x => x.Name == groupName1);
            try
            {
                _groupStore.AddItem(groupModel1, groupModel2);
            }
            catch (ArgumentException ex)
            {
                expectedException = ex;
            }
            finally
            {
                _groupStore.RemoveItem(groupModel1, groupModel2);
                _groupStore.Delete(groupModel2);
                _groupStore.Delete(groupModel1);
            }
            if (expectedException != null)
            {
                throw expectedException;
            }
        }
示例#19
0
        public void RemoveItemFromGroup(string groupName, string itemName)
        {
            IGroupModel parent = _groupStore.GetOne(x => x.Name == groupName);

            if (parent == null)
            {
                throw new ArgumentException($"Can't remove item from group named {groupName} since it doesn't exist.");
            }
            ITextModel  childText  = _textStore.GetOne(x => x.Name == itemName);
            IGroupModel childGroup = _groupStore.GetOne(x => x.Name == itemName);

            if (childText == null)
            {
                if (childGroup == null)
                {
                    throw new ArgumentException($"Can't remove item named {itemName} from group since it doesn't exist.");
                }
                if (!_groupStore.Contains(parent, childGroup))
                {
                    throw new ArgumentException("Cannot remove item from group since it is not a member of that group.");
                }
                parent.Remove(childGroup);
                _groupStore.RemoveItem(parent, childGroup);
            }
            else
            {
                if (childGroup != null)
                {
                    throw new ArgumentException("The database has a text and group with the same name. That shouldn't happen.");
                }
                if (!_groupStore.Contains(parent, childText))
                {
                    throw new ArgumentException("Cannot remove item from group since it is not a member of that group.");
                }
                parent.Remove(childText);
                _groupStore.RemoveItem(parent, childText);
            }
        }
示例#20
0
        public IGroupModel GetOne(Expression <Func <Grouping, bool> > criteria)
        {
            Grouping group = _db.Groupings.FirstOrDefault(criteria);

            if (group == null)
            {
                return(null);
            }
            IGroupModel      output  = _modelFactory.GetGroupModel(group.Name, UniversalConstants.CountSize);
            IQueryable <int> TextIds = _db.Texts.Join(
                _db.Text_Grouping,
                text => text.Id,
                text_grouping => text_grouping.TextId,
                (text, text_grouping) => new { TextId = text_grouping.TextId, GroupingId = text_grouping.GroupingId }
                ).Where(x => x.GroupingId == group.Id)
                                       .Select(x => (int)x.TextId);

            foreach (Text text in _db.Texts.Where(x => TextIds.Contains((int)x.Id)))
            {
                ITextModel textModel = _textStore.GetOne(x => x.Id == text.Id);
                if (textModel == null)
                {
                    throw new ArgumentException("Cannot get group since it contains a reference to a nonexistant text.");
                }
                output.Add(textModel);
            }
            foreach (Grouping_Grouping groupGroup in _db.Grouping_Grouping.Where(x => x.ParentId == group.Id))
            {
                IGroupModel groupModel = GetOne(x => x.Id == groupGroup.ChildId);
                if (groupModel == null)
                {
                    throw new ArgumentException("Cannot get group since it contains a reference to a nonexistant child group.");
                }
                output.Add(groupModel);
            }
            return(output);
        }
        public void Initialize()
        {
            _modelFactory = new ModelFactory();

            var countsOne         = new int[] { 1, 2, 3, 4, 5 };
            var countsTwo         = new int[] { 7, 8, 9, 10, 11 };
            var countsThree       = new int[] { 100, 101, 102, 103, 104 };
            var countsWrongLength = new int[] { 55 };

            var groupCountsBadInitialization = new int[] { 7, 7, 7, 7, 7 };

            var countsWithQuotesOne         = _modelFactory.GetSingleCountModel(countsOne);
            var countsWithQuotesTwo         = _modelFactory.GetSingleCountModel(countsTwo);
            var countsWithQuotesThree       = _modelFactory.GetSingleCountModel(countsThree);
            var countsWithQuotesWrongLength = _modelFactory.GetSingleCountModel(countsWrongLength);

            var countsWithoutQuotesOne         = _modelFactory.GetSingleCountModel((int[])countsOne.Clone());
            var countsWithoutQuotesTwo         = _modelFactory.GetSingleCountModel((int[])countsTwo.Clone());
            var countsWithoutQuotesThree       = _modelFactory.GetSingleCountModel((int[])countsThree.Clone());
            var countsWithoutQuotesWrongLength = _modelFactory.GetSingleCountModel((int[])countsWrongLength.Clone());

            badCountInitialization = _modelFactory.GetSingleCountModel(groupCountsBadInitialization);

            var flexibleCountsOne         = _modelFactory.GetFlexibleCountModel(countsWithQuotesOne, countsWithoutQuotesOne);
            var flexibleCountsTwo         = _modelFactory.GetFlexibleCountModel(countsWithQuotesTwo, countsWithoutQuotesTwo);
            var flexibleCountsThree       = _modelFactory.GetFlexibleCountModel(countsWithQuotesThree, countsWithoutQuotesThree);
            var flexibleCountsWrongLength = _modelFactory.GetFlexibleCountModel(countsWithQuotesWrongLength, countsWithoutQuotesWrongLength);

            textOne         = _modelFactory.GetTextModel("text one", flexibleCountsOne);
            textTwo         = _modelFactory.GetTextModel("text two", flexibleCountsTwo);
            textThree       = _modelFactory.GetTextModel("text three", flexibleCountsThree);
            textWrongLength = _modelFactory.GetTextModel("text wrong length", flexibleCountsWrongLength);

            groupOne = _modelFactory.GetGroupModel("group one", 5);
            groupTwo = _modelFactory.GetGroupModel("group two", 5);
        }
示例#22
0
 private static GroupViewModel MapGroupToView(IGroupModel g)
 {
     return new GroupViewModel
     {
         GroupId = g.GroupId,
         GroupNumber = g.GroupNumber,
         Year = g.Year,
         ContactEmail = g.ContactEmail,
         ContactName = g.ContactName,
         ContactPhone = g.ContactPhone
     };
 }
 public void ConstructorBadCountInitialization()
 {
     groupOne = new GroupModel("bad count initialization", badCountInitialization);
 }
 public void ConstructorNullWordCount()
 {
     groupOne = new GroupModel("group one", null);
 }
示例#25
0
        public bool Contains(IGroupModel group, ITextOrGroupModel item)
        {
            string groupName = group.GetName();
            string itemName  = item.GetName();

            if (string.Equals(groupName, itemName))
            {
                return(false);
            }
            Grouping parentGroup = _db.Groupings.FirstOrDefault(x => x.Name == groupName);

            if (parentGroup == null)
            {
                throw new ArgumentException("Parent group does not exist.");
            }
            //IQueryable<Grouping_Grouping> childGroupIds = _db.Grouping_Grouping.Where(x => x.ParentId == parentGroup.Id);
            List <Grouping> allGroups = new List <Grouping>()
            {
                parentGroup
            };
            List <Grouping> nextGroups = new List <Grouping>();
            int             oldCount   = allGroups.Count;
            int             newCount   = allGroups.Count;

            do
            {
                oldCount = allGroups.Count;
                foreach (Grouping grouping in allGroups)
                {
                    nextGroups.AddRange(_db.Grouping_Grouping.Where(x => x.ParentId == grouping.Id).Join(
                                            _db.Groupings,
                                            gg => gg.ChildId,
                                            g => g.Id,
                                            (gg, g) => g
                                            ));
                }
                nextGroups = nextGroups.Distinct().ToList();
                foreach (var nextGroup in nextGroups)
                {
                    allGroups.Add(nextGroup);
                }
                allGroups  = allGroups.Distinct().ToList();
                newCount   = allGroups.Count;
                nextGroups = new List <Grouping>();
            } while (oldCount < newCount);
            List <Text> allTexts = new List <Text>();

            foreach (Grouping g in allGroups)
            {
                IQueryable <Text> childTexts = _db.Text_Grouping.Where(x => x.GroupingId == g.Id).Join(
                    _db.Texts,
                    tg => tg.TextId,
                    t => t.Id,
                    (tg, t) => t
                    );
                allTexts.AddRange(childTexts);
            }
            allTexts = allTexts.Distinct().ToList();
            return(allGroups.Any(x => x.Name == itemName) || allTexts.Any(x => x.Name == itemName));


            //Grouping group = _db.Groupings.FirstOrDefault(x => x.Name == groupName);
            //Grouping groupItem = _db.Groupings.FirstOrDefault(x => x.Name == itemName);
            //Text textItem = _db.Texts.FirstOrDefault(x => x.Name == itemName);
            //if (textItem == null && groupItem == null)
            //{
            //    throw new ArgumentException("No item with the specified name exists.");
            //}
            //if (textItem == null)
            //{
            //    return _db.Grouping_Grouping.Any(x => x.ParentId == group.Id && x.ChildId == groupItem.Id);
            //}
            //return _db.Text_Grouping.Any(x => x.TextId == textItem.Id && x.GroupingId == group.Id);
        }
示例#26
0
        public void AddItem(IGroupModel model, ITextOrGroupModel item)
        {
            string   parentName = model.GetName();
            Grouping parent     = _db.Groupings.FirstOrDefault(x => x.Name == parentName);

            if (parent == null)
            {
                throw new ArgumentException("Cannot add to group since the group does not exist.");
            }
            string   childName  = item.GetName();
            Text     childText  = _db.Texts.FirstOrDefault(x => x.Name == childName);
            Grouping childGroup = _db.Groupings.FirstOrDefault(x => x.Name == childName);

            if (childText == null)
            {
                if (childGroup == null)
                {
                    throw new ArgumentException("Cannot add item to group since the item does not exist.");
                }
                if (childGroup.Id == parent.Id)
                {
                    throw new ArgumentException("Cannot add a group to itself.");
                }
                if (item is IGroupModel)
                {
                    if (Contains((IGroupModel)item, model))
                    {
                        throw new ArgumentException("Cannot add item to its own child or a child of its child or ...");
                    }
                }
                else
                {
                    throw new ArgumentException("The item's name corresponds to a group in the db, but the item is not a group model. Something is wrong.");
                }
                if (_db.Grouping_Grouping.Any(x => x.ParentId == parent.Id && x.ChildId == childGroup.Id))
                {
                    throw new ArgumentException("Cannot add item to group since it is already a member.");
                }
                Grouping_Grouping association = new Grouping_Grouping()
                {
                    ParentId = parent.Id, ChildId = childGroup.Id
                };
                _db.Grouping_Grouping.Add(association);
                _db.SaveChanges();
            }
            else
            {
                if (childGroup != null)
                {
                    throw new InvalidOperationException("The database contains both a text and a group with the same name. That's not good.");
                }
                if (_db.Text_Grouping.Any(x => x.TextId == childText.Id && x.GroupingId == parent.Id))
                {
                    throw new ArgumentException("Cannot add item to group since it is already a member.");
                }
                Text_Grouping assocation = new Text_Grouping()
                {
                    TextId = childText.Id, GroupingId = parent.Id
                };
                _db.Text_Grouping.Add(assocation);
                _db.SaveChanges();
            }
        }