Fixed crash

This commit is contained in:
Kwoth 2016-10-14 23:18:07 +02:00
parent c46fd50c12
commit dacfc1f8ea

View File

@ -66,35 +66,40 @@ namespace NadekoBot.Modules.Utility
} }
public async Task UpdateCurrency() public async Task UpdateCurrency()
{ {try
var currencyRates = await UpdateCurrencyRates();
var unitTypeString = "currency";
var range = currencyRates.ConversionRates.Select(u => new ConvertUnit()
{ {
InternalTrigger = u.Key, var currencyRates = await UpdateCurrencyRates();
Modifier = u.Value, var unitTypeString = "currency";
UnitType = unitTypeString var range = currencyRates.ConversionRates.Select(u => new ConvertUnit()
}).ToArray(); {
var baseType = new ConvertUnit() InternalTrigger = u.Key,
{ Modifier = u.Value,
Triggers = new[] { currencyRates.Base }, UnitType = unitTypeString
Modifier = decimal.One, }).ToArray();
UnitType = unitTypeString var baseType = new ConvertUnit()
}; {
var toRemove = Units.Where(u => u.UnitType == unitTypeString); Triggers = new[] { currencyRates.Base },
Modifier = decimal.One,
UnitType = unitTypeString
};
var toRemove = Units.Where(u => u.UnitType == unitTypeString);
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
uow.ConverterUnits.RemoveRange(toRemove.ToArray()); uow.ConverterUnits.RemoveRange(toRemove.ToArray());
uow.ConverterUnits.Add(baseType); uow.ConverterUnits.Add(baseType);
uow.ConverterUnits.AddRange(range); uow.ConverterUnits.AddRange(range);
await uow.CompleteAsync().ConfigureAwait(false); await uow.CompleteAsync().ConfigureAwait(false);
}
Units.RemoveAll(u => u.UnitType == unitTypeString);
Units.Add(baseType);
Units.AddRange(range);
_log.Info("Updated Currency");
}
catch {
_log.Warn("Failed updating currency.");
} }
Units.RemoveAll(u => u.UnitType == unitTypeString);
Units.Add(baseType);
Units.AddRange(range);
_log.Info("Updated Currency");
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]