public static bool UnAssignAllProducts(ProductFilter filter, int groupId) { int totalCount = ProductDataSource.FindProductsCount(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly); int currentIndex = 0; IDatabaseSessionManager database = AbleContext.Current.Database; database.BeginTransaction(); while (currentIndex < totalCount) { IList <Product> currentBatch = ProductDataSource.FindProducts(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly, 100, currentIndex); foreach (Product p in currentBatch) { ProductGroup pg = ProductGroupDataSource.Load(p.Id, groupId); if (pg != null) { p.ProductGroups.Remove(pg); p.Save(); pg.Delete(); } } currentIndex += 100; } database.CommitTransaction(); return(true); }
public static bool AssignAllProducts(ProductFilter filter, int[] groupIds, string groupRestrictions) { int totalCount = ProductDataSource.FindProductsCount(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly); int currentIndex = 0; IDatabaseSessionManager database = AbleContext.Current.Database; database.BeginTransaction(); List <Group> groups = new List <Group>(); foreach (int gid in groupIds) { Group group = GroupDataSource.Load(gid); if (group != null) { groups.Add(group); } } while (currentIndex < totalCount) { IList <Product> currentBatch = ProductDataSource.FindProducts(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly, 100, currentIndex); foreach (Product p in currentBatch) { foreach (Group group in groups) { ProductGroup pg = ProductGroupDataSource.Load(p.Id, group.Id); if (pg == null) { pg = new ProductGroup(p, group); p.ProductGroups.Add(pg); } } switch (groupRestrictions) { case "YES": p.EnableGroups = true; break; case "NO": p.EnableGroups = false; break; default: break; } p.Save(); } currentIndex += 100; } database.CommitTransaction(); return(true); }
public static bool AssignProducts(int[] productIds, int[] groupIds, string groupRestrictions) { List <string> ids = new List <string>(); IDatabaseSessionManager database = AbleContext.Current.Database; database.BeginTransaction(); List <Group> groups = new List <Group>(); foreach (int gid in groupIds) { Group group = GroupDataSource.Load(gid); if (group != null) { groups.Add(group); } } foreach (int pid in productIds) { Product product = ProductDataSource.Load(pid); foreach (Group group in groups) { ProductGroup pg = ProductGroupDataSource.Load(pid, group.Id); if (pg == null) { pg = new ProductGroup(product, group); product.ProductGroups.Add(pg); } } switch (groupRestrictions) { case "YES": product.EnableGroups = true; break; case "NO": product.EnableGroups = false; break; default: break; } product.Save(); } database.CommitTransaction(); return(true); }
public static bool UnAssignProducts(int[] productIds, int groupId) { List <string> ids = new List <string>(); IDatabaseSessionManager database = AbleContext.Current.Database; database.BeginTransaction(); foreach (int pid in productIds) { ProductGroup pg = ProductGroupDataSource.Load(pid, groupId); if (pg != null) { var product = pg.Product; product.ProductGroups.Remove(pg); product.Save(); pg.Delete(); } } database.CommitTransaction(); return(true); }