public async Task <OperationResult <List <Region> > > ListAsync()
        {
            try
            {
                var transactionOptions = new TransactionOptions
                {
                    IsolationLevel = IsolationLevel.ReadCommitted,
                    Timeout        = TimeSpan.FromSeconds(30)
                };

                using var transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOptions, TransactionScopeAsyncFlowOption.Enabled);
                var res = await _dao.ListAsync();

                transactionScope.Complete();
                return(new OperationResult <List <Region> >()
                {
                    Success = true, Result = res
                });
            }
            catch (Exception e)
            {
                return(new OperationResult <List <Region> >()
                {
                    Success = false, Exception = e
                });
            }
        }
Esempio n. 2
0
        public async Task <OperationResult <bool> > CreateAsync(Region item)
        {
            try
            {
                if (_dao.ListAsync().Result.Any(x => x.Name.ToLower().Trim() == item.Name.ToLower().Trim() && !x.IsDeleted))
                {
                    return new OperationResult <bool>()
                           {
                               Success = true, Result = false, Message = "Name already exists"
                           }
                }
                ;
                await _dao.CreateAsync(item);

                return(new OperationResult <bool>()
                {
                    Success = true, Result = true
                });
            }
            catch (Exception e)
            {
                return(new OperationResult <bool>()
                {
                    Success = false, Exception = e
                });
            }
        }