public ServiceResult DeleteBlockedRole(BlockedRole n)
        {
            if (CurrentUser == null)
            {
                return(ServiceResponse.Error("You must be logged in to access this function."));
            }

            RoleManager roleManager = new RoleManager(Globals.DBConnectionKey, CurrentUser);

            return(roleManager.DeleteBlockedRole(n, CurrentUser));
        }
        public ServiceResult InsertBlockedRole(BlockedRole n)
        {
            if (CurrentUser == null)
            {
                return(ServiceResponse.Error("You must be logged in to access this function."));
            }

            n.AccountUUID = CurrentUser.AccountUUID;
            n.CreatedBy   = CurrentUser.UUID;
            n.DateCreated = DateTime.UtcNow;

            RoleManager roleManager = new RoleManager(Globals.DBConnectionKey, CurrentUser);

            return(roleManager.AddBlockedRole(n, CurrentUser));
        }
        public ServiceResult SaveBlockedRoles()
        {
            if (CurrentUser == null)
            {
                return(ServiceResponse.Error("You must be logged in to access this function."));
            }

            string body = Request.Content.ReadAsStringAsync().Result;

            if (string.IsNullOrEmpty(body))
            {
                return(ServiceResponse.Error("No roles were sent."));
            }

            var commands = JsonConvert.DeserializeObject <List <BatchCommand> >(body);

            if (commands == null)
            {
                return(ServiceResponse.Error("Invalid roles posted to server."));
            }

            RoleManager rm = new RoleManager(Globals.DBConnectionKey, CurrentUser);

            ServiceResult res = ServiceResponse.OK("");

            foreach (var command in commands)
            {
                if (string.IsNullOrWhiteSpace(command.Command) || string.IsNullOrWhiteSpace(command.UUID))
                {
                    continue;
                }

                var rs = rm.Get(command.UUID);
                if (rs == null || rs.Code != 200)
                {
                    return(ServiceResponse.Error("Role not found for id:" + command.UUID));
                }

                var r = (Role)rs.Result;

                switch (command.Command.ToLower())
                {
                case "add":
                    var br = new BlockedRole()
                    {
                        Name          = r.Name,
                        AccountUUID   = CurrentUser.AccountUUID,
                        Active        = true,
                        CreatedBy     = CurrentUser.UUID,
                        DateCreated   = DateTime.UtcNow,
                        RoleUUID      = r.UUID,
                        RoleOperation = r.RoleOperation,
                        RoleWeight    = r.RoleWeight,
                        ReferenceUUID = CurrentUser.UUID,
                        ReferenceType = CurrentUser.UUIDType,
                        TargetUUID    = r.UUID,
                        TargetType    = r.UUIDType
                    };

                    rm.AddBlockedRole(br, CurrentUser);

                    break;

                case "remove":
                    var blockedRole = rm.GetBlockedRoles(CurrentUser.UUID, CurrentUser.AccountUUID).FirstOrDefault(w => w.RoleUUID == command.UUID);
                    if (blockedRole == null)
                    {
                        continue;
                    }

                    res = rm.DeleteBlockedRole(blockedRole, CurrentUser);
                    break;
                }

                if (res.Code != 200)
                {
                    return(res);
                }
            }

            return(ServiceResponse.OK(""));
        }