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 virtual IActionResult Create(GiftCardModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageGiftCards)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var giftCard = model.ToEntity <GiftCard>(); giftCard.CreatedOnUtc = DateTime.UtcNow; _giftCardService.InsertGiftCard(giftCard); //activity log _customerActivityService.InsertActivity("AddNewGiftCard", string.Format(_localizationService.GetResource("ActivityLog.AddNewGiftCard"), giftCard.GiftCardCouponCode), giftCard); SuccessNotification(_localizationService.GetResource("Admin.GiftCards.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = giftCard.Id }) : RedirectToAction("List")); } //prepare model model = _giftCardModelFactory.PrepareGiftCardModel(model, null, true); //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 ActionResult Create(GiftCardModel model, bool continueEditing) { if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageGiftCards)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var giftCard = model.ToEntity(); giftCard.CreatedOnUtc = DateTime.UtcNow; _giftCardService.InsertGiftCard(giftCard); //activity log _customerActivityService.InsertActivity("AddNewGiftCard", _services.Localization.GetResource("ActivityLog.AddNewGiftCard"), giftCard.GiftCardCouponCode); NotifySuccess(_services.Localization.GetResource("Admin.GiftCards.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = giftCard.Id }) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form model.PrimaryStoreCurrencyCode = _services.StoreContext.CurrentStore.PrimaryStoreCurrency.CurrencyCode; return(View(model)); }
public virtual GiftCard UpdateGiftCardModel(GiftCard giftCard, GiftCardModel model) { giftCard = model.ToEntity(giftCard); _giftCardService.UpdateGiftCard(giftCard); //activity log _customerActivityService.InsertActivity("EditGiftCard", giftCard.Id, _localizationService.GetResource("ActivityLog.EditGiftCard"), giftCard.GiftCardCouponCode); return(giftCard); }
public virtual GiftCard InsertGiftCardModel(GiftCardModel model) { var giftCard = model.ToEntity(); giftCard.CreatedOnUtc = DateTime.UtcNow; _giftCardService.InsertGiftCard(giftCard); //activity log _customerActivityService.InsertActivity("AddNewGiftCard", giftCard.Id, _localizationService.GetResource("ActivityLog.AddNewGiftCard"), giftCard.GiftCardCouponCode); return(giftCard); }
public virtual async Task <IActionResult> Edit(GiftCardModel model, bool continueEditing) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageGiftCards)) { return(AccessDeniedView()); } //try to get a gift card with the specified id var giftCard = await _giftCardService.GetGiftCardByIdAsync(model.Id); if (giftCard == null) { return(RedirectToAction("List")); } var order = await _orderService.GetOrderByOrderItemAsync(giftCard.PurchasedWithOrderItemId ?? 0); model.PurchasedWithOrderId = order?.Id; model.RemainingAmountStr = await _priceFormatter.FormatPriceAsync(await _giftCardService.GetGiftCardRemainingAmountAsync(giftCard), true, false); model.AmountStr = await _priceFormatter.FormatPriceAsync(giftCard.Amount, true, false); model.CreatedOn = await _dateTimeHelper.ConvertToUserTimeAsync(giftCard.CreatedOnUtc, DateTimeKind.Utc); model.PrimaryStoreCurrencyCode = (await _currencyService.GetCurrencyByIdAsync(_currencySettings.PrimaryStoreCurrencyId)).CurrencyCode; model.PurchasedWithOrderNumber = order?.CustomOrderNumber; if (ModelState.IsValid) { giftCard = model.ToEntity(giftCard); await _giftCardService.UpdateGiftCardAsync(giftCard); //activity log await _customerActivityService.InsertActivityAsync("EditGiftCard", string.Format(await _localizationService.GetResourceAsync("ActivityLog.EditGiftCard"), giftCard.GiftCardCouponCode), giftCard); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.GiftCards.Updated")); if (!continueEditing) { return(RedirectToAction("List")); } return(RedirectToAction("Edit", new { id = giftCard.Id })); } //prepare model model = await _giftCardModelFactory.PrepareGiftCardModelAsync(model, giftCard, true); //if we got this far, something failed, redisplay form return(View(model)); }
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)); }