コード例 #1
0
        public virtual CommandResult <bool> Delete(TDataTransferObject dto)
        {
            var result = new CommandResult <bool>(); // We only return serializable Data transfer objects (DTO) from this layer

            try
            {
                var entity = _objectMapper.Map <TEntity>(dto);          // Map the entity to a DTO

                using (var scope = UnitOfWorkScopeFactory.Create())     // Always use a Unit of Work
                {
                    var domainData = _crudDomainService.Delete(entity); // Perform the work

                    if (domainData.HasException)
                    {
                        throw domainData.Exception; // This generally doesn't happen since we allow domain exceptions to bubble up to the application layer
                    }
                    else
                    {
                        result.DataResult = domainData.DataResult;
                    }

                    scope.Commit(); // Commit the transaction
                }
                return(result);
            }
            catch (BusinessException ex) // The exception was handled at a lower level if we get BusinessException
            {
                result.Exception = ex;
                this.ExceptionManager.HandleException(ex, DefaultExceptionPolicies.ApplicationReplacePolicy);
                throw ex;
            }
            catch (AutoMapperMappingException ex) // Mapping Exception
            {
                this.ExceptionManager.HandleException(ex, DefaultExceptionPolicies.ApplicationWrapPolicy);
                throw ex;
            }
            catch (ApplicationException ex) // We didn't do a good job handling exceptions at a lower level or have failed logic in this class
            {
                result.Exception = ex;
                this.ExceptionManager.HandleException(ex, DefaultExceptionPolicies.ApplicationWrapPolicy);
                throw ex;
            }
        }
コード例 #2
0
 public virtual int Delete(TKey id)
 {
     return(domainService.Delete(id));
 }