示例#1
0
        public IActionResult Save(ReceivedGift model)
        {
            if (ModelState.IsValid)
            {
                model.Save(User.GetAccount());
                this.SetResultMessage("Successfully updated your recieved gift info.");
            }

            return(RedirectToAction("Index"));
        }
示例#2
0
        //[ResponseCache(Location = ResponseCacheLocation.Any, Duration = int.MaxValue, VaryByHeader = "Cookie", VaryByQueryKeys = new[] { "accountId" })]
        public IActionResult Image(Guid accountId)
        {
            var          account = DataRepository.Get <Account>(accountId);
            ReceivedGift gift    = account.ReceivedGift[DateHelper.Year];

            if (gift.Image == null || gift.Image.Length == 0)
            {
                return(null);
            }

            return(File(gift.Image, "image/jpg"));
        }
    public async Task <IActionResult> Save(ReceivedGift model, CancellationToken token = default)
    {
        if (ModelState.IsValid && await this.GetAccountAsync(_accountRepository, token) is Account account)
        {
            if (model.ImageUpload is not null && model.ImageUpload.Length > 0)
            {
                using var imageStream = model.ImageUpload.OpenReadStream();

                model.Image = ImageResizer.ResizeJpg(imageStream);
            }

            account.ReceivedGift[DateHelper.Year] = model;

            await _accountRepository.SaveAsync(account, token);

            this.SetResultMessage("Successfully updated your recieved gift info.");
        }

        return(RedirectToAction("Index"));
    }