Пример #1
0
        /// <summary>
        /// Deletes this channel
        /// </summary>
        public async Task <TaskResult <int> > TryDeleteAsync(ServerPlanetMember member, ValourDB db)
        {
            Planet ??= await GetPlanetAsync(db);

            if (Id == Planet.Main_Channel_Id)
            {
                return(new TaskResult <int>(false, $"Cannot delete main channel", 400));
            }

            if (member == null)
            {
                return(new TaskResult <int>(false, "Member not found", 403));
            }

            if (!await HasPermission(member, ChatChannelPermissions.View, db))
            {
                return(new TaskResult <int>(false, "Member lacks ChatChannelPermissions.View", 403));
            }

            if (!await HasPermission(member, ChatChannelPermissions.ManageChannel, db))
            {
                return(new TaskResult <int>(false, "Member lacks ChatChannelPermissions.ManageChannel", 403));
            }

            // Remove permission nodes
            db.ChatChannelPermissionsNodes.RemoveRange(
                db.ChatChannelPermissionsNodes.Where(x => x.Channel_Id == Id)
                );

            // Remove messages
            db.PlanetMessages.RemoveRange(
                db.PlanetMessages.Where(x => x.Channel_Id == Id)
                );

            // Remove channel
            db.PlanetChatChannels.Remove(
                await db.PlanetChatChannels.FirstOrDefaultAsync(x => x.Id == Id)
                );

            // Save changes
            await db.SaveChangesAsync();

            // Notify channel deletion
            await PlanetHub.NotifyChatChannelDeletion(this);

            return(new TaskResult <int>(true, "Success", 200));
        }
Пример #2
0
 /// <summary>
 /// Notifies all clients that this channel has changed
 /// </summary>
 public void NotifyClientsChange()
 {
     PlanetHub.NotifyChatChannelChange(this);
 }