Exemplo n.º 1
0
        public void AcceptInvitationForExistingUser(ShareInvitation shareInvitation, User user)
        {
            var shareInvitations = _shareInvitationRepository.GetAll()
                                   .Where(x => x.Email == shareInvitation.Email.ToLower() && x.InvitationStatus == InvitationStatusEnum.Invited).ToList();

            user.ServiceDescription_Users = new List <ServiceDescription_User>();

            foreach (var item in shareInvitations)
            {
                //Update the invitation status to Accepted
                item.InvitationStatus = InvitationStatusEnum.Accepted;

                //Update the entity with the new invitation status in the EF context
                _shareInvitationRepository.Update(item);

                //Get the service description according to the service description id in the input parameters
                var serviceDescription = _serviceDescriptionRepository.GetComplete(item.IdServiceDescription);

                //Generate the graph (original) for the service description
                var graphJson = _graphService.CreateGraphData(serviceDescription.Id, serviceDescription.ServiceName, serviceDescription.WsdlInterfaces);

                //Generate the service description for the (invited) shared user
                var serviceDescription_User = new ServiceDescription_User
                {
                    IdServiceDescription = item.IdServiceDescription,
                    IdSharedUser         = user.Id
                };

                //Add the link between the (invited) shared user and the service description
                _serviceDescription_UserRepository.Create(serviceDescription_User);
            }

            //Update the (invited) shared user in the database via the EF context
            _serviceDescription_UserRepository.SaveChanges();

            //Save the updated invitation, with new status, in the database via the EF context
            _shareInvitationRepository.SaveChanges();
        }
        public IHttpActionResult PostShareInvitation(ShareInvitation_ApiRequestCreateModel shareInvitationRequestCreateModel)
        {
            List <int> idOntologiesList = null;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!string.IsNullOrEmpty(shareInvitationRequestCreateModel.IdOntologies))
            {
                idOntologiesList = shareInvitationRequestCreateModel.IdOntologies.Split(',').Select(x => Convert.ToInt32(x)).ToList();
            }

            var idUser = _userIdentityService.Id;

            ShareInvitation shareInvitation;
            ShareInvitation_ApiResponseViewModel shareInvitationResponseModel;
            var shareInvitationResponseModels = new List <ShareInvitation_ApiResponseViewModel>();
            var count = 0;

            var emails = shareInvitationRequestCreateModel.Emails.Split(',');

            List <Ontology> ontologies = null;

            foreach (var email in emails)
            {
                if (idOntologiesList != null && idOntologiesList.Any())
                {
                    ontologies = new List <Ontology>();

                    foreach (var idOntology in idOntologiesList)
                    {
                        var ontology = _ontologyService.Get(idOntology);
                        ontologies.Add(ontology);
                    }
                }

                shareInvitation = new ShareInvitation
                {
                    IdUserInviter        = idUser,
                    Email                = email,
                    IdServiceDescription = shareInvitationRequestCreateModel.IdServiceDescription
                };

                var regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
                var match = regex.Match(email);

                if (match.Success)
                {
                    shareInvitation.ExistingUser = false;
                }
                else
                {
                    shareInvitation.ExistingUser = true;
                }

                count = count + _shareInvitationService.Create(shareInvitation, ontologies);

                shareInvitationResponseModel = _mapper.Map <ShareInvitation_ApiResponseViewModel>(shareInvitation);

                shareInvitationResponseModels.Add(shareInvitationResponseModel);
            }

            return(Ok(shareInvitationResponseModels));
        }
Exemplo n.º 3
0
        public int Update(ShareInvitation shareInvitation)
        {
            _shareInvitationRepository.Update(shareInvitation);

            return(_shareInvitationRepository.SaveChanges());
        }
Exemplo n.º 4
0
        public int Remove(ShareInvitation shareInvitation)
        {
            _shareInvitationRepository.Remove(shareInvitation.Id);

            return(_shareInvitationRepository.SaveChanges());
        }
Exemplo n.º 5
0
        //TODO: Create a new invitation when the user has been revoked or if they rejected the invitation, to keep the history.
        //Today it's using the same invitation but changing the status.
        public int Create(ShareInvitation shareInvitation)
        {
            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();
                        }
                        else
                        {
                            if (alreadyExistingShareInvitation.InvitationStatus == InvitationStatusEnum.Accepted)
                            {
                                return(count);
                            }

                            if (alreadyExistingShareInvitation.InvitationStatus == InvitationStatusEnum.Revoked)
                            {
                                alreadyExistingShareInvitation.InvitationStatus = InvitationStatusEnum.Invited;

                                _shareInvitationRepository.Update(alreadyExistingShareInvitation);

                                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();
                }
                else
                {
                    if (alreadyExistingShareInvitation.InvitationStatus == InvitationStatusEnum.Accepted)
                    {
                        return(count);
                    }

                    invitationSecurity = alreadyExistingShareInvitation.InvitationSecurity;
                    email = alreadyExistingShareInvitation.Email;
                }

                _eventDispatcher.Dispatch(new SendInvitationEmailEvent(email, invitationSecurity));
            }

            return(count);
        }
Exemplo n.º 6
0
        public void AcceptInvitationForNewUser(ShareInvitation shareInvitation, User newUser)
        {
            var shareInvitations = _shareInvitationRepository.GetAll()
                                   .Where(x => x.Email == shareInvitation.Email.ToLower() && x.InvitationStatus == InvitationStatusEnum.Invited).ToList();

            newUser.ServiceDescription_Users = new List <ServiceDescription_User>();

            foreach (var invitation in shareInvitations)
            {
                //Update the invitation status to Accepted
                invitation.InvitationStatus = InvitationStatusEnum.Accepted;

                //Update the entity with the new invitation status in the EF context
                _shareInvitationRepository.Update(invitation);

                var idServiceDescription = invitation.IdServiceDescription;

                //Generate the service description for the (invited) shared user
                var serviceDescription_User = new ServiceDescription_User
                {
                    IdServiceDescription = idServiceDescription
                };

                //Add the link between the (invited) shared user and the service description
                newUser.ServiceDescription_Users.Add(serviceDescription_User);

                var ontologiesUsedByServiceDescription = _serviceDescription_OntologyRepository.GetAll().Where(x => x.IdServiceDescription == idServiceDescription);
                var ontologiesSharedByOpenedInProject  = _shareInvitation_OntologyRepository.GetAll().Where(x => x.IdShareInvitation == invitation.Id);
                newUser.Ontology_Users = new List <Ontology_User>();

                foreach (var idOntology in ontologiesUsedByServiceDescription.Select(x => x.IdOntology).ToList())
                {
                    if (!newUser.Ontology_Users.Any(x => x.IdOntology == idOntology))
                    {
                        newUser.Ontology_Users.Add(new Ontology_User {
                            IdOntology = idOntology
                        });
                    }
                }

                foreach (var idOntology in ontologiesSharedByOpenedInProject.Select(x => x.IdOntology).ToList())
                {
                    if (!newUser.Ontology_Users.Any(x => x.IdOntology == idOntology))
                    {
                        newUser.Ontology_Users.Add(new Ontology_User {
                            IdOntology = idOntology
                        });
                    }
                }
            }

            //Hash the password for the invited user
            newUser.Password = HashHelper.GetHash(newUser.Password);

            //Create the the (invited) shared user in the EF context
            _userRepository.Create(newUser);

            //Save the (invited) shared user in the database via the EF context
            _userRepository.SaveChanges();

            //Save the updated invitation, with new status, in the database via the EF context
            _shareInvitationRepository.SaveChanges();
        }