Skip to content

Commit

Permalink
update variable names for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
MathoMathiasCamara committed Jul 23, 2024
1 parent acfd679 commit 7a375ad
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/Moryx.AbstractionLayer.Products.Endpoints/ProductConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public IProductType ConvertProductBack(ProductModel source, ProductType converte
private void UpdateCollection(IList value, IEnumerable<PartModel> parts)
{
// Track which part links are still represented by the models
var unused = new List<IProductPartLink>(value.OfType<IProductPartLink>());
var oldParts = new List<IProductPartLink>(value.OfType<IProductPartLink>());
// Iterate over the part models
// Create or update the part links
var elemType = value.GetType().GetInterfaces()
Expand All @@ -269,27 +269,27 @@ private void UpdateCollection(IList value, IEnumerable<PartModel> parts)
if (partModel is null)
continue;

var match = unused.Find(r => r.Id == partModel?.Id);
var oldPartMatch = oldParts.Find(r => r.Id == partModel.Id);
// new partlink
if (match == null)
if (oldPartMatch == null)
{
match = (IProductPartLink)Activator.CreateInstance(elemType);
match.Product = _productManagement.LoadType(partModel.Product.Id);
value.Add(match);
oldPartMatch = (IProductPartLink)Activator.CreateInstance(elemType);
oldPartMatch.Product = _productManagement.LoadType(partModel.Product.Id);
value.Add(oldPartMatch);
}
//modified reference
else if (match.Product.Id != partModel.Product.Id)
match.Product = _productManagement.LoadType(partModel.Product.Id);
else if (oldPartMatch.Product.Id != partModel.Product.Id)
oldPartMatch.Product = _productManagement.LoadType(partModel.Product.Id);

This comment has been minimized.

Copy link
@dacky179

dacky179 Jul 23, 2024

Member

if i understand correctly we update the partlink; but at the end this partlink will be removed because it was not removed from "oldParts.
As this would be a bug with a great impact, i think this code won't be executed ever. @Toxantron ?

else
//part removed
unused.Remove(match);
//part removed

This comment has been minimized.

Copy link
@dacky179

dacky179 Jul 23, 2024

Member

This comment causes most of my confusion: In reality it is: existing / unchanged Partlink

oldParts.Remove(oldPartMatch);

EntryConvert.UpdateInstance(match, partModel.Properties);
EntryConvert.UpdateInstance(oldPartMatch, partModel.Properties);
}

// Clear all values no longer present in the model
foreach (var link in unused)
value.Remove(link);
foreach (var part in oldParts)
value.Remove(part);
}

private void UpdateReference(IProductPartLink value, PartModel part)
Expand Down

0 comments on commit 7a375ad

Please sign in to comment.