public PartyTypePair AddPartyTypePair(string title, PartyType allowedSource, PartyType allowedTarget, string description, bool partyRelationShipTypeDefault, PartyRelationshipType partyRelationshipType, string conditionSource, string conditionTarget) { Contract.Requires(!string.IsNullOrEmpty(title)); Contract.Requires(allowedSource != null && allowedSource.Id > 0); Contract.Requires(allowedTarget != null && allowedTarget.Id > 0); Contract.Ensures(Contract.Result <PartyTypePair>() != null && Contract.Result <PartyTypePair>().Id >= 0); var entity = new PartyTypePair() { AllowedSource = allowedSource, AllowedTarget = allowedTarget, Description = description, PartyRelationshipType = partyRelationshipType, Title = title, PartyRelationShipTypeDefault = partyRelationShipTypeDefault, ConditionSource = conditionSource, ConditionTarget = conditionTarget }; using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <PartyTypePair> repo = uow.GetRepository <PartyTypePair>(); repo.Put(entity); 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 void AddSameRoleIntoRelationship_FailTest() { var husbandType = new PartyRoleType("Husband"); var husbandRole = new PartyRole(husbandType); var familyRelationshipType = new PartyRelationshipType("Family"); var famalyCanHasHusband = new PartyRelationshipConstraint(husbandType); familyRelationshipType.AddConstraint(famalyCanHasHusband); var familyCanHaveOnlyOneHusband = new PartyRelationshipConstraint(familyRelationshipType, new Func <PartyRelationship, PartyRole, bool>((relationship, role) => { var c = relationship.Roles.Count(r => r.Id == role.Id); if (c == 0) { return(true); } else { return(false); } })); familyRelationshipType.AddConstraint(familyCanHaveOnlyOneHusband); var familyRelationship = new PartyRelationship(familyRelationshipType); familyRelationship.AddRole(husbandRole); familyRelationship.AddRole(husbandRole); }
public PartyTypePair UpdatePartyTypePair(long id, string title, PartyType allowedSource, PartyType alowedTarget, string description, bool partyRelationShipTypeDefault, PartyRelationshipType partyRelationshipType) { Contract.Requires(id > 0); Contract.Requires(!string.IsNullOrEmpty(title)); Contract.Requires(allowedSource != null && allowedSource.Id > 0); Contract.Requires(alowedTarget != null && alowedTarget.Id > 0); Contract.Ensures(Contract.Result <PartyTypePair>() != null && Contract.Result <PartyTypePair>().Id >= 0); var entity = new PartyTypePair(); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <PartyTypePair> repo = uow.GetRepository <PartyTypePair>(); entity = repo.Get(id); if (entity == null) { BexisException.Throw(null, "PartyTypePair not found", BexisException.ExceptionType.Edit); } entity.AllowedSource = allowedSource; entity.AllowedTarget = alowedTarget; entity.Description = description; entity.PartyRelationshipType = partyRelationshipType; entity.Title = title; entity.PartyRelationShipTypeDefault = partyRelationShipTypeDefault; repo.Put(entity); uow.Commit(); } return(entity); }
public static int CountRelations(long sourcePartyId, PartyRelationshipType partyRelationshipType) { PartyManager partyManager = new PartyManager(); var cnt = partyManager.PartyRelationshipRepository.Query(item => (item.PartyRelationshipType != null && item.PartyRelationshipType.Id == partyRelationshipType.Id) && (item.FirstParty != null && (item.FirstParty.Id == sourcePartyId) || (item.SecondParty.Id == sourcePartyId)) && (item.EndDate >= DateTime.Now)).Count(); return(cnt); }
public IEnumerable <PartyTypePair> GetPartyTypePairs(PartyRelationshipType partyRelationshipType, PartyType sourcePartyType, PartyType targetPartyType) { using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <PartyTypePair> repoPartyTypePair = uow.GetRepository <PartyTypePair>(); var partyTypePairs = repoPartyTypePair.Get(cc => cc.PartyRelationshipType.Id == partyRelationshipType.Id && cc.AllowedSource.Id == sourcePartyType.Id && cc.AllowedTarget.Id == targetPartyType.Id); return(partyTypePairs); } }
public void ValidateRoleConstraint_SuccessTest() { var husbandCanBePersonOnly = new PartyRoleConstraint(typeof(Person)); var husbandType = new PartyRoleType("Husband"); husbandType.AddConstraint(husbandCanBePersonOnly); var husbandRole = new PartyRole(husbandType); var whifeCanBePersonOnly = new PartyRoleConstraint(typeof(Person)); var whifeType = new PartyRoleType("Whife"); whifeType.AddConstraint(whifeCanBePersonOnly); var whifeRole = new PartyRole(whifeType); var familyRelationshipTyp = new PartyRelationshipType("Family"); var famalyCanHasHusband = new PartyRelationshipConstraint(husbandType); familyRelationshipTyp.AddConstraint(famalyCanHasHusband); var famalyCanHasWhife = new PartyRelationshipConstraint(whifeType); familyRelationshipTyp.AddConstraint(famalyCanHasWhife); var familyRelationship = new PartyRelationship(familyRelationshipTyp); familyRelationship.AddRole(husbandRole); familyRelationship.AddRole(whifeRole); Assert.AreEqual(2, familyRelationship.Roles.Count()); Assert.AreEqual(1, husbandRole.Type.RoleConstraints.Count()); Assert.AreEqual(0, husbandRole.Type.Rules.Count()); Assert.AreEqual(2, familyRelationship.Roles.Count()); Assert.AreEqual(1, whifeRole.Type.RoleConstraints.Count()); Assert.AreEqual(0, whifeRole.Type.Rules.Count()); var john = new Person() { Birthdate = new DateTime(1972, 11, 4) }; familyRelationship.Assign(husbandRole, john); var marry = new Person() { Birthdate = new DateTime(1976, 4, 16) }; familyRelationship.Assign(whifeRole, marry); Assert.AreEqual(2, familyRelationship.Roles.Count()); Assert.AreEqual(1, familyRelationship.GetRoles(john).Count()); Assert.AreEqual(1, familyRelationship.GetRoles(marry).Count()); }
/// <summary> /// /// </summary> /// <param name="partyTypePair"></param> /// <param name="partyRelationshipType"></param> /// <param name="partyRelationshipTypeManager"></param> private static void UpdateOrCreatePartyTypePair(PartyTypePair partyTypePair, PartyRelationshipType partyRelationshipType, PartyRelationshipTypeManager partyRelationshipTypeManager) { var entity = partyRelationshipTypeManager.PartyTypePairRepository.Get(item => item.Title == partyTypePair.Title && item.PartyRelationshipType.Id == partyRelationshipType.Id).FirstOrDefault(); if (entity != null) { partyRelationshipTypeManager.UpdatePartyTypePair(entity.Id, partyTypePair.Title, partyTypePair.SourcePartyType, partyTypePair.TargetPartyType, partyTypePair.Description, "", "", partyTypePair.PartyRelationShipTypeDefault, entity.PartyRelationshipType, entity.PermissionTemplate); } else { partyRelationshipTypeManager.AddPartyTypePair(partyTypePair.Title, partyTypePair.SourcePartyType, partyTypePair.TargetPartyType, partyTypePair.Description, partyTypePair.PartyRelationShipTypeDefault, partyRelationshipType, partyTypePair.ConditionSource, partyTypePair.ConditionTarget, partyTypePair.PermissionTemplate); } }
public void AddCustomer_SuccessTest() { var customerRoleType = new PartyRoleType("Customer"); var customerRole = new PartyRole(customerRoleType); var customerRelationshipType = new PartyRelationshipType("Customers relationship"); var customerRelationship = new PartyRelationship(customerRelationshipType); customerRelationship.AddRole(customerRole); var vlad = new Person(); customerRelationship.Assign(customerRole, vlad); var ilona = new Person(); customerRelationship.Assign(customerRole, ilona); }
/// <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 displayName, string description, bool indicatesHierarchy, int maxCardinality, int minCardinality, bool partyRelationShipTypeDefault, PartyType partyTypePairAlowedSource, PartyType partyTypePairAlowedTarget, string partyTypePairTitle, string partyTypePairDescription, string conditionSource, string conditionTarget, int permissionTemplate) { 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.Ensures(Contract.Result<PartyTypePair>() != null && Contract.Result<PartyTypePair>().Id >= 0); PartyRelationshipType entity = new PartyRelationshipType() { Description = description, IndicatesHierarchy = indicatesHierarchy, MaxCardinality = maxCardinality, MinCardinality = minCardinality, Title = title, DisplayName = displayName }; var partyTypeEntity = new PartyTypePair() { SourcePartyType = partyTypePairAlowedSource, TargetPartyType = partyTypePairAlowedTarget, Description = partyTypePairDescription, PartyRelationshipType = entity, Title = partyTypePairTitle, PartyRelationShipTypeDefault = partyRelationShipTypeDefault, ConditionSource = conditionSource, PermissionTemplate = permissionTemplate, ConditionTarget = conditionTarget }; 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 void AddWrongRoleIntoRelationship_FailTest() { var husbandType = new PartyRoleType("Husband"); var husbandRole = new PartyRole(husbandType); var whifeType = new PartyRoleType("Whife"); var whifeRole = new PartyRole(whifeType); var familyRelationshipTyp = new PartyRelationshipType("Family"); var famalyCanHasHusband = new PartyRelationshipConstraint(husbandType); familyRelationshipTyp.AddConstraint(famalyCanHasHusband); var famalyCanHasWhife = new PartyRelationshipConstraint(whifeType); familyRelationshipTyp.AddConstraint(famalyCanHasWhife); var familyRelationship = new PartyRelationship(familyRelationshipTyp); familyRelationship.AddRole(husbandRole); var familyRelationshipType2 = new PartyRelationshipType("Family2"); var familyRelationship2 = new PartyRelationship(familyRelationshipType2); familyRelationship2.AddRole(whifeRole); var john = new Person() { Birthdate = new DateTime(1972, 11, 4) }; familyRelationship.Assign(husbandRole, john); var marry = new Person() { Birthdate = new DateTime(1976, 4, 16) }; familyRelationship.Assign(whifeRole, marry); }
public void AddRightRoleIntoRelationship_FailTest() { var husbandType = new PartyRoleType("Husband"); var husbandRole = new PartyRole(husbandType); var whifeType = new PartyRoleType("Whife"); var whifeRole = new PartyRole(whifeType); var familyRelationshipTyp = new PartyRelationshipType("Family"); var famalyCanHasHusband = new PartyRelationshipConstraint(husbandType); familyRelationshipTyp.AddConstraint(famalyCanHasHusband); var famalyCanHasWhife = new PartyRelationshipConstraint(whifeType); familyRelationshipTyp.AddConstraint(famalyCanHasWhife); var familyRelationship = new PartyRelationship(familyRelationshipTyp); familyRelationship.AddRole(husbandRole); familyRelationship.AddRole(whifeRole); var john = new Person() { Birthdate = new DateTime(1972, 11, 4) }; familyRelationship.Assign(husbandRole, john); var marry = new Person() { Birthdate = new DateTime(1976, 4, 16) }; familyRelationship.Assign(whifeRole, marry); Assert.AreEqual(2, familyRelationship.Roles.Count()); Assert.AreEqual(1, familyRelationship.GetRoles(john).Count()); Assert.AreEqual(1, familyRelationship.GetRoles(marry).Count()); }
public ActionResult CreatePartyRelationships(int partyId, Dictionary <string, string> partyRelationshipsDic) { PartyManager partyManager = null; try { partyManager = new PartyManager(); Party party = partyManager.PartyRepository.Get(partyId); List <PartyRelationship> partyRelationships = ConvertDictionaryToPartyRelationships(partyRelationshipsDic); var partyRelationshipManager = new PartyRelationshipTypeManager(); foreach (var partyRelationship in partyRelationships) { Party secondParty = partyManager.PartyRepository.Get(partyRelationship.SecondParty.Id); PartyRelationshipType partyRelationshipType = partyRelationshipManager.PartyRelationshipTypeRepository.Get(partyRelationship.PartyRelationshipType.Id); PartyTypePair partyTypePair = partyRelationshipManager.PartyTypePairRepository.Get(partyRelationship.PartyTypePair.Id); //Min date value is sent from telerik date time element, if it was empty if (partyRelationship.EndDate == DateTime.MinValue) { partyRelationship.EndDate = DateTime.MaxValue; } partyManager.AddPartyRelationship(party, secondParty, partyRelationshipType, partyRelationship.Title, partyRelationship.Description, partyTypePair, partyRelationship.StartDate, partyRelationship.EndDate, partyRelationship.Scope); } partyManager?.Dispose(); //partyManager = new PartyManager(); ////if relationship rules are satisfied, it is not temp // if (string.IsNullOrWhiteSpace(Helpers.Helper.ValidateRelationships(party.Id))) // party.IsTemp = false; //else // party.IsTemp = true; //partyManager.Update(party); return(RedirectToAction("CreateEdit", "party", new { id = partyId, relationTabAsDefault = true })); } finally { partyManager?.Dispose(); } }
public void AddCommunications_SuccessTest() { var customerRoleType = new PartyRoleType("Customer"); var customerRole = new PartyRole(customerRoleType); var customerRelationshipType = new PartyRelationshipType("Customers relationship"); var customerRelationship = new PartyRelationship(customerRelationshipType); customerRelationship.AddRole(customerRole); var vlad = new Person(); customerRelationship.Assign(customerRole, vlad); var ilona = new Person(); customerRelationship.Assign(customerRole, ilona); var customerServiceRepresentativeRoleType = new PartyRoleType("CustomerServiceRepresentative"); var customerServiceRepresentativeRole = new PartyRole(customerServiceRepresentativeRoleType); var communicationRelationshipType = new PartyRelationshipType("Communication relationship"); var communicationRelationship = new Communication(communicationRelationshipType); communicationRelationship.AddRole(customerServiceRepresentativeRole); communicationRelationship.Assign(customerServiceRepresentativeRole, vlad); communicationRelationship.Assign(customerServiceRepresentativeRole, ilona); var customerCommunicationManager = new CustomerCommunicationManager(); var customerServiceCase = new CustomerServiceCase(new CustomerServiceCaseIdentifier(Guid.NewGuid())); customerCommunicationManager.AddCustomerServiceCases(customerServiceCase); var thread1 = new CommunicationThread(); customerServiceCase.AddThread(thread1); var communication = new Communication(communicationRelationshipType); thread1.AddCommunication(communicationRelationship); }
/// <summary> /// A summary of the outcome of the Communication— every Communication should have some outcome (this may be something other /// than an Action, e.g., agreement that an issue has been resolved) /// </summary> //public IEnumerable<Outcome> Outcomes { get; set; } public Communication(PartyRelationshipType type) : base(type) { }
public void ValidateEntityValueConstraine_SuccessTest() { var husbandType = new PartyRoleType("Husband"); var husbendMustBeOlderThen18 = new RuleSet(new Func <object, bool>((x) => { var person = x as Person; if (person.Age > 18) { return(true); } else { return(false); } })); husbandType.AddRule(husbendMustBeOlderThen18); var husbandRole = new PartyRole(husbandType); var whifeType = new PartyRoleType("Whife"); var whifeMustBeOlderThen16 = new RuleSet(new Func <object, bool>((x) => { var person = x as Person; if (person.Age > 16) { return(true); } else { return(false); } })); whifeType.AddRule(whifeMustBeOlderThen16); var whifeRole = new PartyRole(whifeType); var childrenType = new PartyRoleType("Children"); var childrenMustBeYangerThenParents = new RuleSet(new Func <object, bool>((x) => { return(true); })); childrenType.AddRule(childrenMustBeYangerThenParents); var childrenRole = new PartyRole(childrenType); var familyRelationshipTyp = new PartyRelationshipType("Family"); var famalyCanHasHusband = new PartyRelationshipConstraint(husbandType); familyRelationshipTyp.AddConstraint(famalyCanHasHusband); var famalyCanHasWhife = new PartyRelationshipConstraint(whifeType); familyRelationshipTyp.AddConstraint(famalyCanHasWhife); var famalyCanHasChildren = new PartyRelationshipConstraint(childrenType); familyRelationshipTyp.AddConstraint(famalyCanHasChildren); var familyRelationship = new PartyRelationship(familyRelationshipTyp); familyRelationship.AddRole(husbandRole); familyRelationship.AddRole(whifeRole); familyRelationship.AddRole(childrenRole); Assert.AreEqual(3, familyRelationship.Roles.Count()); Assert.AreEqual(1, husbandRole.Type.Rules.Count()); Assert.AreEqual(3, familyRelationship.Roles.Count()); Assert.AreEqual(1, whifeRole.Type.Rules.Count()); Assert.AreEqual(3, familyRelationship.Roles.Count()); Assert.AreEqual(1, childrenRole.Type.Rules.Count()); var john = new Person() { Birthdate = new DateTime(1972, 11, 4) }; familyRelationship.Assign(husbandRole, john); var marry = new Person() { Birthdate = new DateTime(1976, 4, 16) }; familyRelationship.Assign(whifeRole, marry); var gimmy = new Person() { Birthdate = new DateTime(1996, 4, 16) }; familyRelationship.Assign(childrenRole, gimmy); Assert.AreEqual(3, familyRelationship.Roles.Count()); Assert.AreEqual(1, familyRelationship.GetRoles(john).Count()); Assert.AreEqual(1, familyRelationship.GetRoles(marry).Count()); Assert.AreEqual(1, familyRelationship.GetRoles(gimmy).Count()); }
// Methods public PlayerPartyRelationship(byte[] data) : base(data) { this.uid = BitConverter.ToUInt32(data, 1); this.relationship = (PartyRelationshipType) data[5]; }
public PartyRelationship AddPartyRelationship(PartyX firstParty, PartyX secondParty, PartyRelationshipType partyRelationshipType, string title, string description, PartyTypePair partyTypePair, 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; } if (startDate > endDate) { BexisException.Throw(firstParty, "End date should be greater than start date."); } var entity = new PartyRelationship() { Description = description, EndDate = endDate.Value, FirstParty = firstParty, PartyRelationshipType = partyRelationshipType, Scope = scope, SecondParty = secondParty, StartDate = startDate.Value, Title = title }; if (partyTypePair != null) { entity.PartyTypePair = partyTypePair; } using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <PartyX> repoParty = uow.GetRepository <PartyX>(); IRepository <PartyRelationship> repoPR = uow.GetRepository <PartyRelationship>(); IRepository <PartyRelationshipType> repoRelType = uow.GetRepository <PartyRelationshipType>(); partyRelationshipType = repoRelType.Reload(partyRelationshipType); 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)).Where(item => item.EndDate > startDate).Count(); //Check maximun cardinality if (partyRelationshipType.MaxCardinality != -1 && 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.AllowedSource.Id == firstParty.PartyType.Id || item.AllowedSource.Id == secondParty.PartyType.Id); var alowedTarget = partyRelationshipType.AssociatedPairs.FirstOrDefault(item => item.AllowedTarget.Id == firstParty.PartyType.Id || item.AllowedTarget.Id == secondParty.PartyType.Id); if (alowedSource == null || alowedTarget == null) { BexisException.Throw(entity, "There is not relevant 'PartyTypePair' for these types of parties.", BexisException.ExceptionType.Add); } partyRelationshipType.PartyRelationships.Add(entity); repoPR.Put(entity); uow.Commit(); //update the source party to check if relationship rules are satisfied and changed the istemp field Update(entity.FirstParty); } return(entity); }