public void UpdatePersonsGroup(long curatorId, long groupId, PersonsGroup group)
        {
            using (var personsGroupRepository = new BaseRepository<PersonsGroup>())
            {
                Client curator = personsGroupRepository.Context.Clients.FirstOrDefault(x => x.Id == curatorId);
                if (curator == null)
                {
                    throw new UserDoesNotExistException();
                }

                PersonsGroup foundedGroup =
                    personsGroupRepository.GetAllItems.FirstOrDefault(x => x.Id == groupId && x.Curator.Id == curatorId);
                if (foundedGroup == null)
                {
                    throw new PersonsGroupDoesNotExistException();
                }

                if (!String.IsNullOrWhiteSpace(group.Name) && !String.Equals(group.Name, foundedGroup.Name))
                {
                    // Check unique Name
                    // SELECT Name FROM PersonsGroup WHERE Curator_Id = curatorId AND Name  = group.Name
                    if (personsGroupRepository.GetAllItems.Any(x => x.Curator.Id == curatorId && String.Equals(x.Name, group.Name)))
                    {
                        throw new PersonsGroupNameException();
                    }
                    foundedGroup.Name = group.Name;
                }

                if (group.Note != null)
                {
                    foundedGroup.Note = group.Note;
                }

                if (!personsGroupRepository.Update(foundedGroup).Status)
                {
                    throw new UpdateException();
                }
            }
        }
        public PersonsGroup CreatePersonsGroup(long curatorId, PersonsGroup personsGroup)
        {
            using (var personsGroupRepository = new BaseRepository<PersonsGroup>())
            {
                Client curator = personsGroupRepository.Context.Clients.FirstOrDefault(x => x.Id == curatorId);
                if (curator == null)
                {
                    throw new UserDoesNotExistException();
                }

                if (String.IsNullOrWhiteSpace(personsGroup.Name))
                {
                    throw new RequireFieldException();
                }

                // Check Name Unique
                // SELECT Name FROM PersonsGroups WHERE Curator_Id = curatorId AND Name = personsGroup.Name
                if (personsGroupRepository.GetAllItems.Where(x => x.Curator.Id == curatorId).Select(x => x.Name).Contains(personsGroup.Name))
                {
                    throw new PersonsGroupNameException();
                }

                personsGroup.CreationDate = DateTime.Now;
                personsGroup.Curator = curator;

                if (!personsGroupRepository.Create(personsGroup).Status)
                {
                    throw new CreateException();
                }

                return personsGroup;

            }
        }