private async Task <AdsCategoryViewModel> ImportCategory(ExchangeDataRow item, AdsImportResultViewModel importResult) { if (!Guid.TryParse(item.FamilyId, out var familyId)) { _logger.LogWarning($"ParentId:{item.FamilyId} is not a guid"); } if (!Guid.TryParse(item.CategoryId, out var categoryId)) { _logger.LogWarning($"CategoryId:{item.CategoryId} is not a guid"); } var family = await ImportFamily(item, importResult); var current = await _adsUnitOfWork. CategoriesRepository.Get(categoryId); if (current == null) { _logger.LogInformation($"Create new category with id {categoryId} code {item.Code} label {item.Label}"); current = new AdsCategoryViewModel() { CategoryId = categoryId, Code = item.Code, Label = item.Label, FamilyId = family.FamilyId, MetaDescription = item.MetaDescription, MetaKeywords = item.MetaKeywords, MetaTitle = item.MetaTitle, PictureUrl = item.PictureUrl }; importResult.CategoriesAdded += 1; await _adsUnitOfWork.CategoriesRepository.Add(current); } else if (item.Type.Equals("category", StringComparison.OrdinalIgnoreCase)) { _logger.LogInformation($"Update Category with id {categoryId} code {current.Code} label {current.Label}"); current.CategoryId = categoryId; current.Code = item.Code; current.Label = item.Label; current.FamilyId = familyId; current.MetaDescription = item.MetaDescription; current.MetaKeywords = item.MetaKeywords; current.MetaTitle = item.MetaTitle; current.PictureUrl = item.PictureUrl; importResult.CategoriesUpdated += 1; await _adsUnitOfWork.CategoriesRepository.Update(current); } return(current); }
private async Task ImportAttribute(ExchangeDataRow item) { if (!Guid.TryParse(item.FamilyAttributeId, out var familyAttributeId)) { _logger.LogWarning($"Id:{item.FamilyAttributeId} is not a guid"); } if (!Guid.TryParse(item.FamilyId, out var familyId)) { _logger.LogWarning($"ParentId:{item.FamilyId} is not a guid"); } var attributes = await _adsUnitOfWork .FamilyAttributesRepository .GetByFamily(familyId); var current = attributes.FirstOrDefault(a => a.FamilyAttributeId == familyAttributeId); if (current == null) { _logger.LogInformation($"Create new attribute for family {familyId} with id {familyAttributeId} code {item.Code} label {item.Label}"); current = new AdsFamilyAttributeViewModel() { Code = item.Code, FamilyId = familyId, FamilyAttributeId = familyAttributeId, Label = item.Label, IsRequired = bool.Parse(item.IsRequired), IsSearchable = bool.Parse(item.IsSearchable), Type = item.AttributeType }; await _adsUnitOfWork.FamilyAttributesRepository.Add(current); } else if (item.Type.Equals("category", StringComparison.OrdinalIgnoreCase)) { _logger.LogInformation($"Update attribute {familyAttributeId} for family with id {familyId} code {current.Code} label {current.Label}"); current.Code = item.Code; current.Label = item.Label; current.IsRequired = bool.Parse(item.IsRequired); current.IsSearchable = bool.Parse(item.IsSearchable); current.Type = item.AttributeType; await _adsUnitOfWork.FamilyAttributesRepository.Update(current); } }
private async Task <AdsFamilyViewModel> ImportFamily(ExchangeDataRow item, AdsImportResultViewModel importResult) { if (!Guid.TryParse(item.FamilyId, out var familyId)) { _logger.LogWarning($"ParentId:{item.FamilyId} is not a guid"); } var current = await _adsUnitOfWork.FamiliesRepository.Get(familyId); if (current == null) { _logger.LogInformation($"Create new family with id {familyId} code {item.Code} label {item.Label}"); current = new AdsFamilyViewModel() { Code = item.Code, FamilyId = familyId, Label = item.Label, LabelSearch = item.LabelSearch, HeaderAuthorize = item.HeaderAuthorize, MetaDescription = item.MetaDescription, MetaKeywords = item.MetaKeywords, MetaTitle = item.MetaTitle, PictureUrl = item.PictureUrl, UrlApi = item.UrlApi, PurchaseLabelRule = item.PurchaseLabelRule }; importResult.FamiliesAdded += 1; await _adsUnitOfWork.FamiliesRepository.Add(current); } else if (item.Type.Equals("family", StringComparison.OrdinalIgnoreCase)) { _logger.LogInformation($"Update family with id {familyId} code {current.Code} label {current.Label}"); bool hasChanged = false; if (current.Code != item.Code) { hasChanged = true; current.Code = item.Code; } if (current.Label != item.Label) { hasChanged = true; current.Label = item.Label; } if (current.LabelSearch != item.LabelSearch) { hasChanged = true; current.LabelSearch = item.LabelSearch; } if (current.HeaderAuthorize != item.HeaderAuthorize) { hasChanged = true; current.HeaderAuthorize = item.HeaderAuthorize; } if (current.MetaDescription != item.MetaDescription) { hasChanged = true; current.MetaDescription = item.MetaDescription; } if (current.MetaKeywords != item.MetaKeywords) { hasChanged = true; current.MetaKeywords = item.MetaKeywords; } if (current.MetaTitle != item.MetaTitle) { hasChanged = true; current.MetaTitle = item.MetaTitle; } if (current.PictureUrl != item.PictureUrl) { hasChanged = true; current.PictureUrl = item.PictureUrl; } if (current.UrlApi != item.UrlApi) { hasChanged = true; current.UrlApi = item.UrlApi; } if (current.PurchaseLabelRule != item.PurchaseLabelRule) { hasChanged = true; current.PurchaseLabelRule = item.PurchaseLabelRule; } if (hasChanged) { importResult.FamiliesUpdated += 1; await _adsUnitOfWork.FamiliesRepository.Update(current); } } return(current); }