Example #1
0
        /// <summary>
        /// Saves the role object
        /// </summary>
        /// <returns><c>true</c> if successful</returns>
        public static bool SaveOrUpdate(Role entity)
        {
            if (entity == null) throw new ArgumentNullException("entity");
            if (entity.ProjectId <= Globals.NEW_ID) throw (new ArgumentException("Cannot save role, the project id is invalid"));
            if (string.IsNullOrEmpty(entity.Name)) throw (new ArgumentException("The role name cannot be empty or null"));

            if (entity.Id > Globals.NEW_ID)
                return DataProviderManager.Provider.UpdateRole(entity);

            var tempId = DataProviderManager.Provider.CreateNewRole(entity);
            if (tempId <= 0) return false;
            entity.Id = tempId;
            return true;
        }
Example #2
0
        /// <summary>
        /// Associates the default roles created at installation to a project.
        /// </summary>
        /// <param name="projectId">The project id.</param>
        public static void CreateDefaultProjectRoles(int projectId)
        {
            if (projectId <= Globals.NEW_ID)
                throw (new ArgumentOutOfRangeException("projectId"));

            foreach (var role in Globals.DefaultRoles)
            {
                var r = new Role { ProjectId = projectId, Name = role, Description = role, AutoAssign = false};
                var newRoleId = DataProviderManager.Provider.CreateNewRole(r);

                int[] permissions = null;
                //add permissions to roles
                switch (role)
                {
                    case "Project Administrators":
                        permissions = Globals.AdministratorPermissions;
                        break;
                    case "Read Only":
                        permissions = Globals.ReadOnlyPermissions;
                        break;
                    case "Reporter":
                        permissions = Globals.ReporterPermissions;
                        break;
                    case "Developer":
                        permissions = Globals.DeveloperPermissions;
                        break;
                    case "Quality Assurance":
                        permissions = Globals.QualityAssurancePermissions;
                        break;
                }

                if (permissions != null)
                    foreach (var i in permissions)
                    {
                        AddPermission(newRoleId, i);
                    }
            }
        }
Example #3
0
        /// <summary>
        /// Creates the new role.
        /// </summary>
        /// <param name="newRole">The new role.</param>
        /// <returns></returns>
        public override int CreateNewRole(Role newRole)
        {
            // Validate Parameters
            if (newRole == null) throw (new ArgumentNullException("newRole"));

            try
            {
                using (var sqlCmd = new SqlCommand())
                {
                    AddParamToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
                    AddParamToSqlCmd(sqlCmd, "@RoleName", SqlDbType.NText, 256, ParameterDirection.Input, newRole.Name);
                    AddParamToSqlCmd(sqlCmd, "@RoleDescription", SqlDbType.NText, 1000, ParameterDirection.Input, newRole.Description);
                    AddParamToSqlCmd(sqlCmd, "@AutoAssign", SqlDbType.Bit, 0, ParameterDirection.Input, newRole.AutoAssign);
                    AddParamToSqlCmd(sqlCmd, "@ProjectId", SqlDbType.Int, 0, ParameterDirection.Input, newRole.ProjectId);

                    SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_ROLE_CREATE);
                    ExecuteScalarCmd(sqlCmd);
                    return ((int)sqlCmd.Parameters["@ReturnValue"].Value);   
                }
            }
            catch (Exception ex)
            {
                throw ProcessException(ex);
            }
        }
Example #4
0
 public abstract int CreateNewRole(Role newRole);
Example #5
0
 public abstract bool UpdateRole(Role roleToUpdate);
Example #6
0
        /// <summary>
        /// Creates the role.
        /// </summary>
        /// <param name="roleName">Name of the role.</param>
        /// <param name="projectId">The project id.</param>
        /// <param name="description">The description.</param>
        /// <param name="autoAssign">if set to <c>true</c> [auto assign].</param>
        /// <returns></returns>
        public static int CreateRole(string roleName, int projectId, string description, bool autoAssign)
        {
            if (!Exists(roleName, projectId))
            {
                var r = new Role {ProjectId = projectId, Name = roleName, Description = description, AutoAssign = autoAssign};
                SaveOrUpdate(r);
                return r.Id;
            }

            return 0;
        }