Exemplo n.º 1
0
        public virtual async Task SaveChangesAsync(params OperationLog[] operationLogs)
        {
            if (operationLogs == null)
            {
                throw new ArgumentNullException(nameof(operationLogs));
            }
            var pkMap = new PrimaryKeyResolvingMap();

            using (var repository = _repositoryFactory())
            {
                var ids           = operationLogs.Where(x => !x.IsTransient()).Select(x => x.Id).Distinct().ToArray();
                var existEntities = await repository.GetOperationLogsByIdsAsync(ids);

                foreach (var operation in operationLogs)
                {
                    var existsEntity   = existEntities.FirstOrDefault(x => x.Id == operation.Id);
                    var modifiedEntity = AbstractTypeFactory <OperationLogEntity> .TryCreateInstance().FromModel(operation, pkMap);

                    if (existsEntity != null)
                    {
                        modifiedEntity.Patch(existsEntity);
                    }
                    else
                    {
                        repository.Add(modifiedEntity);
                    }
                }
                await repository.UnitOfWork.CommitAsync();

                ChangeLogCacheRegion.ExpireRegion();
            }
        }
Exemplo n.º 2
0
        public virtual async Task DeleteAsync(string[] ids)
        {
            using (var repository = _repositoryFactory())
            {
                var existEntities = await repository.GetOperationLogsByIdsAsync(ids);

                foreach (var entity in existEntities)
                {
                    repository.Remove(entity);
                }
                await repository.UnitOfWork.CommitAsync();

                ChangeLogCacheRegion.ExpireRegion();
            }
        }
Exemplo n.º 3
0
 public void Reset()
 {
     ChangeLogCacheRegion.ExpireRegion();
 }