private void ImportProductProperties() { Header("Importing Product Properties"); ProductPropertyMapper = new Dictionary<int, long>(); data.bvc2004Entities oldDatabase = GetOldDatabase(); foreach (data.bvc_ProductProperty old in oldDatabase.bvc_ProductProperty) { wl("Item: " + old.DisplayName); ProductPropertyDTO pp = new ProductPropertyDTO(); pp.Choices = GetPropertyChoices(old.ID); 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; } 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; ProductPropertyMapper.Add(old.ID, newId); wl("SUCCESS"); } } } }
// 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 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"); } } } }
//DTO public ProductPropertyDTO ToDto() { ProductPropertyDTO dto = new ProductPropertyDTO(); foreach (ProductPropertyChoice c in this.Choices) { dto.Choices.Add(c.ToDto()); } dto.CultureCode = this.CultureCode; dto.DefaultValue = this.DefaultValue; dto.DisplayName = this.DisplayName; dto.DisplayOnSite = this.DisplayOnSite; dto.DisplayToDropShipper = this.DisplayToDropShipper; dto.Id = this.Id; dto.PropertyName = this.PropertyName; dto.StoreId = this.StoreId; dto.TypeCode = (ProductPropertyTypeDTO)((int)this.TypeCode); dto.LastUpdatedUtc = this.LastUpdatedUtc; return dto; }
public void FromDto(ProductPropertyDTO dto) { if (dto == null) return; this.Choices.Clear(); if (dto.Choices != null) { foreach (ProductPropertyChoiceDTO c in dto.Choices) { ProductPropertyChoice pc = new ProductPropertyChoice(); pc.FromDto(c); this.Choices.Add(pc); } } this.CultureCode = dto.CultureCode; this.DefaultValue = dto.DefaultValue; this.DisplayName = dto.DisplayName; this.DisplayOnSite = dto.DisplayOnSite; this.DisplayToDropShipper = dto.DisplayToDropShipper; this.Id = dto.Id; this.PropertyName = dto.PropertyName; this.StoreId = dto.StoreId; this.TypeCode = (ProductPropertyType)((int)dto.TypeCode); this.LastUpdatedUtc = dto.LastUpdatedUtc; }
public ApiResponse<ProductPropertyDTO> ProductPropertiesUpdate(ProductPropertyDTO item) { ApiResponse<ProductPropertyDTO> result = new ApiResponse<ProductPropertyDTO>(); result = RestHelper.PostRequest<ApiResponse<ProductPropertyDTO>>(this.fullApiUri + "productproperties/" + item.Id + "?key=" + Enc(key), MerchantTribe.Web.Json.ObjectToJson(item)); return result; }