Example #1
0
        private async Task SyncUserGroups()
        {
            var allGroups = await GroupeAPI.GetAllGroups();

            if (allGroups == null)
            {
                return;
            }

            var activeClientGroups = new List <Groupe>();

            foreach (var group in allGroups)
            {
                var members = await InvitationAPI.GetGroupMembers(group.id_groupe);

                if (ActiveClient == null ||
                    members.Find(client => client.id_client == ActiveClient.id_client) == null &&
                    @group.admin != ActiveClient.id_client)
                {
                    continue;
                }

                activeClientGroups.Add(group);
            }

            GroupesListView?.Invoke((MethodInvoker) delegate
            {
                GroupesListView.Items.Clear();
                foreach (var group in activeClientGroups)
                {
                    string[] rows = { group.id_groupe.ToString(), group.nom };
                    GroupesListView.Items.Add(new ListViewItem(rows));
                }
            });
        }
 protected ApplicationPanel(MainForm parent)
 {
     _parent       = parent;
     ClientAPI     = new ClientAPI();
     FichierAPI    = new FichierAPI();
     GroupeAPI     = new GroupeAPI();
     InvitationAPI = new InvitationAPI();
 }
Example #3
0
        private async void Supprimer_Click(object sender, System.EventArgs e)
        {
            if (ActiveGroup.admin != ActiveClient.id_client)
            {
                return;
            }

            await GroupeAPI.DeleteGroupAsync(ActiveGroup);

            ChangeActivePanel(MainForm.Panel.Home);
        }
Example #4
0
        private async void VoirGroupeButton_Click(object sender, System.EventArgs e)
        {
            if (GroupesListView.SelectedItems.Count == 1)
            {
                var selectedGroup = int.Parse(GroupesListView.SelectedItems[0].Text);
                ActiveGroup = await GroupeAPI.GetGroupById(selectedGroup);

                ChangeActivePanel(MainForm.Panel.Groupe);
            }
            else
            {
                DialogResult res = MessageBox.Show("Veuillez sélectionner un groupe.", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #5
0
        private async void CreerButton_ClickAsync(object sender, System.EventArgs e)
        {
            string groupName = Prompt.ShowDialog("Nom du groupe:", "");

            if (groupName != "")
            {
                int activeClientId = ActiveClient.id_client;
                await GroupeAPI.CreateGroup(groupName, activeClientId);

                // TODO : open group panel with group id??
            }
            else
            {
                DialogResult res = MessageBox.Show("Veuillez saisir un nom pour le groupe.", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #6
0
        private async void PromoteAdmin_Click(object sender, System.EventArgs e)
        {
            if (ActiveGroup.admin != ActiveClient.id_client)
            {
                return;
            }

            if (!(MemberListBox.SelectedItem is Client selectedClient))
            {
                return;
            }

            ActiveGroup.admin = selectedClient.id_client;
            await GroupeAPI.ModifyGroupAsync(ActiveGroup);

            Synchronize();
        }
Example #7
0
        public MainForm()
        {
            InitializeComponent();

            _homePanel          = new HomePanel(this);
            _groupPanel         = new GroupPanel(this);
            _connectionPanel    = new ConnectionPanel(this);
            _notificationsPanel = new NotificationsPanel(this);
            CurrentPanel        = Panel.Connection;
            UDPClient.Connect("localhost", UDP_PORT);
            FichierAPI    = new FichierAPI();
            GroupeAPI     = new GroupeAPI();
            InvitationAPI = new InvitationAPI();

            LAST_TIME_SYNC_FILES   = DateTime.Now;
            LAST_TIME_SYNC_CLIENTS = DateTime.Now;
            LAST_TIME_SYNC_GROUPS  = DateTime.Now;
            LAST_TIME_SYNC_NOTIFS  = DateTime.Now;

            Task.Run(PeriodicSynchronization);
        }
        private void GetInvitations()
        {
            var invites = Task.Run(() => InvitationAPI.GetInvitationsByClient(ActiveClient.id_client)).Result;

            if (invites == null)
            {
                DialogResult res = MessageBox.Show("La recherche des notifications a échoué.", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                NotificationsListView.Invoke((MethodInvoker) delegate
                {
                    NotificationsListView.Items.Clear();
                    foreach (Invitation invite in invites)
                    {
                        var group = Task.Run(() => GroupeAPI.GetGroupById(invite.id_groupe_fk)).Result;
                        if (group == null)
                        {
                            DialogResult res = MessageBox.Show("La recherche du groupe a échoué.", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        else
                        {
                            NotificationsListView.Invoke((MethodInvoker) delegate
                            {
                                string[] rows     = { invite.id_invitation.ToString(), group.nom };
                                ListViewItem item = new ListViewItem(rows);
                                item.Name         = invite.id_invitation.ToString();
                                if (!NotificationsListView.Items.ContainsKey(invite.id_invitation.ToString()))
                                {
                                    NotificationsListView.Items.Add(item);
                                }
                            });
                        }
                    }
                });
            }
        }