Esempio n. 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);
        }
Esempio n. 2
0
        public async Task GenerateCharacterCardAsync(ulong id)
        {
            using (var db = new Database.UserContext(_config))
            {
                var cards = await db.Cards.Where(x => x.Character == id).ToListAsync();

                if (cards.Count < 1)
                {
                    await "Cards not found!".ToResponse(404).ExecuteResultAsync(ControllerContext);
                    return;
                }

                _ = Task.Run(async() =>
                {
                    foreach (var card in cards)
                    {
                        _ = await _waifu.GenerateAndSaveCardAsync(card);
                    }
                });

                await "Started!".ToResponse(200).ExecuteResultAsync(ControllerContext);
            }
        }