Ejemplo n.º 1
0
        /// <summary>
        /// Removes a user group.
        /// </summary>
        /// <param name="group">The group to remove.</param>
        /// <returns><c>true</c> if the group is removed, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="group"/> is <c>null</c>.</exception>
        public bool RemoveUserGroup(UserGroup group)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group");
            }

            try {
                UserGroupEntity userGroupEntity = GetUserGroupEntity(_wiki, group.Name);
                // If the group does not exists return false
                if (userGroupEntity == null)
                {
                    return(false);
                }

                CloudTable     table     = _cloudTableClient.GetTableReference(UserGroupsTable);
                TableOperation operation = TableOperation.Delete(userGroupEntity);
                table.Execute(operation);

                _userGroups = null;

                return(true);
            }
            catch (Exception ex) {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes a user group.
        /// </summary>
        /// <param name="group">The group to remove.</param>
        /// <returns><c>true</c> if the group is removed, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="group"/> is <c>null</c>.</exception>
        public bool RemoveUserGroup(UserGroup group)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group");
            }

            try {
                UserGroupEntity userGroupEntity = GetUserGroupEntity(_wiki, group.Name);
                // If the group does not exists return false
                if (userGroupEntity == null)
                {
                    return(false);
                }

                _context.DeleteObject(userGroupEntity);
                _context.SaveChangesStandard();

                _userGroups = null;

                return(true);
            }
            catch (Exception ex) {
                throw ex;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a new user group.
        /// </summary>
        /// <param name="name">The name of the group.</param>
        /// <param name="description">The description of the group.</param>
        /// <returns>The correct <see cref="T:UserGroup"/> object or <c>null</c>.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="name"/> or <paramref name="description"/> are <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="name"/> is empty.</exception>
        public UserGroup AddUserGroup(string name, string description)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentException("Name cannot be empty", "name");
            }
            if (description == null)
            {
                throw new ArgumentNullException("description");
            }

            try {
                // If a group with the given name already exists return null
                if (GetUserGroupEntity(_wiki, name) != null)
                {
                    return(null);
                }

                UserGroupEntity userGroupEntity = new UserGroupEntity()
                {
                    PartitionKey = _wiki,
                    RowKey       = name,
                    Description  = description
                };

                CloudTable     table     = _cloudTableClient.GetTableReference(UserGroupsTable);
                TableOperation operation = TableOperation.Insert(userGroupEntity);
                table.Execute(operation);

                _userGroups = null;

                return(new UserGroup(name, description, this));
            }
            catch (Exception ex) {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds a new user group.
        /// </summary>
        /// <param name="name">The name of the group.</param>
        /// <param name="description">The description of the group.</param>
        /// <returns>The correct <see cref="T:UserGroup"/> object or <c>null</c>.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="name"/> or <paramref name="description"/> are <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="name"/> is empty.</exception>
        public UserGroup AddUserGroup(string name, string description)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentException("Name cannot be empty", "name");
            }
            if (description == null)
            {
                throw new ArgumentNullException("description");
            }

            try {
                // If a group with the given name already exists return null
                if (GetUserGroupEntity(_wiki, name) != null)
                {
                    return(null);
                }

                UserGroupEntity userGroupEntity = new UserGroupEntity()
                {
                    PartitionKey = _wiki,
                    RowKey       = name,
                    Description  = description
                };

                _context.AddObject(UserGroupsTable, userGroupEntity);
                _context.SaveChangesStandard();

                _userGroups = null;

                return(new UserGroup(name, description, this));
            }
            catch (Exception ex) {
                throw ex;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Modifies a user group.
        /// </summary>
        /// <param name="group">The group to modify.</param>
        /// <param name="description">The new description of the group.</param>
        /// <returns>The correct <see cref="T:UserGroup"/> object or <c>null</c>.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="group"/> or <paramref name="description"/> are <c>null</c>.</exception>
        public UserGroup ModifyUserGroup(UserGroup group, string description)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group");
            }
            if (description == null)
            {
                throw new ArgumentNullException("description");
            }

            try {
                UserGroupEntity userGroupEntity = GetUserGroupEntity(_wiki, group.Name);
                // If the userGroup does not exists return null
                if (userGroupEntity == null)
                {
                    return(null);
                }

                userGroupEntity.Description = description;

                CloudTable     table     = _cloudTableClient.GetTableReference(UserGroupsTable);
                TableOperation operation = TableOperation.Replace(userGroupEntity);
                table.Execute(operation);

                _userGroups = null;

                return(new UserGroup(group.Name, description, this)
                {
                    Users = (from u in GetUsers()
                             where u.Groups.ToList().Contains(userGroupEntity.RowKey)
                             select u.Username).ToArray()
                });
            }
            catch (Exception ex) {
                throw ex;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Modifies a user group.
        /// </summary>
        /// <param name="group">The group to modify.</param>
        /// <param name="description">The new description of the group.</param>
        /// <returns>The correct <see cref="T:UserGroup"/> object or <c>null</c>.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="group"/> or <paramref name="description"/> are <c>null</c>.</exception>
        public UserGroup ModifyUserGroup(UserGroup group, string description)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group");
            }
            if (description == null)
            {
                throw new ArgumentNullException("description");
            }

            try {
                UserGroupEntity userGroupEntity = GetUserGroupEntity(_wiki, group.Name);
                // If the userGroup does not exists return null
                if (userGroupEntity == null)
                {
                    return(null);
                }

                userGroupEntity.Description = description;

                _context.UpdateObject(userGroupEntity);
                _context.SaveChangesStandard();

                _userGroups = null;

                return(new UserGroup(group.Name, description, this)
                {
                    Users = (from u in GetUsers()
                             where u.Groups.ToList().Contains(userGroupEntity.RowKey)
                             select u.Username).ToArray()
                });
            }
            catch (Exception ex) {
                throw ex;
            }
        }