Example #1
0
        public async Task SetUp()
        {
            _giftCardService = GetService <IGiftCardService>();

            _giftCard1 = new GiftCard {
                Amount = 100, IsGiftCardActivated = true
            };
            _giftCard2 = new GiftCard {
                Amount = 100
            };

            await _giftCardService.InsertGiftCardAsync(_giftCard1);

            await _giftCardService.InsertGiftCardAsync(_giftCard2);
        }
        public virtual async Task <IActionResult> Create(GiftCardModel model, bool continueEditing)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageGiftCards))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var giftCard = model.ToEntity <GiftCard>();
                giftCard.CreatedOnUtc = DateTime.UtcNow;
                await _giftCardService.InsertGiftCardAsync(giftCard);

                //activity log
                await _customerActivityService.InsertActivityAsync("AddNewGiftCard",
                                                                   string.Format(await _localizationService.GetResourceAsync("ActivityLog.AddNewGiftCard"), giftCard.GiftCardCouponCode), giftCard);

                _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.GiftCards.Added"));

                return(continueEditing ? RedirectToAction("Edit", new { id = giftCard.Id }) : RedirectToAction("List"));
            }

            //prepare model
            model = await _giftCardModelFactory.PrepareGiftCardModelAsync(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }