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); } }
public async Task <ActionResult <bool> > AddAttributes(AdsFamilyAttributeViewModel model) { model = await _adsUnitOfWork.FamilyAttributesRepository.Add(model); return(Ok(model)); }