Created
June 1, 2018 04:47
-
-
Save aodendaal/86fedc36b3593a4adbd4e35ef0327702 to your computer and use it in GitHub Desktop.
ASP.NET Boilerplate entity not found exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Abp.AppFactory | |
{ | |
public class AbpEntityNotFoundException : Exception | |
{ | |
private string field; | |
private string value; | |
private string entityType; | |
public override string Message | |
{ | |
get | |
{ | |
if (field == null && value == null) | |
{ | |
return $"Entity '{entityType}' not found"; | |
} | |
else if (field == null) | |
{ | |
return $"Entity '{entityType}' with Id '{value}' not found"; | |
} | |
else | |
{ | |
return $"Entity '{entityType}' with '{field}' = '{value}' not found"; | |
} | |
} | |
} | |
public AbpEntityNotFoundException(Type entityType) | |
{ | |
this.entityType = entityType.Name; | |
} | |
public AbpEntityNotFoundException(Type entityType, long id) | |
{ | |
this.entityType = entityType.Name; | |
this.value = id.ToString(); | |
} | |
public AbpEntityNotFoundException(Type entityType, string propertyName, string value) | |
{ | |
this.entityType = entityType.Name; | |
this.field = propertyName; | |
this.value = value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment