public async Task <IActionResult> GoToId(MerchandiseReturnListModel model)
        {
            if (model.GoDirectlyToId == null)
            {
                return(RedirectToAction("List", "MerchandiseReturn"));
            }

            int.TryParse(model.GoDirectlyToId, out var id);

            //try to load a product entity
            var merchandiseReturn = await _merchandiseReturnService.GetMerchandiseReturnById(id);

            if (merchandiseReturn == null)
            {
                //not found
                return(RedirectToAction("List", "MerchandiseReturn"));
            }

            if (await _groupService.IsStaff(_workContext.CurrentCustomer) && merchandiseReturn.StoreId != _workContext.CurrentCustomer.StaffStoreId)
            {
                return(RedirectToAction("List", "MerchandiseReturn"));
            }

            return(RedirectToAction("Edit", "MerchandiseReturn", new { id = merchandiseReturn.Id }));
        }
        public virtual async Task <IActionResult> MerchandiseReturnDetails(string merchandiseReturnId)
        {
            var rr = await _merchandiseReturnService.GetMerchandiseReturnById(merchandiseReturnId);

            if (!await rr.Access(_workContext.CurrentCustomer, _groupService))
            {
                return(Challenge());
            }

            var order = await _orderService.GetOrderById(rr.OrderId);

            if (!await order.Access(_workContext.CurrentCustomer, _groupService))
            {
                return(Challenge());
            }

            var model = await _mediator.Send(new GetMerchandiseReturnDetails()
            {
                Order             = order,
                Language          = _workContext.WorkingLanguage,
                MerchandiseReturn = rr,
            });

            return(View(model));
        }
Esempio n. 3
0
        public virtual async Task <IActionResult> GetMerchandiseReturnNoteFile(string merchandiseReturnNoteId)
        {
            var merchandiseReturnNote = await _merchandiseReturnService.GetMerchandiseReturnNote(merchandiseReturnNoteId);

            if (merchandiseReturnNote == null)
            {
                return(InvokeHttp404());
            }

            var merchandiseReturn = await _merchandiseReturnService.GetMerchandiseReturnById(merchandiseReturnNote.MerchandiseReturnId);

            if (merchandiseReturn == null)
            {
                return(InvokeHttp404());
            }

            if (_workContext.CurrentCustomer == null || merchandiseReturn.CustomerId != _workContext.CurrentCustomer.Id)
            {
                return(Challenge());
            }

            var download = await _downloadService.GetDownloadById(merchandiseReturnNote.DownloadId);

            if (download == null)
            {
                return(Content("Download is not available any more."));
            }

            if (download.UseDownloadUrl)
            {
                return(new RedirectResult(download.DownloadUrl));
            }

            //binary download
            if (download.DownloadBinary == null)
            {
                return(Content("Download data is not available any more."));
            }

            //return result
            string fileName    = !String.IsNullOrWhiteSpace(download.Filename) ? download.Filename : merchandiseReturnNote.Id.ToString();
            string contentType = !String.IsNullOrWhiteSpace(download.ContentType) ? download.ContentType : "application/octet-stream";

            return(new FileContentResult(download.DownloadBinary, contentType)
            {
                FileDownloadName = fileName + download.Extension
            });
        }
Esempio n. 4
0
        public virtual async Task <IList <MerchandiseReturnModel.MerchandiseReturnItemModel> > PrepareMerchandiseReturnItemModel(string merchandiseReturnId)
        {
            var merchandiseReturn = await _merchandiseReturnService.GetMerchandiseReturnById(merchandiseReturnId);

            var items = new List <MerchandiseReturnModel.MerchandiseReturnItemModel>();
            var order = await _orderService.GetOrderById(merchandiseReturn.OrderId);

            foreach (var item in merchandiseReturn.MerchandiseReturnItems)
            {
                var orderItem = order.OrderItems.Where(x => x.Id == item.OrderItemId).FirstOrDefault();

                items.Add(new MerchandiseReturnModel.MerchandiseReturnItemModel
                {
                    ProductId       = orderItem.ProductId,
                    ProductName     = (await _productService.GetProductByIdIncludeArch(orderItem.ProductId)).Name,
                    Quantity        = item.Quantity,
                    UnitPrice       = _priceFormatter.FormatPrice(orderItem.UnitPriceInclTax),
                    ReasonForReturn = item.ReasonForReturn,
                    RequestedAction = item.RequestedAction
                });
            }
            return(items);
        }
        public virtual async Task <DocumentModel> PrepareDocumentModel(DocumentModel documentModel, Document document, SimpleDocumentModel simpleModel)
        {
            var model = documentModel == null ? new DocumentModel()
            {
                Published = true
            } : documentModel;

            if (document != null)
            {
                model = document.ToModel();
            }
            else
            {
                if (simpleModel != null)
                {
                    model.ReferenceId = simpleModel.Reference;
                    model.ObjectId    = simpleModel.ObjectId;
                    if (!string.IsNullOrEmpty(simpleModel.CustomerId))
                    {
                        model.CustomerEmail = (await _customerService.GetCustomerById(simpleModel.CustomerId))?.Email;
                    }

                    if (!string.IsNullOrEmpty(simpleModel.ObjectId))
                    {
                        switch (simpleModel.Reference)
                        {
                        case (int)Reference.Order:
                            var order = await _orderService.GetOrderById(simpleModel.ObjectId);

                            if (order != null)
                            {
                                model.Number         = order.OrderNumber.ToString();
                                model.TotalAmount    = order.OrderTotal;
                                model.OutstandAmount = order.PaymentStatusId == Domain.Payments.PaymentStatus.Paid ? 0 : order.OrderTotal;
                                model.CurrencyCode   = order.CustomerCurrencyCode;
                                model.Name           = string.Format(_translationService.GetResource("Order.Document"), model.Number);
                                model.DocDate        = order.CreatedOnUtc;
                                model.DueDate        = order.CreatedOnUtc;
                                model.Quantity       = 1;
                                model.Username       = $"{order.BillingAddress?.FirstName} {order.BillingAddress?.LastName}";
                                model.CustomerEmail  = order.CustomerEmail;
                            }
                            break;

                        case (int)Reference.Product:
                            var product = await _productService.GetProductById(simpleModel.ObjectId);

                            if (product != null)
                            {
                                model.Name     = product.Name;
                                model.Number   = product.Sku;
                                model.Quantity = 1;
                            }
                            break;

                        case (int)Reference.Category:
                            var category = await _categoryService.GetCategoryById(simpleModel.ObjectId);

                            if (category != null)
                            {
                                model.Name     = category.Name;
                                model.Quantity = 1;
                            }
                            break;

                        case (int)Reference.Collection:
                            var collection = await _collectionService.GetCollectionById(simpleModel.ObjectId);

                            if (collection != null)
                            {
                                model.Name     = collection.Name;
                                model.Quantity = 1;
                            }
                            break;

                        case (int)Reference.Vendor:
                            var vendor = await _vendorService.GetVendorById(simpleModel.ObjectId);

                            if (vendor != null)
                            {
                                model.Name     = vendor.Name;
                                model.Quantity = 1;
                            }
                            break;

                        case (int)Reference.Shipment:
                            var shipment = await _shipmentService.GetShipmentById(simpleModel.ObjectId);

                            if (shipment != null)
                            {
                                model.DocDate = shipment.CreatedOnUtc;
                                model.Number  = shipment.ShipmentNumber.ToString();
                                model.Name    = string.Format(_translationService.GetResource("Shipment.Document"), shipment.ShipmentNumber);
                                var sorder = await _orderService.GetOrderById(shipment.OrderId);

                                if (sorder != null)
                                {
                                    model.CustomerId    = sorder.CustomerId;
                                    model.CustomerEmail = sorder.CustomerEmail;
                                }
                            }
                            break;

                        case (int)Reference.MerchandiseReturn:
                            var merchandisereturn = await _merchandiseReturnService.GetMerchandiseReturnById(simpleModel.ObjectId);

                            if (merchandisereturn != null)
                            {
                                model.DocDate = merchandisereturn.CreatedOnUtc;
                                model.Number  = merchandisereturn.ReturnNumber.ToString();
                                model.Name    = string.Format(_translationService.GetResource("MerchandiseReturns.Document"), merchandisereturn.ReturnNumber);
                                var sorder = await _orderService.GetOrderById(merchandisereturn.OrderId);

                                if (sorder != null)
                                {
                                    model.CustomerId    = sorder.CustomerId;
                                    model.CustomerEmail = sorder.CustomerEmail;
                                }
                            }
                            break;
                        }
                    }
                }
            }
            //fill document types
            var types = await _documentTypeService.GetAll();

            foreach (var item in types)
            {
                model.AvailableDocumentTypes.Add(new SelectListItem
                {
                    Text  = item.Name,
                    Value = item.Id
                });
            }

            //fill sales employees
            model.AvailableSelesEmployees.Add(new SelectListItem
            {
                Text  = _translationService.GetResource("Admin.Documents.Document.Fields.SeId.None"),
                Value = ""
            });
            var salesEmployees = await _salesEmployeeService.GetAll();

            foreach (var item in salesEmployees.Where(x => x.Active))
            {
                model.AvailableSelesEmployees.Add(new SelectListItem
                {
                    Text  = item.Name,
                    Value = item.Id
                });
            }
            return(model);
        }