Пример #1
0
        public Guid CreateRole(Guid agencyId, string name, DTO.RoleDetails details)
        {
            // Security Check
            RequiresAgencyAdmin(agencyId);

            // Find the Agency
            var agency = UnitOfWork.Find <Agency>(agencyId);

            // Create the role
            var role = agency.CreateRole(name, details.Description);

            // Commit the work
            UnitOfWork.Commit();

            // return the identity of the new role
            return(role.Id);
        }
Пример #2
0
        /// <summary>
        /// Update an Existing Role in the System
        /// </summary>
        public void UpdateRole(Guid roleId, DTO.RoleDetails details)
        {
            // Find the Role
            var role = UnitOfWork.Find <Role>(roleId);

            // Security Check
            RequiresAgencyAdmin(role.AgencyId);

            // Detect Name Changes
            var nameChanged = details.Name != role.Name;

            // Map Details
            details.MapInto(role);

            // Change the Name of the Role
            if (nameChanged)
            {
                role.Agency.ChangeRoleName(role.Id, details.Name);
            }

            // Set AgencyPermissions
            if (details.AgencyPermissions != null)
            {
                role.SetAgencyPermissions(details.AgencyPermissions.As <AgencyPermissions>());
            }

            // Set Module Permissions
            if (details.ModulePermissions != null)
            {
                foreach (var modulePermission in details.ModulePermissions)
                {
                    role.SetModulePermissions(modulePermission.Key, modulePermission.Value.As <ModulePermissions>());
                }
            }

            // Commit the work
            UnitOfWork.Commit();

            // TODO: Hack until the Surrogate Keys are introduced in the Data layer.
            // TODO: Currently the Event messages will get the wrong Id unless they are raised AFTER the database commit
            // TODO: because the database may override the Guid the Domain is trying to use.
            UnitOfWork.PendingMessages.Add(new RoleModifiedMessage(role.Id));
            UnitOfWork.PublishPendingMessages();
        }