private void DeleteHierarchy(int parent, IServiceUnitOfWork unit) { var child = unit.Service <ProductGroupMapping>().GetAll(x => x.ParentProductGroupMappingID.HasValue && x.ParentProductGroupMappingID.Value == parent).ToList(); if (child.Count < 1) { ((IProductGroupMappingService)unit.Service <ProductGroupMapping>()).Delete(parent); } else { child.ForEach(x => { DeleteHierarchy(x.ProductGroupMappingID, unit); }); } }
public List <DefaultColumnDefinition> GetColumnDefinitions(int userID, string name, IServiceUnitOfWork unit) { var serializer = new JavaScriptSerializer(); var state = unit.Service <UserState>().Get(c => c.UserID == userID && c.EntityName == name); var stateObject = state != null ? state.SavedState : String.Empty; var columnWrapper = serializer.Deserialize <ColumnDefinitionWrapper>(stateObject); return(columnWrapper != null && columnWrapper.Columns != null ? columnWrapper.Columns : new List <DefaultColumnDefinition>()); }
private bool ReadyforWehkampProductDescription(ProductDescription productDescription, int productID, IServiceUnitOfWork unit) { if (productDescription.VendorID != ConcentratorVendorID) { productDescription = unit.Service <ProductDescription>().Get(x => x.VendorID == ConcentratorVendorID && x.ProductID == productID); } if (productDescription != null && !string.IsNullOrEmpty(productDescription.LongContentDescription) && !string.IsNullOrEmpty(productDescription.ShortContentDescription)) { return(true); } else { return(false); } }
private static int GetNextRelatedProductIndex(IServiceUnitOfWork unit, RelatedProduct relatedProduct) { if (relatedProduct.RelatedProductTypeID == 8 || relatedProduct.CreatedBy == 1) { return(relatedProduct.Index); } var relatedProducts = unit.Service <RelatedProduct>().GetAll(x => x.ProductID == relatedProduct.ProductID); foreach (var product in relatedProducts.OrderByDescending(r => r.Index)) { return(product.Index > 1000 ? product.Index++ : 1001); } return(relatedProduct.Index); }
private TreeNode GetNodes(TreeNode level, List <string> levels, int currentLevel, IServiceUnitOfWork unit) { bool node = levels.IndexOf(currentLevel.ToString()) < levels.Count() - 1; var mapping = unit.Service <ProductGroupMapping>().Get(c => c.ProductGroupMappingID == currentLevel); var productGroupName = mapping.ProductGroup.ProductGroupLanguages.FirstOrDefault(c => c.LanguageID == Client.User.LanguageID) ?? mapping.ProductGroup.ProductGroupLanguages.FirstOrDefault(); level.text = mapping.CustomProductGroupLabel != "" ? mapping.CustomProductGroupLabel + "(C)" : productGroupName.Name; level.leaf = !node; level.ConnectorID = mapping.ConnectorID; level.ProductGroupMappingID = currentLevel; if (node) { TreeNode tn = new TreeNode(); level.children = new List <TreeNode>(); level.children.Add(GetNodes(tn, levels, int.Parse(levels[levels.IndexOf(currentLevel.ToString()) + 1]), unit)); } return(level); }
public ProductModelRepository(IServiceUnitOfWork unit, int vendorID) { _unit = unit; _vendorID = vendorID; //check and create setting if not existing var vendorSetting = _unit.Service <VendorSetting>().Get(c => c.VendorID == vendorID && c.SettingKey == _settingKey); if (vendorSetting == null) { vendorSetting = new VendorSetting() { SettingKey = _settingKey, VendorID = _vendorID, Value = string.Empty }; unit.Service <VendorSetting>().Create(vendorSetting); unit.Save(); } _vendorSetting = vendorSetting; }
private void CheckForFields(IServiceUnitOfWork unit, WebToPrintBinding wtpb) { try { if (wtpb.WebToPrintBindingFields == null) { wtpb.WebToPrintBindingFields = new List <WebToPrintBindingField>(); } if (wtpb.WebToPrintBindingFields.Count != 0) { unit.Service <WebToPrintBindingField>().Delete(wtpb.WebToPrintBindingFields); wtpb.WebToPrintBindingFields = new List <WebToPrintBindingField>(); unit.Save(); } string query = wtpb.QueryText; wtpb.Query = ""; if (query.ToLower().Contains("select") && query.ToLower().Contains("from")) { int fromindex = query.ToLower().LastIndexOf("from"); int offset = 7; if (query.ToLower().Contains("distinct")) { offset += 9; } List <string> selects = new List <string>(); string subString = query.Substring(offset, fromindex - offset); int bracketcount = 0; int lastIndex = 0; for (int i = 0; i < subString.Length; i++) { if (subString[i] == '(') { bracketcount++; } if (subString[i] == ')') { bracketcount--; } if (subString[i] == ',' && bracketcount == 0) { selects.Add(subString.Substring(lastIndex, i - lastIndex).Trim()); lastIndex = i + 1; } } selects.Add(subString.Substring(lastIndex, subString.Length - lastIndex).Trim()); string[] selectwords = selects.ToArray(); string newquery = "select "; if (query.ToLower().Contains("distinct")) { newquery += "distinct "; } for (int i = 0; i < selectwords.Length; i++) { string word = selectwords[i].Trim(); string name = word; int asIndex = word.ToLower().LastIndexOf("as"); if (asIndex >= 0) { name = word.Substring((asIndex + 3), word.Length - (asIndex + 3)); } WebToPrintBindingField wtpbf = new WebToPrintBindingField() { Name = name, WebToPrintBinding = wtpb, Options = 0, Type = (byte)BindingFieldType.Unknown + 1 }; unit.Service <WebToPrintBindingField>().Create(wtpbf); unit.Save(); if (asIndex >= 0) { newquery += word.Substring(0, asIndex - 1) + " as '" + wtpbf.FieldID + "'"; } else { newquery += word + " as '" + wtpbf.FieldID + "'"; } if (i < selectwords.Length - 1) { newquery += ", "; } } if (query.ToLower().Contains("where")) { int whereindex = query.ToLower().LastIndexOf("where") + 5; newquery += " " + query.Substring(fromindex, whereindex - 5 - (fromindex)); newquery += "where"; string[] wherewords = query.Substring(whereindex, query.Length - whereindex).Split('='); for (int i = 0; i < wherewords.Length - 1; i++) { string[] values = wherewords[i].Trim().Split(' '); string[] values2 = wherewords[i + 1].Trim().Split(' '); WebToPrintBindingField wtpbf = new WebToPrintBindingField() { Name = values2[0], Type = (byte)BindingFieldType.Unknown }; wtpb.WebToPrintBindingFields.Add(wtpbf); unit.Save(); newquery += " " + values[values.Length - 1] + "=@" + wtpbf.FieldID; if (values2.Length > 1) { newquery += " " + values2[1]; } } } else { newquery += " " + query.Substring(fromindex, query.Length - (fromindex)); } wtpb.Query = newquery; unit.Save(); } else { Exception e = new Exception("The query is invalid"); throw e; } } catch (Exception e) { throw e; } }
private ProductAttributeMetaData GetOrCreateProductAttributeMetaData(string attributeCode, int vendorID, IServiceUnitOfWork unit) { ProductAttributeMetaData attribute = null; var attributes = unit.Service <ProductAttributeMetaData>().GetAll(x => x.AttributeCode == attributeCode); if (attributes.Any()) { //get attribute by vendor, create if not exists if (ConcentratorSection.Default.Management.ProductBrowser.General.CreateAttributeByVendor) { attribute = attributes.FirstOrDefault(x => x.VendorID == vendorID); } else { attribute = attributes.FirstOrDefault(); } } else { throw new Exception(string.Format("Attribute '{0}' does not exist, please create first.", attributeCode)); } if (attribute == null) { //create and return var baseAttribute = attributes.FirstOrDefault(); attribute = new ProductAttributeMetaData { AttributeCode = baseAttribute.AttributeCode, ProductAttributeGroupID = baseAttribute.ProductAttributeGroupID, FormatString = baseAttribute.FormatString, DataType = baseAttribute.DataType, Index = baseAttribute.Index, IsVisible = baseAttribute.IsVisible, NeedsUpdate = baseAttribute.NeedsUpdate, VendorID = vendorID, IsSearchable = baseAttribute.IsSearchable, Sign = baseAttribute.Sign, CreatedBy = baseAttribute.CreatedBy, CreationTime = DateTime.Now, Mandatory = baseAttribute.Mandatory, DefaultValue = baseAttribute.DefaultValue, IsConfigurable = baseAttribute.IsConfigurable, ConfigurablePosition = baseAttribute.ConfigurablePosition, HasOption = baseAttribute.HasOption, IsSlider = baseAttribute.IsSlider, ProductAttributeNames = new List <ProductAttributeName>() }; unit.Service <ProductAttributeMetaData>().Create(attribute); foreach (var attributeName in baseAttribute.ProductAttributeNames) { attribute.ProductAttributeNames.Add(new ProductAttributeName { LanguageID = attributeName.LanguageID, Name = attributeName.Name }); } unit.Save(); } return(attribute); }