private List<ProductPropertyChoiceDTO> GetPropertyChoices(string propertyBvin, PropertyMapperInfo mapInfo) { List<ProductPropertyChoiceDTO> result = new List<ProductPropertyChoiceDTO>(); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); var choices = db.bvc_ProductPropertyChoice.Where(y => y.PropertyBvin == propertyBvin) .OrderBy(y => y.SortOrder); if (choices == null) return result; foreach (data.bvc_ProductPropertyChoice ppc in choices) { ProductPropertyChoiceDTO dto = new ProductPropertyChoiceDTO(); dto.ChoiceName = ppc.ChoiceName; dto.LastUpdated = ppc.LastUpdated; //dto.PropertyId = ppc.PropertyBvin; dto.SortOrder = ppc.SortOrder; result.Add(dto); PropertyChoiceMapperInfo choiceMapInfo = new PropertyChoiceMapperInfo(); choiceMapInfo.OldBvin = ppc.bvin; choiceMapInfo.SortOrder = ppc.SortOrder; choiceMapInfo.TextValue = ppc.ChoiceName; mapInfo.Choices.Add(choiceMapInfo); } return result; }
// Maps the new choice (long)id value to the old (string)bvin value for a choice private void SynchronizeChoices(ProductPropertyDTO dto, PropertyMapperInfo mapInfo) { if (dto == null) return; if (dto.Choices == null) return; if (mapInfo == null) return; foreach(PropertyChoiceMapperInfo mapChoice in mapInfo.Choices) { var dtoChoice = dto.Choices.Where(y => y.ChoiceName == mapChoice.TextValue).FirstOrDefault(); if (dtoChoice != null) { mapChoice.NewBvin = dtoChoice.Id; } } }
private long FindNewChoiceId(PropertyMapperInfo map, string oldPropertyValue) { if (map == null) return -1; if (map.Choices == null) return -1; var matchingChoice = map.Choices.Where(y => y.OldBvin == oldPropertyValue).FirstOrDefault(); if (matchingChoice == null) return -1; return matchingChoice.NewBvin; }
private void ImportProductProperties() { Header("Importing Product Properties"); ProductPropertyMapper = new List<PropertyMapperInfo>(); foreach (data.bvc_ProductProperty old in oldDatabase.bvc_ProductProperty) { wl("Item: " + old.DisplayName); // Skip creation if we've already mapped this one before if (ProductPropertyMapper.Where(y => y.OldBvin == old.bvin).Count() > 0) continue; PropertyMapperInfo mapInfo = new PropertyMapperInfo(); mapInfo.OldBvin = old.bvin; ProductPropertyDTO pp = new ProductPropertyDTO(); pp.Choices = GetPropertyChoices(old.bvin, mapInfo); pp.CultureCode = old.CultureCode; pp.DefaultValue = old.DefaultValue; pp.DisplayName = old.DisplayName; pp.DisplayOnSite = old.DisplayOnSite == 1; pp.DisplayToDropShipper = old.DisplayToDropShipper == 1; pp.PropertyName = old.PropertyName; switch (old.TypeCode) { case 0: pp.TypeCode = ProductPropertyTypeDTO.None; break; case 1: pp.TypeCode = ProductPropertyTypeDTO.TextField; break; case 2: pp.TypeCode = ProductPropertyTypeDTO.MultipleChoiceField; break; case 3: pp.TypeCode = ProductPropertyTypeDTO.CurrencyField; break; case 4: pp.TypeCode = ProductPropertyTypeDTO.DateField; break; case 7: pp.TypeCode = ProductPropertyTypeDTO.HyperLink; break; } mapInfo.PropertyType = pp.TypeCode; Api bv6proxy = GetBV6Proxy(); var res = bv6proxy.ProductPropertiesCreate(pp); if (res != null) { if (res.Errors.Count() > 0) { DumpErrors(res.Errors); wl("FAILED"); } else { long newId = res.Content.Id; mapInfo.NewBvin = newId; SynchronizeChoices(res.Content, mapInfo); ProductPropertyMapper.Add(mapInfo); wl("SUCCESS"); } } } }