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); }
public PartyRelationship AddPartyRelationship(PartyX firstParty, PartyX secondParty, PartyRelationshipType partyRelationshipType, string title, string description, DateTime? startDate = null, DateTime? endDate = null, string scope = "") { Contract.Requires(!string.IsNullOrWhiteSpace(title)); Contract.Requires(firstParty != null); Contract.Requires(firstParty.Id >= 0, "Provided first entity must have a permanent ID"); Contract.Requires(secondParty != null); Contract.Requires(secondParty.Id >= 0, "Provided first entity must have a permanent ID"); Contract.Requires(partyRelationshipType != null && partyRelationshipType.Id > 0); Contract.Ensures(Contract.Result<PartyRelationship>() != null && Contract.Result<PartyRelationship>().Id >= 0); if (startDate == null) startDate = DateTime.MinValue; if (endDate == null) endDate = DateTime.MaxValue; var entity = new PartyRelationship() { Description = description, EndDate = endDate.Value, FirstParty = firstParty, PartyRelationshipType = partyRelationshipType, Scope = scope, SecondParty = secondParty, StartDate = startDate.Value, Title = title }; using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository<PartyRelationship> repoPR = uow.GetRepository<PartyRelationship>(); IRepository<PartyRelationshipType> repoRelType = uow.GetRepository<PartyRelationshipType>(); partyRelationshipType = repoRelType.Reload(partyRelationshipType); //Check if there is another relationship var cnt = repoPR.Query(item => (item.PartyRelationshipType != null && item.PartyRelationshipType.Id == partyRelationshipType.Id) && (item.FirstParty != null && item.FirstParty.Id == firstParty.Id) && (item.SecondParty != null && item.SecondParty.Id == secondParty.Id)).Count(); //if ( > 0) // BexisException.Throw(entity, "This relationship is already exist in database.", BexisException.ExceptionType.Add); //Check maximun cardinality if (partyRelationshipType.MaxCardinality <= cnt) BexisException.Throw(entity, string.Format("Maximum relations for this type of relation is {0}.", partyRelationshipType.MaxCardinality), BexisException.ExceptionType.Add); //Check if there is a relevant party type pair var alowedSource = partyRelationshipType.AssociatedPairs.FirstOrDefault(item => item.AlowedSource == firstParty.PartyType || item.AlowedSource == secondParty.PartyType); var alowedTarget = partyRelationshipType.AssociatedPairs.FirstOrDefault(item => item.AlowedTarget == firstParty.PartyType || item.AlowedTarget == secondParty.PartyType); if (alowedSource == null || alowedTarget == null) BexisException.Throw(entity, string.Format("There is not relevant 'PartyTypePair' for these types of parties.", partyRelationshipType.MaxCardinality), BexisException.ExceptionType.Add); partyRelationshipType.PartyRelationships.Add(entity); repoPR.Put(entity); uow.Commit(); } return (entity); }
/// <summary> /// Creating PartyRelationshipType /// because PartyRelationshipType should have PartyTypePairs,partyTypePair created in the same time of creating PartyRelationshipType /// </summary> /// <param name="title"></param> /// <param name="description"></param> /// <param name="indicatesHierarchy"></param> /// <param name="maxCardinality"></param> /// <param name="minCardinality"></param> /// <param name="partyTypePairAlowedSource"></param> /// <param name="partyTypePairAlowedTarget"></param> /// <param name="partyTypePairTitle"></param> /// <param name="partyTypePairDescription"></param> /// <returns></returns> public PartyRelationshipType Create(string title, string description, bool indicatesHierarchy, int maxCardinality, int minCardinality, PartyType partyTypePairAlowedSource, PartyType partyTypePairAlowedTarget, string partyTypePairTitle, string partyTypePairDescription) { Contract.Requires(!string.IsNullOrWhiteSpace(title) && !string.IsNullOrWhiteSpace(partyTypePairTitle)); Contract.Requires(partyTypePairAlowedSource != null && partyTypePairAlowedSource.Id > 0); Contract.Requires(partyTypePairAlowedTarget != null && partyTypePairAlowedTarget.Id > 0); Contract.Ensures((Contract.Result<PartyRelationshipType>() != null && Contract.Result<PartyRelationshipType>().Id >= 0) && (Contract.Result<PartyTypePair>() != null && Contract.Result<PartyTypePair>().Id >= 0)); PartyRelationshipType entity = new PartyRelationshipType() { Description = description, IndicatesHierarchy = indicatesHierarchy, MaxCardinality = maxCardinality, MinCardinality = minCardinality, Title = title }; var partyTypeEntity = new PartyTypePair() { AlowedSource = partyTypePairAlowedSource, AlowedTarget = partyTypePairAlowedTarget, Description = partyTypePairDescription, PartyRelationshipType = entity, Title = partyTypePairTitle }; using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository<PartyRelationshipType> repo = uow.GetRepository<PartyRelationshipType>(); IRepository<PartyTypePair> repoPTP = uow.GetRepository<PartyTypePair>(); repo.Put(entity); repoPTP.Put(partyTypeEntity); uow.Commit(); } return (entity); }
public bool Delete(PartyRelationshipType partyRelationType) { Contract.Requires(partyRelationType != null); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository<PartyRelationshipType> repoPR = uow.GetRepository<PartyRelationshipType>(); IRepository<PartyType> repoType = uow.GetRepository<PartyType>(); var entity = repoPR.Reload(partyRelationType); //If there is a relation between entity and a party we couldn't delete it if (entity.PartyRelationships.Count() > 0) BexisException.Throw(entity, "There are some relations between this 'PartyRelationshipType' and 'Party'", BexisException.ExceptionType.Delete); // remove all associations between the entity and AssociatedPairs entity.AssociatedPairs.ToList().ForEach(item => item.PartyRelationshipType = null); entity.AssociatedPairs.Clear(); repoPR.Delete(entity); uow.Commit(); } return (true); }
public PartyRelationship() { PartyRelationshipType = new PartyRelationshipType(); SourceParty = new Party(); TargetParty = new Party(); }
private bool removeTestPartyRelationshipType(PartyRelationshipType partyRelationshipType) { Dlm.Services.Party.PartyRelationshipTypeManager pmr = new Dlm.Services.Party.PartyRelationshipTypeManager(); return pmr.Delete(partyRelationshipType); }
private Dlm.Entities.Party.PartyRelationship addTestPartyRelationship(Dlm.Entities.Party.Party firstParty, Dlm.Entities.Party.Party secondParty, PartyRelationshipType prt) { Dlm.Services.Party.PartyManager pm = new Dlm.Services.Party.PartyManager(); return pm.AddPartyRelationship(firstParty, secondParty, prt, "test Rel", "test relationship", DateTime.Now); }
public PartyRelationship() { PartyRelationshipType = new PartyRelationshipType(); FirstParty = new Party(); SecondParty = new Party(); }