public void HasGetSet() { var value = new Establishment(); var entity = new InstitutionalAgreementParticipant { Establishment = value }; entity.ShouldNotBeNull(); entity.Establishment.ShouldEqual(value); }
public void HasGetSet() { const int value = 1; var entity = new InstitutionalAgreementParticipant { Id = value }; entity.ShouldNotBeNull(); entity.Id.ShouldEqual(value); }
public void Handle(AddParticipantToAgreementCommand command) { if (command == null) { throw new ArgumentNullException("command"); } var agreement = command.Agreement ?? _entities.Get <InstitutionalAgreement>() .EagerLoad(_entities, new Expression <Func <InstitutionalAgreement, object> >[] { r => r.Participants, }) .By(command.AgreementGuid); var participant = agreement.Participants.SingleOrDefault( x => x.Establishment.EntityId == command.EstablishmentGuid); if (participant != null) { return; } var establishment = _entities.Get <Establishment>() .EagerLoad(_entities, new Expression <Func <Establishment, object> >[] { e => e.Affiliates.Select(a => a.Person.User), e => e.Names.Select(n => n.TranslationToLanguage), e => e.Ancestors.Select(h => h.Ancestor.Affiliates.Select(a => a.Person.User)), e => e.Ancestors.Select(h => h.Ancestor.Names.Select(n => n.TranslationToLanguage)) }) .By(command.EstablishmentGuid); participant = new InstitutionalAgreementParticipant { Establishment = establishment, Agreement = agreement, }; // derive ownership (todo, this should be a separate query) Expression <Func <Affiliation, bool> > principalDefaultAffiliation = affiliation => affiliation.IsDefault && affiliation.Person.User != null && affiliation.Person.User.Name.Equals(command.Principal.Identity.Name, StringComparison.OrdinalIgnoreCase); participant.IsOwner = establishment.Affiliates.AsQueryable().Any(principalDefaultAffiliation) || establishment.Ancestors.Any(n => n.Ancestor.Affiliates.AsQueryable().Any(principalDefaultAffiliation)); _entities.Create(participant); command.IsNewlyAdded = true; }