private IActionResult InternalServerErrorResult(Exception exception)
        {
            NullGuard.NotNull(exception, nameof(exception));

            IntranetExceptionBase intranetException = new IntranetExceptionBuilder(ErrorCode.InternalError, exception.Message)
                                                      .WithInnerException(exception)
                                                      .Build();

            return(InternalServerErrorResult(intranetException));
        }
        private static IntranetExceptionBase BuildException(string errorDetails, Type type = null)
        {
            NullGuard.NotNullOrWhiteSpace(errorDetails, nameof(errorDetails));

            IntranetExceptionBuilder intranetExceptionBuilder = new IntranetExceptionBuilder(ErrorCode.SubmittedMessageInvalid, errorDetails);

            if (type != null)
            {
                intranetExceptionBuilder.WithValidatingType(type);
            }

            return(intranetExceptionBuilder.Build());
        }
        public IValidator ShouldBeDeletable <TValue, TDeletable>(TValue value, Func <TValue, Task <TDeletable> > deletableGetter, Type validatingType, string validatingField, bool allowNull = false) where TDeletable : IDeletable
        {
            NullGuard.NotNull(deletableGetter, nameof(deletableGetter))
            .NotNull(validatingType, nameof(validatingType))
            .NotNullOrWhiteSpace(validatingField, nameof(validatingField));

            if (Equals(value, null) && allowNull)
            {
                return(this);
            }

            if (Equals(value, null))
            {
                throw new IntranetExceptionBuilder(ErrorCode.ValueCannotBeNull, validatingField)
                      .WithValidatingType(validatingType)
                      .WithValidatingField(validatingField)
                      .Build();
            }

            Exception innerException = null;

            try
            {
                IDeletable deletable = deletableGetter(value).GetAwaiter().GetResult();
                if (deletable != null && deletable.Deletable)
                {
                    return(this);
                }
            }
            catch (AggregateException aggregateException)
            {
                aggregateException.Handle(exception =>
                {
                    innerException = exception;
                    return(true);
                });
            }
            catch (Exception exception)
            {
                innerException = exception;
            }

            IIntranetExceptionBuilder intranetExceptionBuilder = new IntranetExceptionBuilder(ErrorCode.ValueShouldReferToDeletableEntity, validatingField)
                                                                 .WithValidatingType(validatingType)
                                                                 .WithValidatingField(validatingField);

            throw (innerException == null ? intranetExceptionBuilder : intranetExceptionBuilder.WithInnerException(innerException)).Build();
        }
        public IValidator ShouldBeUnknownValue <T>(T value, Func <T, Task <bool> > isUnknownValueGetter, Type validatingType, string validatingField, bool allowNull = false)
        {
            NullGuard.NotNull(isUnknownValueGetter, nameof(isUnknownValueGetter))
            .NotNull(validatingType, nameof(validatingType))
            .NotNullOrWhiteSpace(validatingField, nameof(validatingField));

            if (Equals(value, null) && allowNull)
            {
                return(this);
            }

            if (Equals(value, null))
            {
                throw new IntranetExceptionBuilder(ErrorCode.ValueCannotBeNull, validatingField)
                      .WithValidatingType(validatingType)
                      .WithValidatingField(validatingField)
                      .Build();
            }

            Exception innerException = null;

            try
            {
                if (isUnknownValueGetter(value).GetAwaiter().GetResult())
                {
                    return(this);
                }
            }
            catch (AggregateException aggregateException)
            {
                aggregateException.Handle(exception =>
                {
                    innerException = exception;
                    return(true);
                });
            }
            catch (Exception exception)
            {
                innerException = exception;
            }

            IIntranetExceptionBuilder intranetExceptionBuilder = new IntranetExceptionBuilder(ErrorCode.ValueShouldBeUnknown, validatingField)
                                                                 .WithValidatingType(validatingType)
                                                                 .WithValidatingField(validatingField);

            throw (innerException == null ? intranetExceptionBuilder : intranetExceptionBuilder.WithInnerException(innerException)).Build();
        }