コード例 #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 void UpdateProductCollection(long subdomain, long collectionid, IEnumerable <long> oldSelectedPIDs, IEnumerable <long> selectedPIDs)
        {
            var oldSelectedProducts =
                db.productCollectionMembers.Where(x => x.collectionid == collectionid && oldSelectedPIDs.Contains(x.productid) && x.product.subdomainid == subdomain);

            db.productCollectionMembers.DeleteAllOnSubmit(oldSelectedProducts);

            Save();

            var newSelectedProducts = db.products.Where(x => x.subdomainid == subdomain && selectedPIDs.Contains(x.id));

            // add new ones
            foreach (var entry in newSelectedProducts)
            {
                var newentry = new productCollectionMember();
                newentry.collectionid = collectionid;
                newentry.productid    = entry.id;
                db.productCollectionMembers.InsertOnSubmit(newentry);
            }

            //CacheHelper.Instance.invalidate_dependency(DependencyType.organisation, subdomain.ToString());
        }