/// <summary>
        /// Prepare the customer return requests model
        /// </summary>
        /// <returns>Customer return requests model</returns>
        public virtual CustomerReturnRequestsModel PrepareCustomerReturnRequestsModel()
        {
            var model = new CustomerReturnRequestsModel();

            var returnRequests = _returnRequestService.SearchReturnRequests(_storeContext.CurrentStore.Id, _workContext.CurrentCustomer.Id);

            foreach (var returnRequest in returnRequests)
            {
                var subscriptionItem = _subscriptionService.GetSubscriptionItemById(returnRequest.SubscriptionItemId);
                if (subscriptionItem != null)
                {
                    var article  = subscriptionItem.Article;
                    var download = _downloadService.GetDownloadById(returnRequest.UploadedFileId);

                    var itemModel = new CustomerReturnRequestsModel.ReturnRequestModel
                    {
                        Id                  = returnRequest.Id,
                        CustomNumber        = returnRequest.CustomNumber,
                        ReturnRequestStatus = returnRequest.ReturnRequestStatus.GetLocalizedEnum(_localizationService, _workContext),
                        ArticleId           = article.Id,
                        ArticleName         = article.GetLocalized(x => x.Name),
                        ArticleSeName       = article.GetSeName(),
                        Quantity            = returnRequest.Quantity,
                        ReturnAction        = returnRequest.RequestedAction,
                        ReturnReason        = returnRequest.ReasonForReturn,
                        Comments            = returnRequest.CustomerComments,
                        UploadedFileGuid    = download != null ? download.DownloadGuid : Guid.Empty,
                        CreatedOn           = _dateTimeHelper.ConvertToUserTime(returnRequest.CreatedOnUtc, DateTimeKind.Utc),
                    };
                    model.Items.Add(itemModel);
                }
            }

            return(model);
        }
        public virtual CustomerReturnRequestsModel PrepareCustomerReturnRequestsModel()
        {
            var model = new CustomerReturnRequestsModel();

            var returnRequests = _returnRequestService.SearchReturnRequests(_storeContext.CurrentStore.Id,
                                                                            _workContext.CurrentCustomer.Id);

            foreach (var returnRequest in returnRequests)
            {
                var orderItem = _orderService.GetOrderItemById(returnRequest.OrderItemId);
                if (orderItem != null)
                {
                    var product = orderItem.Product;

                    var itemModel = new CustomerReturnRequestsModel.ReturnRequestModel
                    {
                        Id                  = returnRequest.Id,
                        CustomNumber        = returnRequest.CustomNumber,
                        ReturnRequestStatus = returnRequest.ReturnRequestStatus.GetLocalizedEnum(_localizationService, _workContext),
                        ProductId           = product.Id,
                        ProductName         = product.GetLocalized(x => x.Name),
                        ProductSeName       = product.GetSeName(),
                        Quantity            = returnRequest.Quantity,
                        ReturnAction        = returnRequest.RequestedAction,
                        ReturnReason        = returnRequest.ReasonForReturn,
                        Comments            = returnRequest.CustomerComments,
                        CreatedOn           = _dateTimeHelper.ConvertToUserTime(returnRequest.CreatedOnUtc, DateTimeKind.Utc),
                    };
                    model.Items.Add(itemModel);
                }
            }

            return(model);
        }
        /// <summary>
        /// Prepare the customer return requests model
        /// </summary>
        /// <returns>Customer return requests model</returns>
        public virtual CustomerReturnRequestsModel PrepareCustomerReturnRequestsModel()
        {
            var model = new CustomerReturnRequestsModel();

            var returnRequests = _returnRequestService.SearchReturnRequests(_storeContext.CurrentStore.Id, _workContext.CurrentCustomer.Id);

            foreach (var returnRequest in returnRequests)
            {
                var orderItem = _orderService.GetOrderItemById(returnRequest.OrderItemId);
                if (orderItem != null)
                {
                    var product  = orderItem.Product;
                    var download = _downloadService.GetDownloadById(returnRequest.UploadedFileId);

                    var itemModel = new CustomerReturnRequestsModel.ReturnRequestModel
                    {
                        Id                  = returnRequest.Id,
                        CustomNumber        = returnRequest.CustomNumber,
                        ReturnRequestStatus = returnRequest.ReturnRequestStatus.GetLocalizedEnum(_localizationService, _workContext),
                        ProductId           = product.Id,
                        ProductName         = product.GetLocalized(x => x.Name),
                        ProductSeName       = System.Net.WebUtility.UrlDecode($"{product.Id}/{product.GetSeName()}-{product.Sku}"), // product.GetSeName(),
                        Quantity            = returnRequest.Quantity,
                        ReturnAction        = returnRequest.RequestedAction,
                        ReturnReason        = returnRequest.ReasonForReturn,
                        Comments            = returnRequest.CustomerComments,
                        UploadedFileGuid    = download != null ? download.DownloadGuid : Guid.Empty,
                        CreatedOn           = _dateTimeHelper.ConvertToUserTime(returnRequest.CreatedOnUtc, DateTimeKind.Utc),
                    };
                    model.Items.Add(itemModel);
                }
            }

            return(model);
        }
Example #4
0
        public async Task <CustomerReturnRequestsModel> Handle(GetReturnRequests request, CancellationToken cancellationToken)
        {
            var model = new CustomerReturnRequestsModel();

            var query = new GetReturnRequestQuery()
            {
                StoreId = request.Store.Id,
            };

            if (request.Customer.IsOwner())
            {
                query.OwnerId = request.Customer.Id;
            }
            else
            {
                query.CustomerId = request.Customer.Id;
            }

            var returnRequests = await _mediator.Send(query);

            foreach (var returnRequest in returnRequests)
            {
                var order = await _orderService.GetOrderById(returnRequest.OrderId);

                decimal total = 0;
                foreach (var rrItem in returnRequest.ReturnRequestItems)
                {
                    var orderItem = order.OrderItems.Where(x => x.Id == rrItem.OrderItemId).First();

                    if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                    {
                        //including tax
                        var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate);
                        total += unitPriceInclTaxInCustomerCurrency * rrItem.Quantity;
                    }
                    else
                    {
                        //excluding tax
                        var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
                        total += unitPriceExclTaxInCustomerCurrency * rrItem.Quantity;
                    }
                }

                var itemModel = new CustomerReturnRequestsModel.ReturnRequestModel {
                    Id                  = returnRequest.Id,
                    ReturnNumber        = returnRequest.ReturnNumber,
                    ReturnRequestStatus = returnRequest.ReturnRequestStatus.GetLocalizedEnum(_localizationService, request.Language.Id),
                    CreatedOn           = _dateTimeHelper.ConvertToUserTime(returnRequest.CreatedOnUtc, DateTimeKind.Utc),
                    ProductsCount       = returnRequest.ReturnRequestItems.Sum(x => x.Quantity),
                    ReturnTotal         = _priceFormatter.FormatPrice(total)
                };

                model.Items.Add(itemModel);
            }

            return(model);
        }
Example #5
0
        public virtual async Task <CustomerReturnRequestsModel> PrepareCustomerReturnRequests()
        {
            var model = new CustomerReturnRequestsModel();

            var returnRequests = await _returnRequestService.SearchReturnRequests(_storeContext.CurrentStore.Id, _workContext.CurrentCustomer.Id);

            foreach (var returnRequest in returnRequests)
            {
                var order = await _orderService.GetOrderById(returnRequest.OrderId);

                decimal total = 0;
                foreach (var rrItem in returnRequest.ReturnRequestItems)
                {
                    var orderItem = order.OrderItems.Where(x => x.Id == rrItem.OrderItemId).First();

                    if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                    {
                        //including tax
                        var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate);
                        total += unitPriceInclTaxInCustomerCurrency * rrItem.Quantity;
                    }
                    else
                    {
                        //excluding tax
                        var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
                        total += unitPriceExclTaxInCustomerCurrency * rrItem.Quantity;
                    }
                }

                var itemModel = new CustomerReturnRequestsModel.ReturnRequestModel
                {
                    Id                  = returnRequest.Id,
                    ReturnNumber        = returnRequest.ReturnNumber,
                    ReturnRequestStatus = returnRequest.ReturnRequestStatus.GetLocalizedEnum(_localizationService, _workContext),
                    CreatedOn           = _dateTimeHelper.ConvertToUserTime(returnRequest.CreatedOnUtc, DateTimeKind.Utc),
                    ProductsCount       = returnRequest.ReturnRequestItems.Sum(x => x.Quantity),
                    ReturnTotal         = _priceFormatter.FormatPrice(total)
                };

                model.Items.Add(itemModel);
            }

            return(model);
        }
Example #6
0
        ////[GrandHttpsRequirement(SslRequirement.Yes)]
        public virtual IActionResult CustomerReturnRequests()
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(new UnauthorizedResult());
            }

            var model = new CustomerReturnRequestsModel();

            var returnRequests = _returnRequestService.SearchReturnRequests(_storeContext.CurrentStore.Id,
                                                                            _workContext.CurrentCustomer.Id);

            foreach (var returnRequest in returnRequests)
            {
                var order     = _orderService.GetOrderById(returnRequest.OrderId);
                var orderItem = order.OrderItems.Where(x => x.Id == returnRequest.OrderItemId).FirstOrDefault();
                if (orderItem != null)
                {
                    var product = _productService.GetProductByIdIncludeArch(orderItem.ProductId);

                    var itemModel = new CustomerReturnRequestsModel.ReturnRequestModel
                    {
                        Id                  = returnRequest.Id,
                        ReturnNumber        = returnRequest.ReturnNumber,
                        ReturnRequestStatus = returnRequest.ReturnRequestStatus.GetLocalizedEnum(_localizationService, _workContext),
                        ProductId           = product.Id,
                        ProductName         = product.GetLocalized(x => x.Name),
                        ProductSeName       = product.GetSeName(),
                        Quantity            = returnRequest.Quantity,
                        ReturnAction        = returnRequest.RequestedAction,
                        ReturnReason        = returnRequest.ReasonForReturn,
                        Comments            = returnRequest.CustomerComments,
                        CreatedOn           = _dateTimeHelper.ConvertToUserTime(returnRequest.CreatedOnUtc, DateTimeKind.Utc),
                    };
                    model.Items.Add(itemModel);
                }
            }

            return(View(model));
        }
        /// <summary>
        /// Prepare the customer return requests model
        /// </summary>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the customer return requests model
        /// </returns>
        public virtual async Task <CustomerReturnRequestsModel> PrepareCustomerReturnRequestsModelAsync()
        {
            var model = new CustomerReturnRequestsModel();
            var store = await _storeContext.GetCurrentStoreAsync();

            var customer = await _workContext.GetCurrentCustomerAsync();

            var returnRequests = await _returnRequestService.SearchReturnRequestsAsync(store.Id, customer.Id);

            foreach (var returnRequest in returnRequests)
            {
                var orderItem = await _orderService.GetOrderItemByIdAsync(returnRequest.OrderItemId);

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

                    var download = await _downloadService.GetDownloadByIdAsync(returnRequest.UploadedFileId);

                    var itemModel = new CustomerReturnRequestsModel.ReturnRequestModel
                    {
                        Id                  = returnRequest.Id,
                        CustomNumber        = returnRequest.CustomNumber,
                        ReturnRequestStatus = await _localizationService.GetLocalizedEnumAsync(returnRequest.ReturnRequestStatus),
                        ProductId           = product.Id,
                        ProductName         = await _localizationService.GetLocalizedAsync(product, x => x.Name),
                        ProductSeName       = await _urlRecordService.GetSeNameAsync(product),
                        Quantity            = returnRequest.Quantity,
                        ReturnAction        = returnRequest.RequestedAction,
                        ReturnReason        = returnRequest.ReasonForReturn,
                        Comments            = returnRequest.CustomerComments,
                        UploadedFileGuid    = download?.DownloadGuid ?? Guid.Empty,
                        CreatedOn           = await _dateTimeHelper.ConvertToUserTimeAsync(returnRequest.CreatedOnUtc, DateTimeKind.Utc),
                    };
                    model.Items.Add(itemModel);
                }
            }

            return(model);
        }