Ejemplo n.º 1
0
        public virtual async Task SavePricelistAssignmentsAsync(PricelistAssignment[] assignments)
        {
            var pkMap = new PrimaryKeyResolvingMap();

            using (var repository = _repositoryFactory())
            {
                var assignmentsIds       = assignments.Select(x => x.Id).Where(x => x != null).Distinct().ToArray();
                var alreadyExistEntities = await repository.GetPricelistAssignmentsByIdAsync(assignmentsIds);

                foreach (var assignment in assignments)
                {
                    var sourceEntity = AbstractTypeFactory <PricelistAssignmentEntity> .TryCreateInstance().FromModel(assignment, pkMap);

                    var targetEntity = alreadyExistEntities.FirstOrDefault(x => x.Id == assignment.Id);
                    if (targetEntity != null)
                    {
                        sourceEntity.Patch(targetEntity);
                    }
                    else
                    {
                        repository.Add(sourceEntity);
                    }
                }

                await repository.UnitOfWork.CommitAsync();

                pkMap.ResolvePrimaryKeys();

                foreach (var assignment in assignments)
                {
                    PricelistAssignmentsCacheRegion.ExpirePricelistAssignment(assignment.Id);
                }
                ResetCache();
            }
        }
        public virtual async Task DeletePricelistsAssignmentsAsync(string[] ids)
        {
            using (var repository = _repositoryFactory())
            {
                await repository.DeletePricelistAssignmentsAsync(ids);

                await repository.UnitOfWork.CommitAsync();

                foreach (var id in ids)
                {
                    PricelistAssignmentsCacheRegion.ExpirePricelistAssignment(id);
                }
                ResetCache();
            }
        }