Example #1
0
        private async Task InsertAnchorsAsync(Material material, DatabaseMaterial model)
        {
            if (material.Anchors.IsEmpty())
            {
                return;
            }

            var ids = model.Anchors
                      .Select(x => x.Id)
                      .ToArray();

            var anchors = material.Anchors
                          .Where(x => !ids.Contains(x.Id))
                          .Select(Mapper.Map <DatabaseMaterialAnchor>)
                          .ToList();

            if (anchors.IsEmpty())
            {
                return;
            }

            anchors.ForEach(x => x.MaterialId = model.Id);

            await _repositoryMaterialAnchor.AddAsync(anchors, true);

            model.Anchors.AddRange(anchors);
        }
Example #2
0
        private async Task RemoveAnchorsAsync(Material material, DatabaseMaterial model)
        {
            if (material.Anchors.IsEmpty())
            {
                if (model.Anchors.IsNotEmpty())
                {
                    await _repositoryMaterialAnchor.RemoveAsync(model.Anchors, true);
                }

                return;
            }

            var ids = material.Anchors
                      .Select(x => x.Id)
                      .ToArray();

            var anchors = model.Anchors
                          .Where(x => !ids.Contains(x.Id))
                          .ToArray();

            if (anchors.IsNotEmpty())
            {
                await _repositoryMaterialAnchor.RemoveAsync(anchors, true);
            }
        }
Example #3
0
        private async Task UpdateAnchorsAsync(Material material, DatabaseMaterial model)
        {
            if (material.Anchors.IsEmpty())
            {
                return;
            }

            var ids = material.Anchors
                      .Select(x => x.Id)
                      .ToArray();

            MaterialAnchor GetAnchor(int id)
            {
                return(material.Anchors.First(y => y.Id == id));
            }

            var anchors = model.Anchors
                          .Where(x => ids.Contains(x.Id))
                          .Select(x => Mapper.Map(GetAnchor(x.Id), x))
                          .ToArray();

            if (anchors.IsNotEmpty())
            {
                await _repositoryMaterialAnchor.UpdateAsync(anchors, true);
            }
        }
Example #4
0
        private async Task ProcessAnchorsAsync(Material material, DatabaseMaterial model)
        {
            await RemoveAnchorsAsync(material, model);
            await UpdateAnchorsAsync(material, model);
            await InsertAnchorsAsync(material, model);

            await _repositoryMaterial.UpdateAsync(model, true);
        }