示例#1
0
        /// <summary>
        /// Creates a new user type
        /// </summary>
        /// <param name="name"></param>
        /// <param name="defaultPermissions"></param>
        /// <param name="alias"></param>
        public static UserType MakeNew(string name, string defaultPermissions, string alias)
        {
            //ensure that the current alias does not exist
            //get the id for the new user type
            var existing = UserTypes.Find(ut => (ut.Alias == alias));

            if (existing != null)
            {
                throw new Exception("The UserType alias specified already exists");
            }

            var userType = new Umbraco.Core.Models.Membership.UserType
            {
                Alias       = alias,
                Name        = name,
                Permissions = defaultPermissions.ToCharArray().Select(x => x.ToString(CultureInfo.InvariantCulture))
            };

            ApplicationContext.Current.Services.UserService.SaveUserType(userType);

            var legacy = new UserType(userType);

            //raise event
            OnNew(legacy, new EventArgs());

            return(legacy);
        }
示例#2
0
 /// <summary>
 /// Gets the user type with the specied ID
 /// </summary>
 /// <param name="id">The id.</param>
 /// <returns></returns>
 public static UserType GetUserType(int id)
 {
     return(UserTypes.Find(
                delegate(UserType ut)
     {
         return (ut.Id == id);
     }
                ));
 }
示例#3
0
        public static UserType MakeNew(string name, string defaultPermissions, string alias)
        {
            //ensure that the current alias does not exist
            //get the id for the new user type
            var existing = UserTypes.Find(ut => (ut.Alias == alias));

            if (existing != null)
            {
                throw new Exception("The UserType alias specified already exists");
            }

            SqlHelper.ExecuteNonQuery(@"
				insert into umbracoUserType 
				(userTypeAlias,userTypeName,userTypeDefaultPermissions) 
				values (@alias,@name,@permissions)"                ,
                                      SqlHelper.CreateParameter("@alias", alias),
                                      SqlHelper.CreateParameter("@name", name),
                                      SqlHelper.CreateParameter("@permissions", defaultPermissions));

            //get it's id
            var newId = SqlHelper.ExecuteScalar <int>("SELECT MAX(id) FROM umbracoUserType WHERE userTypeAlias=@alias", SqlHelper.CreateParameter("@alias", alias));

            //load the instance and return it
            using (var dr = SqlHelper.ExecuteReader(
                       "select id, userTypeName, userTypeAlias, userTypeDefaultPermissions from umbracoUserType where id=@id",
                       SqlHelper.CreateParameter("@id", newId)))
            {
                if (dr.Read())
                {
                    var ut = new UserType(
                        dr.GetShort("id"),
                        dr.GetString("userTypeName"),
                        dr.GetString("userTypeDefaultPermissions"),
                        dr.GetString("userTypeAlias"));

                    //raise event
                    OnNew(ut, new EventArgs());

                    return(ut);
                }
                throw new InvalidOperationException("Could not read the new User Type with id of " + newId);
            }
        }
示例#4
0
        /// <summary>
        /// Creates a new user type
        /// </summary>
        /// <param name="name"></param>
        /// <param name="defaultPermissions"></param>
        /// <param name="alias"></param>
        public static UserType MakeNew(string name, string defaultPermissions, string alias)
        {
            //ensure that the current alias does not exist
            //get the id for the new user type
            UserType existing = UserTypes.Find(
                delegate(UserType ut)
            {
                return(ut.Alias == alias);
            }
                );

            if (existing != null)
            {
                throw new Exception("The UserType alias specified already exists");
            }

            SqlHelper.ExecuteNonQuery(@"
				insert into umbracoUserType 
				(userTypeAlias,userTypeName,userTypeDefaultPermissions) 
				values (@alias,@name,@permissions)"                ,
                                      SqlHelper.CreateParameter("@alias", alias),
                                      SqlHelper.CreateParameter("@name", name),
                                      SqlHelper.CreateParameter("@permissions", defaultPermissions));

            ReCache();

            //find the new user type
            existing = UserTypes.Find(
                delegate(UserType ut)
            {
                return(ut.Alias == alias);
            }
                );

            return(existing);
        }
示例#5
0
 /// <summary>
 /// Gets the user type with the specied ID
 /// </summary>
 /// <param name="id">The id.</param>
 /// <returns></returns>
 public static UserType GetUserType(int id)
 {
     return(UserTypes.Find(ut => (ut.Id == id)));
 }