You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
55 lines
1.5 KiB
using Infrastructure.Extensions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq.Expressions;
|
|
|
|
namespace Infrastructure.Application
|
|
{
|
|
public class BaseResult
|
|
{
|
|
public bool Success { get; set; }
|
|
public List<ValidationResult> ValidationResults { get; private set; } = new List<ValidationResult>();
|
|
|
|
public bool SetSuccess()
|
|
{
|
|
this.Success = true;
|
|
return this.Success;
|
|
}
|
|
|
|
public static BaseResult Result()
|
|
{
|
|
return new BaseResult();
|
|
}
|
|
|
|
public static BaseResult<T> Result<T>()
|
|
{
|
|
return new BaseResult<T>();
|
|
}
|
|
|
|
public void AddError(string errorMessage)
|
|
{
|
|
this.ValidationResults.Add(new ValidationResult(errorMessage));
|
|
}
|
|
|
|
public void AddError(string propertyName, string errorMessage)
|
|
{
|
|
this.ValidationResults.Add(new ValidationResult(errorMessage, new List<string> { propertyName }));
|
|
}
|
|
|
|
public void AddError(Expression<Func<object, object>> expression, string errorMessage)
|
|
{
|
|
this.ValidationResults.Add(new ValidationResult(errorMessage, new List<string> { expression.GetPropertyName() }));
|
|
}
|
|
|
|
public void AddErrors(List<ValidationResult> validationResults)
|
|
{
|
|
this.ValidationResults.AddRange(validationResults);
|
|
}
|
|
}
|
|
|
|
public class BaseResult<T> : BaseResult
|
|
{
|
|
public T Data { get; set; }
|
|
}
|
|
} |