public static async Task <bool> TakeItem(Database.BodyPart item) { if (item.Id != null) { return(await TakeItem(item.Id.ToString())); } else { return(await TakeItem(await TryFindId(item))); } }
/// <summary> /// Last resort method, meant to prevent critical error (when something doesn't have ID) /// </summary> private async static Task <GenericItem> TryFindId(Database.BodyPart item) { // if some of our items do not have ID - this is critical, we cant send requests because of that // so we will try to find item which will fit to us { if (item is Database.Organ) { List <EjectedOrgan> abstracts = await GetAbstractOrgans(); foreach (EjectedOrgan v in abstracts) { if (v.slot == item.SlotString && v.race == item.Race.GetDescription() && v.genderInverted == item.Gender) { item.Id = v.id; // fix this organ for future return(v); } } } else { List <PrimaryAugment> abstracts = await GetAbstractAugments(); foreach (PrimaryAugment v in abstracts) { if (v.slot == item.SlotString && v.race == item.Race.GetDescription() && v.genderInverted == item.Gender) { item.Id = v.id; // fix this augment for future return(v); } } } // and if we fail to find that item - nothing to do, this is critical error, throw exception throw new InvalidOperationException("Критическая ошибка работы базы данных: Непроидентифицированный BodyPart. Не удалось разрешить проблему перебором данных сервера."); } }