private void SaveSpecificationMappings(ProductCreateOrUpdateModel model) { var specificationMappings = new List <ProductSpecificationMapping>(); if (model.Specifications != null) { int i = 0; foreach (var spec in model.Specifications) { // check if specification exist Guid specificationId; if (Guid.TryParse(spec.Key, out specificationId)) { if (specificationId == Guid.Empty) { continue; } // create mapping entity var specificationMapping = new ProductSpecificationMapping { Id = Guid.NewGuid(), ProductId = model.Id, SpecificationId = specificationId, Value = spec.Value, SortOrder = spec.SortOrder, Position = i }; i++; specificationMappings.Add(specificationMapping); } } } // save to database _specificationService.DeleteAllProductSpecificationMappings(model.Id); _specificationService.InsertProductSpecificationMappings(specificationMappings); }