private void AddOption(ProductOptionDto dto)
        {
            var optionDomain = new ProductOptionDomain(this, dto);

            Options.Add(optionDomain);
            AddIntegratedEvent(ProductEventType.PRODUCT_OPTION_ADDED, dto.Id);
            Modify();
        }
 private void UpdateOption(ProductOptionDomain optionDomain, ProductOptionDto dto)
 {
     optionDomain.Update(dto);
     if (optionDomain.Modified)
     {
         AddIntegratedEvent(ProductEventType.PRODUCT_OPTION_UPDATED, dto.Id);
         Modify();
     }
 }
        private void SetOptions(List <ProductOptionDto> optionDtos)
        {
            Options = Options ?? new List <ProductOptionDomain>();

            var currentOptionIds = Options.Select(s => s.Id).ToList();
            var targetOptionIds  = optionDtos.Select(s => s.Id).ToList();

            var removedOptionIds = currentOptionIds.Where(w => !targetOptionIds.Contains(w)).ToList();

            foreach (var removeOptionId in removedOptionIds)
            {
                RemoveOption(removeOptionId);
            }

            foreach (var optionDto in optionDtos)
            {
                var optionDomain = Options.Where(w => w.Id.Equals(optionDto.Id)).SingleOrDefault();
                if (optionDomain == null)
                {
                    AddOption(optionDto);
                }
                else
                {
                    UpdateOption(optionDomain, optionDto);
                }
            }

            var newListOption = new List <ProductOptionDomain>();

            for (int i = 0; i < optionDtos.Count; i++)
            {
                ProductOptionDomain optionDomain = null;
                for (int j = 0; j < Options.Count; j++)
                {
                    if (!optionDtos[i].Id.Equals(Options[j].Id))
                    {
                        continue;
                    }
                    optionDomain = Options[j];
                    if (i != j && currentOptionIds.Contains(optionDtos[i].Id))
                    {
                        AddIntegratedEvent(ProductEventType.PRODUCT_OPTION_INDEX_CHANGED, optionDtos[i].Id);
                        Modify();
                    }
                }
                newListOption.Add(optionDomain);
            }
            Options = newListOption;
        }