コード例 #1
0
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> Edit(ReturnRequestModel model, bool continueEditing)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageReturnRequests))
            {
                return(AccessDeniedView());
            }

            //try to get a return request with the specified id
            var returnRequest = await _returnRequestService.GetReturnRequestByIdAsync(model.Id);

            if (returnRequest == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                returnRequest = model.ToEntity(returnRequest);
                returnRequest.UpdatedOnUtc = DateTime.UtcNow;

                await _returnRequestService.UpdateReturnRequestAsync(returnRequest);

                //activity log
                await _customerActivityService.InsertActivityAsync("EditReturnRequest",
                                                                   string.Format(await _localizationService.GetResourceAsync("ActivityLog.EditReturnRequest"), returnRequest.Id), returnRequest);

                _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.ReturnRequests.Updated"));

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

            //prepare model
            model = await _returnRequestModelFactory.PrepareReturnRequestModelAsync(model, returnRequest, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #2
0
        public virtual async Task <IActionResult> Edit(ReturnRequestModel model, bool continueEditing)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageReturnRequests))
            {
                return(AccessDeniedView());
            }

            //try to get a return request with the specified id
            var returnRequest = await _returnRequestService.GetReturnRequestByIdAsync(model.Id);

            if (returnRequest == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                var quantityToReturn = model.ReturnedQuantity - returnRequest.ReturnedQuantity;
                if (quantityToReturn < 0)
                {
                    _notificationService.ErrorNotification(string.Format(await _localizationService.GetResourceAsync("Admin.ReturnRequests.Fields.ReturnedQuantity.CannotBeLessThanQuantityAlreadyReturned"), returnRequest.ReturnedQuantity));
                }
                else
                {
                    if (quantityToReturn > 0)
                    {
                        var orderItem = await _orderService.GetOrderItemByIdAsync(returnRequest.OrderItemId);

                        if (orderItem != null)
                        {
                            var product = await _productService.GetProductByIdAsync(orderItem.ProductId);

                            if (product != null)
                            {
                                var productStockChangedMessage = string.Format(await _localizationService.GetResourceAsync("Admin.ReturnRequests.QuantityReturnedToStock"), quantityToReturn);

                                await _productService.AdjustInventoryAsync(product, quantityToReturn, orderItem.AttributesXml, productStockChangedMessage);

                                _notificationService.SuccessNotification(productStockChangedMessage);
                            }
                        }
                    }

                    returnRequest = model.ToEntity(returnRequest);
                    returnRequest.UpdatedOnUtc = DateTime.UtcNow;

                    await _returnRequestService.UpdateReturnRequestAsync(returnRequest);

                    //activity log
                    await _customerActivityService.InsertActivityAsync("EditReturnRequest",
                                                                       string.Format(await _localizationService.GetResourceAsync("ActivityLog.EditReturnRequest"), returnRequest.Id), returnRequest);

                    _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.ReturnRequests.Updated"));

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

            //prepare model
            model = await _returnRequestModelFactory.PrepareReturnRequestModelAsync(model, returnRequest, true);

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