Ejemplo n.º 1
0
        public ChatWindowViewModel(Conversation conversation, IServiceRegistry serviceRegistry)
            : base(serviceRegistry)
        {
            if (!IsInDesignMode)
            {
                userRepository          = ServiceRegistry.GetService <RepositoryManager>().GetRepository <User>();
                participationRepository = (ParticipationRepository)ServiceRegistry.GetService <RepositoryManager>().GetRepository <Participation>();

                clientService = ServiceRegistry.GetService <IClientService>();

                Participation participation = participationRepository.GetParticipationByUserIdandConversationId(clientService.ClientUserId, conversation.Id);
                groupChat = new GroupChatModel(participation);

                contributionMessageFormatter = new ContributionMessageFormatter(clientService.ClientUserId, userRepository);

                userRepository.EntityAdded   += OnUserChanged;
                userRepository.EntityUpdated += OnUserChanged;

                ServiceRegistry.GetService <RepositoryManager>().GetRepository <Conversation>().EntityUpdated += OnConversationUpdated;

                participationRepository.EntityUpdated += OnParticipationUpdated;

                AddUserCommand = new AddUserToConversationCommand(this);

                groupChat.Conversation = conversation;
                groupChat.Users        = GetUsers();

                UpdateConnectedUsersList();

                groupChat.WindowTitle = userRepository.FindEntityById(clientService.ClientUserId).Username;
                groupChat.Title       = GetChatTitle();
            }
        }
        public void GetAllConversationIdsByUserIdTest()
        {
            var participationRepository = new ParticipationRepository();

            var userId = 3;

            var participation1 = new Participation(1, userId, 1);
            var participation2 = new Participation(2, userId, 2);
            var participation3 = new Participation(3, userId, 3);

            var expectedConversationIds = new List <int>
            {
                participation1.ConversationId,
                participation2.ConversationId,
                participation3.ConversationId
            };

            participationRepository.AddEntity(participation1);
            participationRepository.AddEntity(participation2);
            participationRepository.AddEntity(participation3);

            IEnumerable <int> actualConversationIds = participationRepository.GetAllConversationIdsByUserId(userId);

            Assert.AreEqual(expectedConversationIds, actualConversationIds);
        }
Ejemplo n.º 3
0
        public MainForm()
        {
            InitializeComponent();

            Initializing = true;

            CoureurRepo       = new CoureurRepository();
            CourseRepo        = new CourseRepository();
            ParticipationRepo = new ParticipationRepository();
            UserRepo          = new UtilisateurRepository();

            // import all courses to initialize the listBox
            foreach (Course course in CourseRepo.GetAll())
            {
                listBoxCourses.Items.Add(course.Nom);
                listBoxCourses.SelectedIndex = 0;
            }

            //Filtre pour les participant
            comboBoxFilters.Items.Add("Aucun filtre");
            for (int i = 0; i < 12; i++)
            {
                comboBoxFilters.Items.Add("Age : " + i + "0-" + (i + 1) + "0 ans");
            }
            comboBoxFilters.SelectedIndex = 0;

            Initializing = false;

            ReloadDataGridView();
        }
Ejemplo n.º 4
0
        public void TestParticipation()
        {
            ICoureurRepository       coureurs = new CoureurRepository();
            IParticipationRepository parts    = new ParticipationRepository();
            ICourseRepository        courses  = new CourseRepository();

            parts.DeleteALL();
            coureurs.DeleteALL();
            courses.DeleteALL();

            Coureur coureur1 = new Coureur("coureur1", "1", "XXXXXXXXX", "*****@*****.**", "X", DateTime.Today);

            Course course1 = new Course("", 42);

            Participation part1 = new Participation(coureur1, course1, 0, 42);

            coureur1.Participations.Add(part1);
            course1.Participations.Add(part1);

            coureurs.Save(coureur1);

            List <Coureur> result = coureurs.GetAll();

            Assert.IsTrue(result[0] == coureur1);

            coureurs.DeleteALL();
        }
Ejemplo n.º 5
0
        public OnParticipationChangedHandler(IServiceRegistry serviceRegistry)
            : base(serviceRegistry)
        {
            participationRepository = (ParticipationRepository)RepositoryManager.GetRepository <Participation>();
            conversationRepository  = RepositoryManager.GetRepository <Conversation>();

            participationRepository.EntityAdded   += OnParticipationAdded;
            participationRepository.EntityUpdated += OnParticipationChanged;
        }
        public void AddParticipationTest()
        {
            var participationRepository = new ParticipationRepository();

            var participation = new Participation(1, 1, 1);

            participationRepository.AddEntity(participation);
            Assert.AreEqual(participation, participationRepository.GetAllEntities().First());
        }
Ejemplo n.º 7
0
 public UnitOfWork(ApplicationDbContext context)
 {
     _context          = context;
     Tournaments       = new TournamentRepository(context);
     Participations    = new ParticipationRepository(context);
     Games             = new GameRepository(context);
     Notifications     = new NotificationRepository(context);
     UserNotifications = new UserNotificationRepository(context);
     CreditCards       = new CreditCardRepository(context);
 }
Ejemplo n.º 8
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            IUtilisateurRepository   utilisateurRepository   = new UtilisateurRepository();
            ICoureurRepository       coureurRepository       = new CoureurRepository();
            ICourseRepository        courseRepository        = new CourseRepository();
            IParticipationRepository participationRepository = new ParticipationRepository();

            Application.Run(new MainForm(utilisateurRepository, coureurRepository, courseRepository, participationRepository));
        }
        public void DoesConversationWithUsersExistTest()
        {
            var participationRepository = new ParticipationRepository();
            var participation           = new Participation(1, 1, 1);

            participationRepository.AddEntity(participation);

            Assert.True(participationRepository.DoesConversationWithUsersExist(new List <int> {
                participation.UserId
            }));
        }
Ejemplo n.º 10
0
 public ConversationViewModel(Conversation conversation, IServiceRegistry serviceRegistry)
     : base(serviceRegistry)
 {
     if (!IsInDesignMode)
     {
         this.conversation = conversation;
         var repositoryManager = serviceRegistry.GetService <RepositoryManager>();
         userRepository          = repositoryManager.GetRepository <User>();
         participationRepository = (ParticipationRepository)repositoryManager.GetRepository <Participation>();
     }
 }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            ICoureurRepository coureurRepo = new CoureurRepository();

            /* Vérifie si il récupère bien le bon ID à partir du nom d'un coureur, ici le 1er*/

            Console.Write("Récupération de l'ID de Raphael Bres : ");
            int id = coureurRepo.GetIdCoureurFromName("Bres");

            Console.WriteLine("ID coureur : " + id);


            /* Vérifie si il récupère bien le bon ID à partir du nom d'une course, ici la 1ere*/

            ICourseRepository courseRepo = new CourseRepository();


            Console.Write("Récupération de l'ID de Marathon : ");
            int idCourse = courseRepo.GetIdCourseFromName("Marathon ");

            Console.WriteLine("ID course : " + idCourse);
            Console.ReadKey();

            /* Vérifie si il récupère bien l'ensemble des participations*/


            IParticipationRepository partictipationRepo = new ParticipationRepository();

            Console.Write("Récupération des participations en fonction de l'ID d'une course : ");
            IList <Participation> participationsCourse = new List <Participation>();

            participationsCourse = partictipationRepo.SearchParticipationByCourseId(2);

            foreach (Participation participation in participationsCourse)
            {
                Console.WriteLine(participation.Participant);
            }


            Console.Write("Récupération des participations en fonction de l'ID d'un coureur : ");
            IList <Participation> participationsCoureur = new List <Participation>();

            participationsCoureur = partictipationRepo.SearchParticipationByCoureurId(2);

            foreach (Participation participation in participationsCoureur)
            {
                Console.WriteLine(participation.Participant);
            }
            Console.ReadKey();
        }
Ejemplo n.º 12
0
            public void ReturnsCorrectRepository()
            {
                IEntityRepository userRepository          = new UserRepository();
                IEntityRepository conversationRepository  = new ConversationRepository();
                IEntityRepository participationRepository = new ParticipationRepository();

                var repositoryManager = new RepositoryManager();

                repositoryManager.AddRepository <User>(userRepository);
                repositoryManager.AddRepository <Conversation>(conversationRepository);
                repositoryManager.AddRepository <Participation>(participationRepository);

                IReadOnlyEntityRepository <Conversation> retrievedConversationRepository = repositoryManager.GetRepository <Conversation>();

                Assert.AreEqual(conversationRepository, retrievedConversationRepository);
            }
Ejemplo n.º 13
0
        private static bool CheckUserCanEnterConversation(ParticipationRequest participationRequest,
                                                          ParticipationRepository participationRepository)
        {
            Participation newparticipation = participationRequest.Participation;

            List <Participation> currentParticipantsInConversation = participationRepository.GetParticipationsByConversationId(newparticipation.ConversationId);

            if (currentParticipantsInConversation.Any(participation => participation.UserId == newparticipation.UserId))
            {
                Log.WarnFormat($"User with id {participationRequest.Participation.UserId} cannot be added to conversation {participationRequest.Participation.ConversationId}, user already exists in this conversation.");

                return(false);
            }

            return(true);
        }
Ejemplo n.º 14
0
        public UserListViewModel(IServiceRegistry serviceRegistry)
            : base(serviceRegistry)
        {
            if (!IsInDesignMode)
            {
                userRepository                = serviceRegistry.GetService <RepositoryManager>().GetRepository <User>();
                conversationRepository        = serviceRegistry.GetService <RepositoryManager>().GetRepository <Conversation>();
                participationRepository       = (ParticipationRepository)serviceRegistry.GetService <RepositoryManager>().GetRepository <Participation>();
                clientService                 = serviceRegistry.GetService <IClientService>();
                userRepository.EntityAdded   += OnUserChanged;
                userRepository.EntityUpdated += OnUserChanged;

                conversationRepository.EntityAdded   += OnConversationAdded;
                conversationRepository.EntityUpdated += OnConversationUpdated;

                UpdateConnectedUsers();
            }
        }
        public void AddParticipationsTest()
        {
            var participationRepository = new ParticipationRepository();

            var conversationId = 1;
            IList <Participation> participations = new List <Participation>
            {
                new Participation(1, 1, conversationId),
                new Participation(2, 2, conversationId)
            };

            foreach (Participation participation in participations)
            {
                participationRepository.AddEntity(participation);
            }

            Assert.AreEqual(participations, participationRepository.GetAllEntities());
        }
        public void GetParticipationsByConversationIdTest()
        {
            const int conversationId = 10;

            var participationRepository = new ParticipationRepository();
            var participation1          = new Participation(1, 1, conversationId);
            var participation2          = new Participation(2, 2, conversationId);

            participationRepository.AddEntity(participation1);
            participationRepository.AddEntity(participation2);

            var expectedParticipations = new List <Participation> {
                participation1, participation2
            };

            IEnumerable <Participation> actualParticipations =
                participationRepository.GetParticipationsByConversationId(conversationId);

            Assert.AreEqual(expectedParticipations, actualParticipations);
        }
        public void GetConversationIdByParticipantsIdTest()
        {
            var participationRepository = new ParticipationRepository();
            var conversationId          = 10;
            var participation1          = new Participation(1, 1, conversationId);
            var participation2          = new Participation(2, 2, conversationId);

            participationRepository.AddEntity(participation1);
            participationRepository.AddEntity(participation2);

            var participantIds = new List <int> {
                participation1.UserId, participation2.UserId
            };

            int actualConversationId = participationRepository.GetConversationIdByUserIds(participantIds);

            Assert.AreEqual(conversationId, actualConversationId);
            Assert.AreEqual(0, participationRepository.GetConversationIdByUserIds(new List <int> {
                1, 2, 3
            }));
        }
        private static bool IsConversationValid(ConversationRequest conversationRequest, ParticipationRepository participationRepository)
        {
            if (conversationRequest.UserIds.Count != conversationRequest.UserIds.Distinct().Count())
            {
                Log.Warn("Cannot make a conversation between two users of same id.");
                return(false);
            }

            return(!participationRepository.DoesConversationWithUsersExist(conversationRequest.UserIds));
        }