public ActionResult Edit(GiftCardModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageGiftCards)) { return(AccessDeniedView()); } var giftCard = _giftCardService.GetGiftCardById(model.Id); model.PurchasedWithOrderId = giftCard.PurchasedWithOrderItem != null ? (int?)giftCard.PurchasedWithOrderItem.OrderId : null; model.RemainingAmountStr = _priceFormatter.FormatPrice(giftCard.GetGiftCardRemainingAmount(), true, false); model.AmountStr = _priceFormatter.FormatPrice(giftCard.Amount, true, false); model.CreatedOn = _dateTimeHelper.ConvertToUserTime(giftCard.CreatedOnUtc, DateTimeKind.Utc); model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode; if (ModelState.IsValid) { giftCard = model.ToEntity(giftCard); _giftCardService.UpdateGiftCard(giftCard); //activity log _customerActivityService.InsertActivity("EditGiftCard", _localizationService.GetResource("ActivityLog.EditGiftCard"), giftCard.GiftCardCouponCode); SuccessNotification(_localizationService.GetResource("Admin.GiftCards.Updated")); return(continueEditing ? RedirectToAction("Edit", giftCard.Id) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Edit(GiftCardModel model, bool continueEditing) { var giftCard = _giftCardService.GetGiftCardById(model.Id); model.PurchasedWithOrderId = giftCard.PurchasedWithOrderItem != null ? (int?)giftCard.PurchasedWithOrderItem.OrderId : null; model.RemainingAmountStr = _priceFormatter.FormatPrice(giftCard.GetGiftCardRemainingAmount(), true, false); model.AmountStr = _priceFormatter.FormatPrice(giftCard.Amount, true, false); model.CreatedOn = _dateTimeHelper.ConvertToUserTime(giftCard.CreatedOnUtc, DateTimeKind.Utc); model.PrimaryStoreCurrencyCode = _services.StoreContext.CurrentStore.PrimaryStoreCurrency.CurrencyCode; if (ModelState.IsValid) { giftCard = model.ToEntity(giftCard); _giftCardService.UpdateGiftCard(giftCard); //activity log _customerActivityService.InsertActivity("EditGiftCard", _services.Localization.GetResource("ActivityLog.EditGiftCard"), giftCard.GiftCardCouponCode); NotifySuccess(_services.Localization.GetResource("Admin.GiftCards.Updated")); return(continueEditing ? RedirectToAction("Edit", giftCard.Id) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form return(View(model)); }
public virtual async Task NotifyRecipient(GiftCard giftCard, GiftCardModel model) { model = giftCard.ToModel(); var order = await FillGiftCardModel(giftCard, model); var languageId = ""; if (order != null) { var customerLang = await _languageService.GetLanguageById(order.CustomerLanguageId); if (customerLang == null) { customerLang = (await _languageService.GetAllLanguages()).FirstOrDefault(); } if (customerLang != null) { languageId = customerLang.Id; } } else { languageId = _localizationSettings.DefaultAdminLanguageId; } int queuedEmailId = await _workflowMessageService.SendGiftCardNotification(giftCard, languageId); if (queuedEmailId > 0) { giftCard.IsRecipientNotified = true; await _giftCardService.UpdateGiftCard(giftCard); model.IsRecipientNotified = true; } }
public virtual void NotifyRecipient(GiftCard giftCard, GiftCardModel model) { model = giftCard.ToModel(); var order = FillGiftCardModel(giftCard, model); var languageId = ""; if (order != null) { var customerLang = _languageService.GetLanguageById(order.CustomerLanguageId); if (customerLang == null) { customerLang = _languageService.GetAllLanguages().FirstOrDefault(); } if (customerLang != null) { languageId = customerLang.Id; } } else { languageId = Grand.Core.Infrastructure.EngineContext.Current.Resolve <LocalizationSettings>().DefaultAdminLanguageId; } int queuedEmailId = _workflowMessageService.SendGiftCardNotification(giftCard, languageId); if (queuedEmailId > 0) { giftCard.IsRecipientNotified = true; _giftCardService.UpdateGiftCard(giftCard); model.IsRecipientNotified = true; } }
public async Task <bool> Handle(ActivatedValueForPurchasedGiftCardsCommand request, CancellationToken cancellationToken) { if (request.Order == null) { throw new ArgumentNullException("order"); } foreach (var orderItem in request.Order.OrderItems) { var giftCards = await _giftCardService.GetAllGiftCards(purchasedWithOrderItemId : orderItem.Id, isGiftCardActivated : !request.Activate); foreach (var gc in giftCards) { if (request.Activate) { //activate bool isRecipientNotified = gc.IsRecipientNotified; if (gc.GiftCardType == GiftCardType.Virtual) { //send email for virtual gift card if (!String.IsNullOrEmpty(gc.RecipientEmail) && !String.IsNullOrEmpty(gc.SenderEmail)) { var customerLang = await _languageService.GetLanguageById(request.Order.CustomerLanguageId); if (customerLang == null) { customerLang = (await _languageService.GetAllLanguages()).FirstOrDefault(); } if (customerLang == null) { throw new Exception("No languages could be loaded"); } int queuedEmailId = await _workflowMessageService.SendGiftCardNotification(gc, customerLang.Id); if (queuedEmailId > 0) { isRecipientNotified = true; } } } gc.IsGiftCardActivated = true; gc.IsRecipientNotified = isRecipientNotified; await _giftCardService.UpdateGiftCard(gc); } else { //deactivate gc.IsGiftCardActivated = false; await _giftCardService.UpdateGiftCard(gc); } } } return(true); }
public virtual IActionResult Edit(GiftCardModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageGiftCards)) { return(AccessDeniedView()); } //try to get a gift card with the specified id var giftCard = _giftCardService.GetGiftCardById(model.Id); if (giftCard == null) { return(RedirectToAction("List")); } model.PurchasedWithOrderId = giftCard.PurchasedWithOrderItem != null ? (int?)giftCard.PurchasedWithOrderItem.OrderId : null; model.RemainingAmountStr = _priceFormatter.FormatPrice(_giftCardService.GetGiftCardRemainingAmount(giftCard), true, false); model.AmountStr = _priceFormatter.FormatPrice(giftCard.Amount, true, false); model.CreatedOn = _dateTimeHelper.ConvertToUserTime(giftCard.CreatedOnUtc, DateTimeKind.Utc); model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode; model.PurchasedWithOrderNumber = giftCard.PurchasedWithOrderItem?.Order.CustomOrderNumber; if (ModelState.IsValid) { giftCard = model.ToEntity(giftCard); _giftCardService.UpdateGiftCard(giftCard); //activity log _customerActivityService.InsertActivity("EditGiftCard", string.Format(_localizationService.GetResource("ActivityLog.EditGiftCard"), giftCard.GiftCardCouponCode), giftCard); SuccessNotification(_localizationService.GetResource("Admin.GiftCards.Updated")); if (!continueEditing) { return(RedirectToAction("List")); } //selected tab SaveSelectedTabName(); return(RedirectToAction("Edit", new { id = giftCard.Id })); } //prepare model model = _giftCardModelFactory.PrepareGiftCardModel(model, giftCard, true); //if we got this far, something failed, redisplay form return(View(model)); }
public ActionResult <GiftCardViewModel> Put(int id, GiftCardViewModel giftCard) { try { return(_giftCardService.UpdateGiftCard(id, giftCard)); } catch (Exception ex) { return(BadRequest(ex)); } }
public string UpdateGiftCard(GiftCard giftCard) => _giftCardService.UpdateGiftCard(giftCard);