public Collection(product_collection collection, IEnumerable <string> match_tags, long?viewerid) : this(collection.name, collection.permalink, collection.MASTERsubdomain) { description = collection.details; all_products_count = collection.productCollectionMembers.AsQueryable() .Select(x => x.product) .IsActive() .Count(); if (match_tags != null) { products = collection.productCollectionMembers .AsQueryable() .Select(x => x.product) .Where(y => y.tags1.Select(z => z.handle).Intersect(match_tags).Count() != 0) .IsActive() .ToLiquidModel(viewerid, collection.permalink) .OrderByDescending(y => y.id) .ToList(); } else { products = collection.productCollectionMembers .AsQueryable() .Select(x => x.product) .IsActive() .ToLiquidModel(viewerid, collection.permalink) .OrderByDescending(y => y.id) .ToList(); } }
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())); }
public ActionResult Create(string title, string details, bool visible) { title = title.Trim(); details = details.Trim(); // if it's empty then if (string.IsNullOrEmpty(title)) { return(SendJsonErrorResponse("Please specify a collection name")); } if (string.Compare(title, "categories", StringComparison.InvariantCultureIgnoreCase) == 0) { return(SendJsonErrorResponse("Create FAIL. Name is RESERVED. Choose another name.")); } var collection = new product_collection { name = title, details = details, subdomainid = subdomainid.Value }; var perma = title.ToPerma(); string perma1 = perma; if (db.product_collections.Count(x => x.permalink == perma1 && x.subdomainid == subdomainid.Value) != 0) { perma = string.Format("{0}-{1}", db.product_collections.Max(x => x.id) + 1, perma); } collection.permalink = perma.ToMaxLength(100); if (visible) { collection.settings |= (int)CollectionSettings.VISIBLE; } else { collection.settings &= ~(int)CollectionSettings.VISIBLE; } try { repository.AddProductCollection(collection, subdomainid.Value); } catch (Exception ex) { return(SendJsonErrorResponse(ex)); } return(Json(new { collection.id, collection.name }.ToJsonOKData())); }
public long AddProductCollection(product_collection collection, long subdomainid) { var existing = db.product_collections.Where( x => x.name == collection.name && x.subdomainid == subdomainid && x.etsy_sectionid == collection.etsy_sectionid && x.etsy_shopid == collection.etsy_shopid). SingleOrDefault(); if (existing != null) { return(existing.id); } db.product_collections.InsertOnSubmit(collection); db.SubmitChanges(); return(collection.id); }
public static void GenerateDefaultStructures(long subdomainid) { using (var repository = new TradelrRepository()) { var mastersubdomain = repository.GetSubDomain(subdomainid); if (mastersubdomain == null) { Syslog.Write("Can't generate liquid structures for domainid: " + subdomainid); return; } if (mastersubdomain.theme != null) { // already initialise, return return; } // init default theme (SOLO) mastersubdomain.theme = new DBML.theme() { created = DateTime.UtcNow, title = "Solo", preset = "", url = "/Content/templates/store/themes/solo/thumb.jpg" }; // do liquid stuff var page_about = new page() { name = "About Us", permalink = "about-us", creator = mastersubdomain.organisation.users.First().id, updated = DateTime.UtcNow, settings = (int)PageSettings.VISIBLE }; using (var reader = File.OpenText(GeneralConstants.APP_ROOT_DIR + "Content/templates/store/aboutus.txt")) { page_about.content = reader.ReadToEnd(); } mastersubdomain.pages.Add(page_about); var linklist_mainmenu = new linklist() { permalink = "main-menu", permanent = true, title = "Main Menu" }; mastersubdomain.linklists.Add(linklist_mainmenu); var link_home = new link { title = "Home", type = (int)LinkType.FRONTPAGE, url = "/" }; var link_catalog = new link() { title = "Catalog", type = (int)LinkType.WEB, url = "/collections/all" }; var link_about = new link() { title = "About Us", type = (int)LinkType.PAGE, url = "/pages/about-us" }; linklist_mainmenu.links.Add(link_home); linklist_mainmenu.links.Add(link_catalog); linklist_mainmenu.links.Add(link_about); var linklist_footer = new linklist() { permalink = "footer", permanent = true, title = "Footer" }; mastersubdomain.linklists.Add(linklist_footer); var link_search = new link { title = "Search", type = (int)LinkType.SEARCHPAGE, url = "/search" }; linklist_footer.links.Add(link_search); linklist_footer.links.Add(link_about); // create default collection var collection = new product_collection() { name = "Frontpage", permalink = "frontpage", settings = (int)(CollectionSettings.VISIBLE | CollectionSettings.PERMANENT) }; mastersubdomain.product_collections.Add(collection); // finally save repository.Save(); // copy theme files var handler = new ThemeHandler(mastersubdomain, false); new Thread(() => { var source = new DirectoryInfo(GeneralConstants.APP_ROOT_DIR + "Content/templates/store/themes/solo"); handler.CopyThemeToUserThemeDirectory(source); }).Start(); // copy mobile theme files var handler_mobile = new ThemeHandler(mastersubdomain, true); new Thread(() => { var source = handler.GetMobileThemeRepositorySourceDir(); handler_mobile.CopyThemeToUserThemeDirectory(source); }).Start(); } }