public RoleDto AddRole(string roleName, string description)
        {
            var idGenerator = ContainerHelper.Resolve<IIdentityGenerator>();
            Role role = new Role(idGenerator.NewGuid())
                {
                    Name = roleName,
                    Description = description
                };

            var validator = ContainerHelper.Resolve<IEntityValidator>();
            if (validator.IsValid(role) == false)
            {
                throw new ApplicationValidationException(validator.GetInvalidMessages(role));
            }

            using (var context = RepositoryContext.Create())
            {
                var repository = context.GetRepository<RoleRepository>();
                bool existedSameNameRole = repository.Exists(roleName);
                if (existedSameNameRole)
                {
                    throw new ApplicationOperationException("Already existed same name role.");
                }

                repository.Add(role);
                context.UnitOfWork.Commit();
                return role.ProjectedAs<RoleDto>();
            }
        }
Exemplo n.º 2
0
        public void Load( Guid id )
        {
            Role = queryRoles.Load(id);

            if (Role == null)
                return;

            var roleFunctions = Role.Functions.ToList();

            var functions = queryFunctions.Query().ToList();

            Functions = new List<FunctionRoleModel>();

            foreach (var function in functions)
            {
                Functions.Add(new FunctionRoleModel
                {
                    Function = function,
                    IsLinked = roleFunctions.Exists(f => f.Id == function.Id)
                });

            }
        }
        public void UserEditModel_Loads_UserById_AndRoles()
        {
            Guid id = Guid.Parse("{0C21D6E8-01D0-4E59-8663-53856EEC7918}");
            var queryRoles = MockRepository.GenerateMock<IQueryService<Role>>();
            var queryUsers = MockRepository.GenerateMock<IQueryService<User>>();

            var emp = MockRepository.GenerateMock<User>();

            var roles = new Role[] { MockRepository.GenerateMock<Role>(),
             MockRepository.GenerateMock<Role>() };

            // expectations
            emp.Expect(c=>c.Roles).Return(new Role[]{roles[0]}.ToList());

            roles[0].Expect(f => f.Id).Return(Guid.Parse("{B4F707B3-D020-4B1C-9874-BA4C8FD259C3}"));
            roles[1].Expect(f => f.Id).Return(Guid.Parse("{C372EFCC-CC01-4B29-8421-873A2B69BDF3}"));

            queryUsers.Expect(f => f.Load(id)).Return(emp);

            queryRoles.Expect(f => f.Query()).Return(roles.AsQueryable());

            var model = new UserManagerEditModel(queryUsers, queryRoles);

            // act

            model.Load(id);

            queryUsers.VerifyAllExpectations();
            queryRoles.VerifyAllExpectations();

            Assert.IsNotNull(model.User);
            Assert.IsNotNull(model.Roles);

            Assert.IsTrue(model.Roles[0].IsLinked);
            Assert.IsFalse(model.Roles[1].IsLinked);
        }
Exemplo n.º 4
0
 public virtual void RemoveRole( Role role )
 {
     role.Employees.Remove(this);
     this.Roles.Remove(role);
 }
Exemplo n.º 5
0
 public virtual void AddRole( Role role )
 {
     Roles.Add(role);
 }
 public RoleManagerCreateOutputModel( )
 {
     Role = new Role();
 }