示例#1
0
        public async Task RemoveAsync(object[] keyValues, AuthorizeAsync <TResult> authorize, NotFound <TResult> notFound = null,
                                      CancellationToken cancellationToken = default(CancellationToken))
        {
            if (keyValues == null)
            {
                throw new ArgumentNullException(nameof(keyValues));
            }
            var entity = await _dbSet.FindAsync(keyValues);

            if (entity == null)
            {
                (notFound ?? NotFound).Invoke(null);
                return;
            }

            var oldDto = Map(entity);

            if (!await authorize(null, oldDto, cancellationToken))
            {
                return;
            }
            if (SoftDelete)
            {
                _rules.Apply(entity, DataAction.Remove);
            }
            else
            {
                _dbSet.Remove(entity);
            }
        }
示例#2
0
        public async Task UpdateAsync(TResult dto, AuthorizeAsync <TResult> authorize, NotFound <TResult> notFound = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }
            if (authorize == null)
            {
                throw new ArgumentNullException(nameof(authorize));
            }
            var entity = await _dbSet.FindAsync(GetKeyValues(dto), cancellationToken);

            if (entity == null)
            {
                (notFound ?? NotFound).Invoke(dto);
                return;
            }

            var oldDto = Map(entity);

            if (!await authorize(dto, oldDto, cancellationToken))
            {
                return;
            }
            _rules.Apply(entity, DataAction.Update);
            Map(dto, entity);
        }
示例#3
0
        public async Task RemoveRangeAsync(IEnumerable <TResult> dtos, AuthorizeAsync <TResult, int> authorize,
                                           NotFound <TResult, int> notFound = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (dtos == null)
            {
                throw new ArgumentNullException(nameof(dtos));
            }
            if (authorize == null)
            {
                throw new ArgumentNullException(nameof(authorize));
            }
            var dtoArray     = dtos.ToArray();
            var entities     = new List <T>(dtoArray.Length);
            var hasError     = false;
            var continuation = new Continuation();

            for (var index = 0; index < dtoArray.Length; index++)
            {
                var dto    = dtoArray[index];
                var entity = await _dbSet.FindAsync(GetKeyValues(dto), cancellationToken);

                if (entity == null)
                {
                    (notFound ?? NotFound).Invoke(dto, index, continuation);
                    hasError = true;
                    if (continuation.Yes)
                    {
                        continue;
                    }
                    break;
                }

                var oldDto = Map(entity);
                if (!await authorize(dto, oldDto, index, continuation, cancellationToken))
                {
                    hasError = true;
                    if (continuation.Yes)
                    {
                        continue;
                    }
                    break;
                }

                entities.Add(entity);
            }

            if (hasError)
            {
                return;
            }
            if (SoftDelete)
            {
                _rules.Apply(entities, DataAction.Remove);
            }
            else
            {
                _dbSet.RemoveRange(entities);
            }
        }
 public Task RemoveRangeAsync(IEnumerable <TResult> dtos, AuthorizeAsync <TResult, int> authorize,
                              NotFound <TResult, int> notFound = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotSupportedException(ErrorMessage);
 }
 public Task RemoveAsync(object[] keyValues, AuthorizeAsync <TResult> authorize, NotFound <TResult> notFound = null,
                         CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotSupportedException(ErrorMessage);
 }
 public Task UpdateAsync(TResult dto, AuthorizeAsync <TResult> authorize, NotFound <TResult> notFound = null,
                         CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotSupportedException(ErrorMessage);
 }