public async Task SetServer(CommandContext context, [Description(Descriptions.WowCharacter)] UserWowCharacter character, [Description(Descriptions.WowServer)] WowServer server) { character.Character.WowServerId = server.Id; await m_dbContext.SaveChangesAsync(); }
public async Task <Optional <QualifiedWowCharacter> > ConvertAsync(string value, CommandContext ctx) { if (string.IsNullOrEmpty(value)) { return(Optional.FromNoValue <QualifiedWowCharacter>()); } WowServer server = null; var dbContext = ctx.Services.GetService <InciteDbContext>(); var nameServerPair = value.Split('-'); if (nameServerPair.Length != 2) { var guild = await dbContext.Guilds .Include(x => x.WowServer) .FirstOrDefaultAsync(x => x.DiscordId == ctx.Guild.Id); if (guild?.WowServerId.HasValue == false) { await ctx.Message.RespondAsync("QualifiedWowCharacter must be in the form CharName-ServerName"); return(Optional.FromNoValue <QualifiedWowCharacter>()); } server = guild.WowServer; } server = await dbContext.WowServers .FirstOrDefaultAsync(x => EF.Functions.ILike(x.Name, nameServerPair[1])); if (server == null) { await ctx.Message.RespondAsync("Server not found"); return(Optional.FromNoValue <QualifiedWowCharacter>()); } return(Optional.FromValue(new QualifiedWowCharacter() { Name = nameServerPair[0], Server = server })); }
public async Task SetRealm(CommandContext context, [Description(Descriptions.WowServer)] WowServer server) { Guild.WowServerId = server.Id; await m_dbContext.SaveChangesAsync(); }