public async Task ShopListAdd(int index, [Remainder] string itemText) { index -= 1; if (index < 0) { return; } var item = new ShopEntryItem() { Text = itemText }; ShopEntry entry; bool rightType = false; bool added = false; using (var uow = _db.UnitOfWork) { var entries = new IndexedCollection <ShopEntry>(uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.ShopEntries) .ThenInclude(x => x.Items)).ShopEntries); entry = entries.ElementAtOrDefault(index); if (entry != null && (rightType = (entry.Type == ShopEntryType.List))) { if (added = entry.Items.Add(item)) { uow.Complete(); } } } if (entry == null) { await ReplyErrorLocalized("shop_item_not_found").ConfigureAwait(false); } else if (!rightType) { await ReplyErrorLocalized("shop_item_wrong_type").ConfigureAwait(false); } else if (added == false) { await ReplyErrorLocalized("shop_list_item_not_unique").ConfigureAwait(false); } else { await ReplyConfirmLocalized("shop_list_item_added").ConfigureAwait(false); } }
public async Task ShopListAdd(int index, [Remainder] string itemText) { index -= 1; if (index < 0) { return; } var item = new ShopEntryItem { Text = itemText }; var entries = new IndexedCollection <ShopEntry>(uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.ShopEntries).ThenInclude(x => x.Items)).ShopEntries); var entry = entries.ElementAtOrDefault(index); if (entry != null) { if (entry.Type == ShopEntryType.List) { if (entry.Items.Add(item)) { await uow.SaveChangesAsync(false).ConfigureAwait(false); await ReplyConfirmLocalized("shop_list_item_added").ConfigureAwait(false); } else { await ReplyErrorLocalized("shop_list_item_not_unique").ConfigureAwait(false); } } else { await ReplyErrorLocalized("shop_item_wrong_type").ConfigureAwait(false); } } else { await ReplyErrorLocalized("shop_item_not_found").ConfigureAwait(false); } }