public ActionResult ProductData(int id)
        {
            var context = new ShopConnectorRequestContext
            {
                ActionMethod = "About"
            };

            try
            {
                if (!_connectorService.SendRequest(context, id))
                {
                    return(new ShopConnectorOperationResult(context));
                }

                var model = new ProductDataModel {
                    Id = id
                };
                model.FetchFromDate       = _connectorService.ConvertDateTime(context.Connection.LastProductCallUtc, true);
                model.AvailableCategories = new List <SelectListItem>();

                if (System.IO.File.Exists(context.ResponsePath))
                {
                    var doc     = new XPathDocument(context.ResponsePath);
                    var content = doc.GetContent();
                    var manus   = new List <SelectListItem>();

                    foreach (XPathNavigator manu in content.Select("Manufacturers/Manufacturer"))
                    {
                        manus.Add(new SelectListItem
                        {
                            Text  = manu.GetString("Name"),
                            Value = manu.GetString("Id")
                        });
                    }
                    model.AvailableManufacturers = new MultiSelectList(manus, "Value", "Text");

                    foreach (XPathNavigator category in content.Select("Categories/Category"))
                    {
                        model.AvailableCategories.Add(new SelectListItem
                        {
                            Text  = category.GetString("Name"),
                            Value = category.GetString("Id")
                        });
                    }
                }

                ViewData["pickTimeFieldIds"] = new List <string> {
                    "FetchFromDate"
                };

                return(PartialView(model));
            }
            catch (Exception ex)
            {
                context.ResponseModel = new OperationResultModel(ex);
            }

            return(new ShopConnectorOperationResult(context));
        }
        public ActionResult About(int id)
        {
            var context = new ShopConnectorRequestContext
            {
                ActionMethod = "About"
            };

            try
            {
                if (!_connectorService.SendRequest(context, id))
                {
                    return(new ShopConnectorOperationResult(context));
                }

                var model = new AboutModel();

                if (System.IO.File.Exists(context.ResponsePath))
                {
                    var doc     = new XPathDocument(context.ResponsePath);
                    var content = doc.GetContent();

                    model.AppVersion           = content.GetString("AppVersion");
                    model.UtcTime              = content.GetString("UtcTime").ToDateTimeIso8601() ?? DateTime.UtcNow;
                    model.ConnectorVersion     = content.GetString("ConnectorVersion");
                    model.StoreName            = content.GetString("StoreName");
                    model.StoreUrl             = content.GetString("StoreUrl");
                    model.StoreCount           = content.GetValue("StoreCount", 1);
                    model.CompanyName          = content.GetString("CompanyName");
                    model.StoreLogoUrl         = content.GetString("StoreLogoUrl");
                    model.UpdatedProductsCount = content.GetString("UpdatedProductsCount", "".NaIfEmpty());
                }
                return(PartialView(model));
            }
            catch (Exception ex)
            {
                context.ResponseModel = new OperationResultModel(ex);
            }

            return(new ShopConnectorOperationResult(context));
        }
        public List <ProductImportItemModel> GetProductImportItems(string importFile, int pageIndex, out int totalItems)
        {
            var data  = new List <ProductImportItemModel>();
            var files = new ShopConnectorFileSystem("Product");
            var path  = files.GetFullFilePath(importFile);

            var doc = new XPathDocument(path);
            var nav = doc.GetContent() ?? doc.CreateNavigator();

            var xpathProducts = "Products/Product";
            var products      = nav.Select(xpathProducts);
            var categories    = new Dictionary <int, ShopConnectorCategory>();

            if (nav != null)
            {
                foreach (XPathNavigator category in nav.Select("Categories/Category"))
                {
                    categories.SafeAddId(category.GetValue("Id", 0), new ShopConnectorCategory
                    {
                        Name     = category.GetString("Name").NaIfEmpty(),
                        Alias    = category.GetString("Alias"),
                        ParentId = category.GetValue <int>("ParentCategoryId")
                    });
                }
            }

            totalItems = products.Count;

            var idx            = 0;
            var pageSize       = _adminAreaSettings.GridPageSize;
            var firstItemIndex = (pageIndex * pageSize) + 1;
            var lastItemIndex  = Math.Min(totalItems, (pageIndex * pageSize) + pageSize);

            foreach (XPathNavigator product in products)
            {
                ++idx;
                if (idx >= firstItemIndex && idx <= lastItemIndex)
                {
                    var importProduct = new ProductImportItemModel
                    {
                        Id            = product.GetValue <int>("Id"),
                        Name          = product.GetString("Name"),
                        Sku           = product.GetString("Sku"),
                        ProductTypeId = product.GetValue <int>("ProductTypeId"),
                        Categories    = new List <string>(),
                        Manufacturers = new List <string>()
                    };

                    var productType = ProductType.SimpleProduct;
                    if (Enum.TryParse(importProduct.ProductTypeId.ToString(), out productType) && productType != ProductType.SimpleProduct)
                    {
                        importProduct.ProductTypeName = T("Admin.Catalog.Products.ProductType.{0}.Label".FormatInvariant(productType.ToString()));
                    }

                    importProduct.ProductType = productType;

                    foreach (XPathNavigator productManufacturer in product.Select("ProductManufacturers/ProductManufacturer"))
                    {
                        var manuName = productManufacturer.SelectSingleNode("Manufacturer").GetString("Name");
                        if (!importProduct.Manufacturers.Contains(manuName))
                        {
                            importProduct.Manufacturers.Add(manuName);
                        }
                    }

                    foreach (XPathNavigator productCategory in product.Select("ProductCategories/ProductCategory"))
                    {
                        var categoryId = productCategory.SelectSingleNode("Category").GetValue("Id", 0);
                        if (categories.ContainsKey(categoryId))
                        {
                            var breadCrumb = GetCategoryBreadCrumb(categories[categoryId], categories);
                            if (breadCrumb.HasValue())
                            {
                                importProduct.Categories.Add(breadCrumb);
                            }
                        }
                    }

                    data.Add(importProduct);
                }
                else if (idx > lastItemIndex)
                {
                    break;
                }
            }
            return(data);
        }