コード例 #1
0
        public ActionResult ImportCollection(FBImportCollection collection)
        {
            var importer   = new ProductImport();
            var pinfos     = new List <ProductInfo>();
            var resultlist = new List <ImportResult>();

            foreach (var product in collection.products)
            {
                // check if product has already been imported
                var fbid  = product.id;
                var count =
                    repository.GetProducts(subdomainid.Value).SelectMany(x => x.facebook_imports).Where(
                        y => y.facebookID == fbid).Count();
                if (count != 0)
                {
                    var result = new ImportResult
                    {
                        id      = product.id.ToString(),
                        message = "already imported",
                        success = false
                    };
                    resultlist.Add(result);
                }
                else
                {
                    var pinfo = importer.ImportFacebook(product, collection.access_token, subdomainid.Value);
                    pinfos.Add(pinfo);
                    var result = new ImportResult
                    {
                        id      = product.id.ToString(),
                        success = true
                    };
                    resultlist.Add(result);
                }
            }

            // add collection
            var pcollection = new product_collection {
                name = collection.title, subdomainid = subdomainid.Value
            };

            if (resultlist.Select(x => x.success).Count() > 0)
            {
                // some products to add so we add collection
                var collectionid = repository.AddProductCollection(pcollection, subdomainid.Value);

                // update products to add with collection id
                foreach (var productInfo in pinfos)
                {
                    var pmember = new productCollectionMember();
                    pmember.collectionid = collectionid;
                    productInfo.p.productCollectionMembers.Add(pmember);
                }
            }

            repository.AddProducts(pinfos, subdomainid.Value);
            return(Json(resultlist.ToJsonOKData()));
        }
コード例 #2
0
        public ActionResult ImportProduct(FBImportSingle sproduct)
        {
            // check if product has already been imported
            var count =
                repository.GetProducts(subdomainid.Value).SelectMany(x => x.facebook_imports).Count(y => y.facebookID == sproduct.product.id);

            if (count != 0)
            {
                return(Json("Product has already been imported".ToJsonFail()));
            }
            var importer = new ProductImport();
            var pinfo    = importer.ImportFacebook(sproduct.product, sproduct.access_token, subdomainid.Value);

            repository.AddProduct(pinfo, subdomainid.Value);
            return(Json(sproduct.product.id.ToJsonOKData()));
        }