Beispiel #1
0
        public void InsertGroupMember()
        {
            GroupMemberRepository groupMemberRepository = new GroupMemberRepository(new InMemoryDbContextFactory().CreateDbContext());
            GroupModel            groupModel            = new GroupModel
            {
                Id          = Guid.NewGuid(),
                Name        = "První cenová skupina",
                Description = "Popisek testovací skupiny První cenová skupiina",
            };

            UserModel userModel = new UserModel
            {
                Id              = Guid.NewGuid(),
                Name            = "Martin",
                Surname         = "Vlach",
                Email           = "*****@*****.**",
                Password        = "******",
                TelephoneNumber = "+420420420420"
            };

            GroupMemberModel groupMemberModel = new GroupMemberModel
            {
                Id         = Guid.NewGuid(),
                Group      = groupModel,
                User       = userModel,
                Permission = PermissionEnum.Moderator
            };

            groupMemberRepository.Insert(groupMemberModel);
            var groupMemberRepositoryResponse = groupMemberRepository.GetById(groupMemberModel.Id);

            Assert.NotNull(groupMemberRepositoryResponse);
            Assert.Equal(userModel.Name, groupMemberModel.User.Name);
            Assert.Equal(groupModel.Name, groupMemberModel.Group.Name);
        }
Beispiel #2
0
        private void AddUser()
        {
            GroupMemberModel groupMember = new GroupMemberModel();

            groupMember.Id         = Guid.NewGuid();
            groupMember.User.Id    = userRepository.GetById(LoggedUserID.selectedUserModel.Id).Id;
            groupMember.Group.Id   = groupRepository.GetById(LoggedUserID.actualGroupModel.Id).Id;
            groupMember.Permission = DAL.Enums.PermissionEnum.User;

            groupMemberRepository.Insert(groupMember);
        }
Beispiel #3
0
 public void Save()
 {
     if (model.Id == Guid.Empty)
     {
         repository.Insert(model);
     }
     else
     {
         repository.Update(model);
     }
 }
Beispiel #4
0
        public static GroupMember AddMemberToGroup(UmbracoDatabase db, int memberId, int structuralGroupId)
        {
            var groupMember = new GroupMember()
            {
                MemberId          = memberId,
                StructuralGroupId = structuralGroupId
            };

            using (var repository = new GroupMemberRepository(db))
            {
                repository.Insert(groupMember);
                return(groupMember);
            }
        }
        public void AddUserToGroupFunction()
        {
            groupMemberModel.Id = Guid.NewGuid();
            groupMemberRepository.Insert(groupMemberModel);
            var user = userRepository.GetUserByEmail(this.addedUserEmail);

            groupMemberModel.User  = user;
            groupMemberModel.Group = LoggedUserID.actualGroupModel;
            groupMemberRepository.dbContext.RemoveEntities <GroupEntity>();
            groupMemberRepository.dbContext.RemoveEntities <UserEntity>();
            groupMemberRepository.Update(groupMemberModel);
            mediator.Send(new AddedMemberMessage());
            addedUserEmail = string.Empty;
            OnPropertyChanged("groupMemberModel");
        }
        public void Save()
        {
            Model.Id = Guid.NewGuid();
            GroupMemberModel groupMember = new GroupMemberModel();

            groupMember.Id    = Guid.NewGuid();
            groupMember.Group = Model;
            groupMemberRepository.Insert(groupMember);

            var groupMemberGet = groupMemberRepository.dbContext.GroupMembers.SingleOrDefault(i => i.Id == groupMember.Id);

            groupMemberGet.User = groupMemberRepository.dbContext.Users.SingleOrDefault(i => i.Id == LoggedUserID.userModel.Id);

            groupMemberRepository.dbContext.SaveChanges();


            mediator.Send(new AddedGroupMessage {
                Id = Model.Id
            });
            Model = null;
        }
        public void GetAllUsersOfGroupByGroupId()
        {
            InMemoryDbContextFactory Db = new InMemoryDbContextFactory();
            var dbContext = Db.CreateDbContext();

            GroupMemberRepository groupMemberRepository = new GroupMemberRepository(dbContext);
            UserRepository        userRepository        = new UserRepository(dbContext);

            GroupModel groupModel1 = new GroupModel
            {
                Id          = Guid.NewGuid(),
                Name        = "První skupina",
                Description = "Popisek1",
            };

            GroupModel groupModel2 = new GroupModel
            {
                Id          = Guid.NewGuid(),
                Name        = "Druhá skupina",
                Description = "Popisek2",
            };

            GroupModel groupModel3 = new GroupModel
            {
                Id          = Guid.NewGuid(),
                Name        = "Třetí skupina",
                Description = "Popisek3",
            };

            UserModel userModel1 = new UserModel
            {
                Id              = Guid.NewGuid(),
                Name            = "Karel",
                Surname         = "Vlach",
                Email           = "*****@*****.**",
                Password        = "******",
                TelephoneNumber = "+420420420420",
            };

            UserModel userModel2 = new UserModel
            {
                Id              = Guid.NewGuid(),
                Name            = "Pavel",
                Surname         = "Vlach",
                Email           = "*****@*****.**",
                Password        = "******",
                TelephoneNumber = "+420420420420",
            };

            UserModel userModel3 = new UserModel
            {
                Id              = Guid.NewGuid(),
                Name            = "Martin",
                Surname         = "Vlach",
                Email           = "*****@*****.**",
                Password        = "******",
                TelephoneNumber = "+420420420420",
            };


            userRepository.Insert(userModel1);
            userRepository.Insert(userModel2);
            userRepository.Insert(userModel3);

            var userRepositoryResponse1 = userRepository.GetById(userModel1.Id);
            var userRepositoryResponse2 = userRepository.GetById(userModel2.Id);
            var userRepositoryResponse3 = userRepository.GetById(userModel3.Id);

            Assert.NotNull(userRepositoryResponse1);
            Assert.NotNull(userRepositoryResponse2);
            Assert.NotNull(userRepositoryResponse3);


            GroupMemberModel groupMemberModel1 = new GroupMemberModel
            {
                Id         = Guid.NewGuid(),
                Group      = groupModel1,
                User       = userModel1,
                Permission = PermissionEnum.User
            };

            GroupMemberModel groupMemberModel2 = new GroupMemberModel
            {
                Id         = Guid.NewGuid(),
                Group      = groupModel1,
                User       = userModel2,
                Permission = PermissionEnum.User
            };

            GroupMemberModel groupMemberModel3 = new GroupMemberModel
            {
                Id         = Guid.NewGuid(),
                Group      = groupModel2,
                User       = userModel1,
                Permission = PermissionEnum.Admin
            };

            dbContext.DetachAllEntities();

            groupMemberRepository.Insert(groupMemberModel1);
            groupMemberRepository.Insert(groupMemberModel2);
            groupMemberRepository.Insert(groupMemberModel3);

            var groupMemberRepositoryResponse1 = groupMemberRepository.GetById(groupMemberModel1.Id);
            var groupMemberRepositoryResponse2 = groupMemberRepository.GetById(groupMemberModel2.Id);
            var groupMemberRepositoryResponse3 = groupMemberRepository.GetById(groupMemberModel3.Id);

            Assert.NotNull(groupMemberRepositoryResponse1);
            Assert.NotNull(groupMemberRepositoryResponse2);
            Assert.NotNull(groupMemberRepositoryResponse3);

            var userRepositoryResponseUsers = userRepository.GetAllUsersOfGroupByGroupId(groupModel1.Id);

            Assert.NotNull(userRepositoryResponseUsers);
            Assert.Equal(userRepositoryResponseUsers.ElementAt(0).Id, userModel1.Id);
            Assert.Equal(userRepositoryResponseUsers.ElementAt(1).Id, userModel2.Id);
            Assert.Equal(userRepositoryResponseUsers.Count, 2);
        }