public async Task <IActionResult> WishlistItem(Guid accountId, Guid itemId, CancellationToken token = default)
    {
        var account = await _accountRepository.GetAsync(accountId, token);

        var item = new KeyValuePair <int, WishlistItem>();

        foreach (var year in account.Wishlist.Keys)
        {
            if (account.Wishlist[year].FirstOrDefault(x => x.Id == itemId) is WishlistItem match)
            {
                item = new KeyValuePair <int, WishlistItem>(year, match);
                break;
            }
        }

        if (item.Value.PreviewImage == null || item.Value.PreviewImage.Length == 0)
        {
            account.Wishlist[item.Key].Remove(item.Value);
            item.Value.PreviewImage = await _previewGenerator.GeneratePreviewAsync(item.Value.Url, token);

            account.Wishlist[item.Key].Add(item.Value);

            await _accountRepository.SaveAsync(account, token);
        }

        return(File(item.Value.PreviewImage, "image/jpg"));
    }
Example #2
0
    public async Task <IActionResult> AddItem(WishlistItem model, CancellationToken token = default)
    {
        if (ModelState.IsValid && await this.GetAccountAsync(_accountRepository, token) is Account account)
        {
            if (!account.Wishlist.ContainsKey(DateHelper.Year))
            {
                account.Wishlist.Add(DateHelper.Year, new List <WishlistItem>());
            }

            model.Id           = Guid.NewGuid();
            model.PreviewImage = await _previewGenerator.GeneratePreviewAsync(model.Url, token);

            account.Wishlist[DateHelper.Year].Add(model);

            await _accountRepository.SaveAsync(account, token);

            this.SetResultMessage($"<strong>Successfully added</strong> {model.Name}.");
        }

        return(RedirectToAction("Index", new { t = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }));
    }