Hi,
I have two repository classes below, MoneyTransferRepository class is used by other classes in my project. I have designed it this way - is it right? If not, what is the best way?
Thanks
public interface IMoneyTransferRepository
{
void UpdateBalance();
}
public interface IOrderRepository
{
void Checkout();
void SaveOrder();
}
public class MoneyTransferRepository : IMoneyTransferRepository
{
DBDataContext DB;
public MoneyTransferRepository(IDbConnection connection)
{
DB = new DBDataContext(connection);
}
public void UpdateBalance()
{
//do something DB.Table1.Update
}
}
public class OrderRepository : IOrderRepository,IMoneyTransferRepository
{
DBDataContext DB;
IMoneyTransferRepository moneyTransferRepository;
public OrderRepository()
{
DB = new DBDataContext();
moneyTransferRepository = new MoneyTransferRepository(DB.Connection);
}
public void Checkout()
{
TransactionOptions transactionOptions = new TransactionOptions();
transactionOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
{
try
{
UpdateBalance();
SaveOrder();
transactionScope.Complete();
}
catch
{
}
}
}
public void UpdateBalance()
{
moneyTransferRepository.UpdateBalance();
}
public void SaveOrder()
{
//do something DB.SaveOrder.Update ......
// DB.Updatestock .....
}
}