public int Create(ServiceDescription_User serviceDescription_User) { _serviceDescription_UserRepository.Create(serviceDescription_User); var count = _serviceDescription_UserRepository.SaveChanges(); var user = _userRepository.Get(serviceDescription_User.IdSharedUser); var invitationSecurity = Guid.NewGuid(); _eventDispatcher.Dispatch(new SendInvitationEmailEvent(user.Email, invitationSecurity)); return(count); }
public User Get(int id, bool @readonly = true) { return(_userRepository.Get(id, @readonly)); }
public int Create(ShareInvitation shareInvitation, List <Ontology> ontologies) { var count = 0; string email = null; ShareInvitation alreadyExistingShareInvitation; var invitationSecurity = Guid.NewGuid(); shareInvitation.Email = shareInvitation.Email.Trim().ToLower(); shareInvitation.InvitationSecurity = invitationSecurity; if (shareInvitation.ExistingUser) { if (int.TryParse(shareInvitation.Email, out int idExistingUser)) { var user = _userRepository.Get(idExistingUser); if (user != null) { alreadyExistingShareInvitation = _shareInvitationRepository.GetAll(@readonly: false) .FirstOrDefault(x => x.Email == user.Email && x.IdServiceDescription == shareInvitation.IdServiceDescription); if (alreadyExistingShareInvitation == null) { email = user.Email; shareInvitation.Email = email; _shareInvitationRepository.Create(shareInvitation); count = _shareInvitationRepository.SaveChanges(); if (shareInvitation.ShareInvitation_Ontologies == null) { shareInvitation.ShareInvitation_Ontologies = new List <ShareInvitation_Ontology>(); } if (ontologies != null && ontologies.Any()) { foreach (var ontology in ontologies) { shareInvitation.ShareInvitation_Ontologies.Add(new ShareInvitation_Ontology { IdOntology = ontology.Id, IdShareInvitation = shareInvitation.Id }); } count = _shareInvitationRepository.SaveChanges(); } } else { if (alreadyExistingShareInvitation.InvitationStatus == InvitationStatusEnum.Accepted) { return(count); } if (alreadyExistingShareInvitation.InvitationStatus == InvitationStatusEnum.Revoked) { alreadyExistingShareInvitation.InvitationStatus = InvitationStatusEnum.Invited; _shareInvitationRepository.Update(alreadyExistingShareInvitation); count = _shareInvitationRepository.SaveChanges(); if (shareInvitation.ShareInvitation_Ontologies == null) { shareInvitation.ShareInvitation_Ontologies = new List <ShareInvitation_Ontology>(); } if (ontologies != null && ontologies.Any()) { foreach (var ontology in ontologies) { shareInvitation.ShareInvitation_Ontologies.Add(new ShareInvitation_Ontology { IdOntology = ontology.Id, IdShareInvitation = shareInvitation.Id }); } count = _shareInvitationRepository.SaveChanges(); } } invitationSecurity = alreadyExistingShareInvitation.InvitationSecurity; email = alreadyExistingShareInvitation.Email; } _eventDispatcher.Dispatch(new SendInvitationEmailEvent(email, invitationSecurity)); } } } else { alreadyExistingShareInvitation = _shareInvitationRepository.GetAll(@readonly: false) .FirstOrDefault(x => x.Email == shareInvitation.Email && x.IdServiceDescription == shareInvitation.IdServiceDescription); if (alreadyExistingShareInvitation == null) { email = shareInvitation.Email; _shareInvitationRepository.Create(shareInvitation); count = _shareInvitationRepository.SaveChanges(); if (shareInvitation.ShareInvitation_Ontologies == null) { shareInvitation.ShareInvitation_Ontologies = new List <ShareInvitation_Ontology>(); } if (ontologies != null && ontologies.Any()) { foreach (var ontology in ontologies) { shareInvitation.ShareInvitation_Ontologies.Add(new ShareInvitation_Ontology { IdOntology = ontology.Id, IdShareInvitation = shareInvitation.Id }); } count = _shareInvitationRepository.SaveChanges(); } } else { if (alreadyExistingShareInvitation.InvitationStatus == InvitationStatusEnum.Accepted) { return(count); } invitationSecurity = alreadyExistingShareInvitation.InvitationSecurity; email = alreadyExistingShareInvitation.Email; } _eventDispatcher.Dispatch(new SendInvitationEmailEvent(email, invitationSecurity)); } return(count); }