Ejemplo n.º 1
0
    public async Task <Result <GuildDto> > Handle(UpdateGuildSettingsCommand command, CancellationToken cancellationToken)
    {
        if (command == null)
        {
            throw new ArgumentNullException(nameof(command));
        }

        var guild = await _context.Guilds.Include(x => x.GuildSetting).FirstOrDefaultAsync(guild => guild.Id == command.GuildId, cancellationToken);

        if (guild == null)
        {
            throw new ArgumentNullException(nameof(guild));
        }

        var newGuildSettings = _mapper.Map <GuildSetting>(command);

        newGuildSettings.Id               = guild.GuildSetting.Id;
        newGuildSettings.MaxQueueItems    = guild.GuildSetting.MaxQueueItems;
        newGuildSettings.MaxPlaylists     = guild.GuildSetting.MaxPlaylists;
        newGuildSettings.MaxSubscriptions = guild.GuildSetting.MaxSubscriptions;

        guild.GuildSetting = newGuildSettings;

        _context.Guilds.Update(guild);
        await _context.SaveChangesAsync(cancellationToken);

        var mappedGuild = _mapper.Map <GuildDto>(guild);

        mappedGuild.Setting = _mapper.Map <GuildSettingDto>(guild.GuildSetting);
        return(await Result <GuildDto> .SuccessAsync(mappedGuild));
    }
Ejemplo n.º 2
0
 public async Task <IActionResult> Update(UpdateGuildSettingsCommand command)
 {
     return(Ok(await Mediator.Send(command)));
 }