-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding project repositories base. related #1
- Loading branch information
1 parent
371c404
commit 9e72834
Showing
8 changed files
with
310 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.Serialization; | ||
using System.Text; | ||
using PetStore.Core.Extension; | ||
using PetStore.Resources; | ||
|
||
namespace PetStore.Core.Repository | ||
{ | ||
/// <summary> | ||
/// Exception on adding objects to repositories | ||
/// </summary> | ||
public class AddPersistenceException : PersistenceException | ||
{ | ||
#region Constructors | ||
|
||
public AddPersistenceException() : this(GeneralResources.AddPersistenceExceptionDefaultMessage) { } | ||
|
||
public AddPersistenceException(string message) : base(message) { } | ||
|
||
public AddPersistenceException(string message, Exception innerException) : base(message, innerException) { } | ||
|
||
protected AddPersistenceException(SerializationInfo info, StreamingContext context) | ||
: base(info, context) | ||
{ | ||
} | ||
|
||
public AddPersistenceException(object obj, Exception innerException) : base(GetMessage(obj), innerException) { } | ||
|
||
#endregion | ||
|
||
#region Private Methods | ||
|
||
private static string GetMessage(object obj) | ||
{ | ||
return GeneralResources.AddPersistenceExceptionCustomMessage.FormatWith(obj); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.Serialization; | ||
using System.Text; | ||
using PetStore.Core.Extension; | ||
using PetStore.Resources; | ||
|
||
namespace PetStore.Core.Repository | ||
{ | ||
/// <summary> | ||
/// Exception on retrieving objects from repositories | ||
/// </summary> | ||
public class FindPersistenceException : PersistenceException | ||
{ | ||
#region Constructors | ||
|
||
public FindPersistenceException() : this(GeneralResources.FindPersistenceExceptionDefaultMessage) { } | ||
|
||
public FindPersistenceException(string message) : base(message) { } | ||
|
||
public FindPersistenceException(string message, Exception innerException) : base(message, innerException) { } | ||
|
||
protected FindPersistenceException(SerializationInfo info, StreamingContext context) | ||
: base(info, context) | ||
{ | ||
} | ||
|
||
public FindPersistenceException(Type entityType, long objectId, Exception innerException) : base(GetMessage(entityType, objectId), innerException) { } | ||
|
||
#endregion | ||
|
||
#region Private Methods | ||
|
||
private static string GetMessage(Type entityType, long objectId) | ||
{ | ||
return GeneralResources.FindPersistenceExceptionCustomMessage.FormatWith(objectId, entityType); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace PetStore.Core.Repository | ||
{ | ||
/// <summary> | ||
/// Generic repository interface | ||
/// </summary> | ||
/// <typeparam name="TEntity">Entity (agregation root).</typeparam> | ||
public interface IRepository<TEntity> where TEntity : class | ||
{ | ||
/// <summary> | ||
/// Add (or update) an entity to the repository | ||
/// </summary> | ||
/// <param name="obj">Object to be added/updated.</param> | ||
/// <exception cref="AddPersistenceException">Exception thrown when there is a problem on adding the object to the repository.</exception> | ||
void Add(TEntity obj); | ||
|
||
/// <summary> | ||
/// Remove an entity from the repository | ||
/// </summary> | ||
/// <param name="obj">Object to be removed.</param> | ||
/// <exception cref="RemovePersistenceException">Exception thrown when there is a problem on removing an entity from the repository.</exception> | ||
void Remove(TEntity obj); | ||
|
||
/// <summary> | ||
/// Retrieves an entity. | ||
/// </summary> | ||
/// <param name="id">ID</param> | ||
/// <returns>Entity</returns> | ||
/// <exception cref="FindPersistenceException">Exception thrown when there is a problem on retrieving an entity from the repository.</exception> | ||
TEntity FindById(int id); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.Serialization; | ||
using System.Text; | ||
using PetStore.Resources; | ||
|
||
namespace PetStore.Core.Repository | ||
{ | ||
/// <summary> | ||
/// Generic persistence exception. | ||
/// </summary> | ||
public abstract class PersistenceException : DomainException | ||
{ | ||
#region Constructors | ||
|
||
protected PersistenceException() | ||
: this(GeneralResources.PersistenceExceptionDefaultMessage) | ||
{ | ||
} | ||
|
||
protected PersistenceException(string message) | ||
: base(message) | ||
{ | ||
} | ||
|
||
protected PersistenceException(string message, Exception innerException) | ||
: base(message, innerException) | ||
{ | ||
} | ||
|
||
protected PersistenceException(SerializationInfo info, StreamingContext context) | ||
: base(info, context) | ||
{ | ||
} | ||
|
||
#endregion | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/PetStore.Core/Repository/RemovePersistenceException.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.Serialization; | ||
using System.Text; | ||
using PetStore.Core.Extension; | ||
using PetStore.Resources; | ||
|
||
namespace PetStore.Core.Repository | ||
{ | ||
/// <summary> | ||
/// Exception on removing objects from repositories | ||
/// </summary> | ||
public class RemovePersistenceException : PersistenceException | ||
{ | ||
#region Constructors | ||
|
||
public RemovePersistenceException() : this(GeneralResources.RemovePersistenceExceptionDefaultMessage) { } | ||
|
||
public RemovePersistenceException(string message) : base(message) { } | ||
|
||
public RemovePersistenceException(string message, Exception innerException) : base(message, innerException) { } | ||
|
||
protected RemovePersistenceException(SerializationInfo info, StreamingContext context) | ||
: base(info, context) | ||
{ | ||
} | ||
|
||
public RemovePersistenceException(object obj, Exception innerException) : base(GetMessage(obj), innerException) { } | ||
|
||
#endregion | ||
|
||
#region Private Methods | ||
|
||
private static string GetMessage(object obj) | ||
{ | ||
return GeneralResources.RemovePersistenceExceptionCustomMessage.FormatWith(obj); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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