Example #1
0
        public async Task UpdateCardInfoAsync(ulong id, [FromBody] Models.CharacterCardInfoUpdate newData)
        {
            var exe = new Executable($"update cards-{id} img", new Task(() =>
            {
                using (var db = new Database.UserContext(_config))
                {
                    var userRelease = new List <string>()
                    {
                        "users"
                    };
                    var cards = db.Cards.Where(x => x.Character == id);

                    foreach (var card in cards)
                    {
                        if (newData?.ImageUrl != null)
                        {
                            card.Image = newData.ImageUrl;
                        }

                        if (newData?.CharacterName != null)
                        {
                            card.Name = newData.CharacterName;
                        }

                        if (newData?.CardSeriesTitle != null)
                        {
                            card.Title = newData.CardSeriesTitle;
                        }

                        try
                        {
                            _waifu.DeleteCardImageIfExist(card);
                            _ = _waifu.GenerateAndSaveCardAsync(card).Result;
                        }
                        catch (Exception) { }

                        userRelease.Add($"user-{card.GameDeckId}");
                    }

                    db.SaveChanges();

                    QueryCacheManager.ExpireTag(userRelease.ToArray());
                }
            }));

            await _executor.TryAdd(exe, TimeSpan.FromSeconds(1));

            await "Started!".ToResponse(200).ExecuteResultAsync(ControllerContext);
        }
Example #2
0
        public async Task ForceUpdateCardsAsync([Summary("WID kart")] params ulong[] ids)
        {
            using (var db = new Database.UserContext(Config))
            {
                var cards = db.Cards.Where(x => ids.Any(c => c == x.Id)).ToList();
                if (cards.Count < 1)
                {
                    await ReplyAsync("", embed : $"{Context.User.Mention} nie odnaleziono kart.".ToEmbedMessage(EMType.Error).Build());

                    return;
                }

                foreach (var card in cards)
                {
                    try
                    {
                        await card.Update(null, _shClient);

                        _waifu.DeleteCardImageIfExist(card);
                    }
                    catch (Exception) { }
                }

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"users" });

                await ReplyAsync("", embed : $"Zaktualizowano {cards.Count} kart.".ToEmbedMessage(EMType.Success).Build());
            }
        }