/** * Parse a given Order file for unknown ingredient or product names. If there is no prior mapping for them, add the name to the mapping table. */ public void ParseMappingFromOrderFile(string filePath) { List <string> allLineInMapping = File.ReadAllLines(filePath).ToList(); allLineInMapping.RemoveRange(0, 5); // Remove the header. foreach (string line in allLineInMapping) { string[] partCollection = line.Split(';'); if (partCollection.Length <= 1) { // Skip empty lines or lines with a comment. continue; } if (partCollection.Length != 23) { throw new InvalidDataException("Unexpected number of columns, a non-order table has been passed to the mapping function."); } string productName = partCollection[10].ToString().Trim(); string extraIngredientList = partCollection[16].ToString().Trim(); if (productName.Length > 0) { // If the product already exists, or there is a mapping for it already, no need to map it again. product product = products.SingleOrDefault(i => i.name == productName); mapping existingMapping = mappings.SingleOrDefault(i => i.originalname == productName && i.isingredient == false); if (product == null && existingMapping == null) { mapProduct(productName); } } if (extraIngredientList.Length > 0) { string[] ingredientNameCollection = extraIngredientList.Split(','); foreach (string ingredientName in ingredientNameCollection) { string ingredientNameFormatted = ingredientName.Trim(); // If the ingredient already exists, or there is a mapping for it already, no need to map it again. ingredient ingredient = ingredients.SingleOrDefault(i => i.name == ingredientNameFormatted); mapping existingMapping = mappings.SingleOrDefault(i => i.originalname == ingredientNameFormatted && i.isingredient == true); if (ingredient == null && existingMapping == null) { mapIngredient(ingredientNameFormatted); } } } } database.SaveChanges(); }
private static countrycode GetOrCreateDefaultCountryCode(dbi298845_prangersEntities db) { //check if countrycode exists, so we can create a bottomprice for NL stores var countrycode = db.countrycodes.SingleOrDefault(i => i.code == "NL"); if (countrycode == null) // if it doesnt exists, create a new countrycode { countrycode = new countrycode() { code = "NL" }; db.countrycodes.Add(countrycode); db.SaveChanges(); } return(countrycode); }