;mp almost fixed. Might need a rework >.>
This commit is contained in:
		@@ -8,7 +8,7 @@ using NadekoBot.Services.Database.Impl;
 | 
				
			|||||||
namespace NadekoBot.Migrations
 | 
					namespace NadekoBot.Migrations
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    [DbContext(typeof(NadekoSqliteContext))]
 | 
					    [DbContext(typeof(NadekoSqliteContext))]
 | 
				
			||||||
    [Migration("20161005030440_first")]
 | 
					    [Migration("20161007091612_first")]
 | 
				
			||||||
    partial class first
 | 
					    partial class first
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        protected override void BuildTargetModel(ModelBuilder modelBuilder)
 | 
					        protected override void BuildTargetModel(ModelBuilder modelBuilder)
 | 
				
			||||||
@@ -6,6 +6,7 @@ using NadekoBot.Services.Database;
 | 
				
			|||||||
using NadekoBot.Services.Database.Models;
 | 
					using NadekoBot.Services.Database.Models;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Diagnostics;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
using System.Text;
 | 
					using System.Text;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
@@ -159,8 +160,7 @@ namespace NadekoBot.Modules.Permissions
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            if (index == 0)
 | 
					            if (index == 0)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                perm.Previous = toAdd;
 | 
					                perm.Prepend(toAdd);
 | 
				
			||||||
                toAdd.Next = perm;
 | 
					 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -91,7 +91,8 @@ namespace NadekoBot.Modules.Permissions
 | 
				
			|||||||
                Permission p;
 | 
					                Permission p;
 | 
				
			||||||
                using (var uow = DbHandler.UnitOfWork())
 | 
					                using (var uow = DbHandler.UnitOfWork())
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    var perms = uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission;
 | 
					                    var config = uow.GuildConfigs.PermissionsFor(channel.Guild.Id);
 | 
				
			||||||
 | 
					                    var perms = config.RootPermission;
 | 
				
			||||||
                    if (index == perms.Count() - 1)
 | 
					                    if (index == perms.Count() - 1)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        return;
 | 
					                        return;
 | 
				
			||||||
@@ -99,7 +100,7 @@ namespace NadekoBot.Modules.Permissions
 | 
				
			|||||||
                    else if (index == 0)
 | 
					                    else if (index == 0)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        p = perms;
 | 
					                        p = perms;
 | 
				
			||||||
                        uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = perms.Next;
 | 
					                        config.RootPermission = perms.Next;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    else
 | 
					                    else
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
@@ -114,7 +115,7 @@ namespace NadekoBot.Modules.Permissions
 | 
				
			|||||||
                    uow2._context.SaveChanges();
 | 
					                    uow2._context.SaveChanges();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                await channel.SendMessageAsync($"{imsg.Author.Mention} removed permission **{p.GetCommand()}** from position #{index + 1}.").ConfigureAwait(false);
 | 
					                await channel.SendMessageAsync($"{imsg.Author.Mention} removed permission **{p.GetCommand(channel.Guild)}** from position #{index + 1}.").ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            catch (ArgumentOutOfRangeException)
 | 
					            catch (ArgumentOutOfRangeException)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@@ -136,21 +137,29 @@ namespace NadekoBot.Modules.Permissions
 | 
				
			|||||||
                    Permission toInsert;
 | 
					                    Permission toInsert;
 | 
				
			||||||
                    using (var uow = DbHandler.UnitOfWork())
 | 
					                    using (var uow = DbHandler.UnitOfWork())
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        var perms = uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission;
 | 
					                        var config = uow.GuildConfigs.PermissionsFor(channel.Guild.Id);
 | 
				
			||||||
 | 
					                        var perms = config.RootPermission;
 | 
				
			||||||
                        if (from == 0)
 | 
					                        if (from == 0)
 | 
				
			||||||
 | 
					                        {
 | 
				
			||||||
                            toInsert = perms;
 | 
					                            toInsert = perms;
 | 
				
			||||||
 | 
					                            perms = perms.Next;
 | 
				
			||||||
 | 
					                            toInsert.Previous = null;
 | 
				
			||||||
 | 
					                            toInsert.Next = null;
 | 
				
			||||||
 | 
					                            perms.Previous = null;
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
                        else
 | 
					                        else
 | 
				
			||||||
 | 
					                        {
 | 
				
			||||||
                            toInsert = perms.RemoveAt(from);
 | 
					                            toInsert = perms.RemoveAt(from);
 | 
				
			||||||
                        if (from < to)
 | 
					                            toInsert.Previous = null;
 | 
				
			||||||
                            to -= 1;
 | 
					                        }
 | 
				
			||||||
                        var last = perms.Count() - 1;
 | 
					                        var size = perms.Count();
 | 
				
			||||||
                        if (from == last || to == last)
 | 
					                        if (from == size || to == size)
 | 
				
			||||||
                            throw new IndexOutOfRangeException();
 | 
					                            throw new IndexOutOfRangeException();
 | 
				
			||||||
                        perms.Insert(to, toInsert);
 | 
					                        perms.Insert(to, toInsert);
 | 
				
			||||||
                        uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = perms.GetRoot();
 | 
					                        config.RootPermission = perms.GetRoot();
 | 
				
			||||||
                        await uow.CompleteAsync().ConfigureAwait(false);
 | 
					                        await uow.CompleteAsync().ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    await channel.SendMessageAsync($"`Moved permission:` \"{toInsert.GetCommand()}\" `from #{from} to #{to}.`").ConfigureAwait(false);
 | 
					                    await channel.SendMessageAsync($"`Moved permission:` \"{toInsert.GetCommand(channel.Guild)}\" `from #{from} to #{to}.`").ConfigureAwait(false);
 | 
				
			||||||
                    return;
 | 
					                    return;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                catch (Exception e) when (e is ArgumentOutOfRangeException || e is IndexOutOfRangeException)
 | 
					                catch (Exception e) when (e is ArgumentOutOfRangeException || e is IndexOutOfRangeException)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,12 +1,14 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using System.ComponentModel.DataAnnotations.Schema;
 | 
					using System.ComponentModel.DataAnnotations.Schema;
 | 
				
			||||||
 | 
					using System.Diagnostics;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
using System.Text;
 | 
					using System.Text;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Services.Database.Models
 | 
					namespace NadekoBot.Services.Database.Models
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    [DebuggerDisplay("{global::NadekoBot.Modules.Permissions.PermissionExtensions.GetCommand(this)}", Target = typeof(Permission))]
 | 
				
			||||||
    public class Permission : DbEntity
 | 
					    public class Permission : DbEntity
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public Permission Previous { get; set; } = null;
 | 
					        public Permission Previous { get; set; } = null;
 | 
				
			||||||
@@ -49,6 +51,15 @@ namespace NadekoBot.Services.Database.Models
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            return blockNsfw;
 | 
					            return blockNsfw;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public Permission Clone() => new Permission()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            PrimaryTarget = PrimaryTarget,
 | 
				
			||||||
 | 
					            SecondaryTarget = SecondaryTarget,
 | 
				
			||||||
 | 
					            PrimaryTargetId = PrimaryTargetId,
 | 
				
			||||||
 | 
					            SecondaryTargetName = SecondaryTargetName,
 | 
				
			||||||
 | 
					            State = State,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public enum PrimaryPermissionType
 | 
					    public enum PrimaryPermissionType
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -186,8 +186,8 @@ namespace NadekoBot.Services.Database
 | 
				
			|||||||
            var permissionEntity = modelBuilder.Entity<Permission>();
 | 
					            var permissionEntity = modelBuilder.Entity<Permission>();
 | 
				
			||||||
            permissionEntity
 | 
					            permissionEntity
 | 
				
			||||||
                .HasOne(p => p.Next)
 | 
					                .HasOne(p => p.Next)
 | 
				
			||||||
                .WithOne(p => p.Previous);
 | 
					                .WithOne(p => p.Previous)
 | 
				
			||||||
 | 
					                .IsRequired(false);
 | 
				
			||||||
            #endregion
 | 
					            #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            #region LogSettings
 | 
					            #region LogSettings
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user