public async Task <IActionResult> UpdateClashAPIPlugin([FromRoute] string guildId, [FromBody] ClashAPIPluginDto clashAPIPluginDto) { var result = await _pluginService.UpdateClashAPIPluginAsync(guildId, clashAPIPluginDto, await _userManager.GetUserAsync(User)); if (!result) { return(BadRequest()); } return(Ok()); }
public async Task <bool> UpdateClashAPIPluginAsync(string guildId, ClashAPIPluginDto clashAPIPluginDto, User user) { try { var guild = await _guildService.GetByGuildIdAsync(guildId); var discordGuild = await _botService.GetGuildAsync(guildId); var member = await discordGuild.GetMemberAsync(ulong.Parse(user.UserId)); var hasPermission = await CheckIfHasPermissionAsync(member, discordGuild, guild); if (!hasPermission) { return(false); } if (clashAPIPluginDto.IsEnabled != guild.ClashAPIPlugin.IsEnabled) { guild.ClashAPIPlugin.IsEnabled = clashAPIPluginDto.IsEnabled; } var initiator = await _userService.GetByUsernameAndDiscriminatorAsync(user.UserName, user.Discriminator); // TODO: log await _pluginRepository.SaveAllAsync(); return(true); } catch (Exception e) { Console.WriteLine(e); return(false); } }