public PartyTypePair AddPartyTypePair(string title, PartyType alowedSource, PartyType alowedTarget, string description,
PartyRelationshipType partyRelationshipType)
{
Contract.Requires(!string.IsNullOrEmpty(title));
Contract.Requires(alowedSource != null && alowedSource.Id > 0);
Contract.Requires(alowedTarget != null && alowedTarget.Id > 0);
Contract.Ensures(Contract.Result<PartyTypePair>() != null && Contract.Result<PartyTypePair>().Id >= 0);
var entity = new PartyTypePair()
{
AlowedSource = alowedSource,
AlowedTarget = alowedTarget,
Description = description,
PartyRelationshipType = partyRelationshipType,
Title = title
};
using (IUnitOfWork uow = this.GetUnitOfWork())
{
IRepository<PartyTypePair> repo = uow.GetRepository<PartyTypePair>();
//Is it usefull?
//var similarPartTypePair = repo.Get(item => item.AlowedSource == alowedSource && item.AlowedTarget == alowedTarget);
//if (similarPartTypePair.Any())
// throw new Exception("Add party type pair failed.\r\nThere is already an entity with the same elements.");
repo.Put(entity);
uow.Commit();
}
return (entity);
}