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)); }
/// <summary> /// Inserts an entire order from nopcommerce into isam /// </summary> /// <param name="order"></param> public async Task InsertOrderAsync(Order order) { var shipToRows = await _yahooService.GetYahooShipToRowsAsync(order); foreach (var row in shipToRows) { InsertUsingService( SHIPTO_TABLE_NAME, _shiptoCols, _shiptoParams, row.ToStringValues() ); } var headerRows = await _yahooService.GetYahooHeaderRowsAsync(order); foreach (var row in headerRows) { InsertUsingService( HEADER_TABLE_NAME, _headerCols, _headerParams, row.ToStringValues() ); } var detailRows = await _yahooService.GetYahooDetailRowsAsync(order); foreach (var row in detailRows) { InsertUsingService( DETAIL_TABLE_NAME, _detailCols, _detailParams, row.ToStringValues() ); } _baseIsamService.ExecuteBatch(); // store amount used before insert order // insert order changes the amount in the object memory to properly calculate gift card amounts // for multiple orders decimal giftCardAmtUsed = 0; var giftCardUsageHistory = await _giftCardService.GetGiftCardUsageHistoryAsync(order); if (giftCardUsageHistory.Any()) { giftCardAmtUsed = giftCardUsageHistory.OrderByDescending(gcu => gcu.CreatedOnUtc).FirstOrDefault().UsedValue; } // if there is a gift card, update gift card amt in isam if (giftCardUsageHistory.Any()) { GiftCardUsageHistory orderGcUsage = giftCardUsageHistory.FirstOrDefault(); GiftCard orderGiftCard = await _giftCardService.GetGiftCardByIdAsync(orderGcUsage.GiftCardId); var isamGiftCardInfo = _isamGiftCardService.GetGiftCardInfo(orderGiftCard.GiftCardCouponCode); GiftCard isamGiftCard = isamGiftCardInfo.GiftCard; decimal isamGiftCardAmtUsed = isamGiftCardInfo.AmountUsed; _isamGiftCardService.UpdateGiftCardAmt(isamGiftCard, isamGiftCardAmtUsed + giftCardAmtUsed); await _giftCardUsageHistoryRepository.DeleteAsync(orderGcUsage); await _giftCardService.UpdateGiftCardAsync(orderGiftCard); } }