コード例 #1
0
        private async void buttonSignIn_Click(object sender, EventArgs e)
        {
            try
            {
                labelError.Text = "";
                var userlogin = await HttpRequests.UserLogin(textBoxUser.Text, textBoxPassword.Text);

                this.Hide();

                if (userlogin is Admin)
                {
                    //On lance la form admin
                    Form22 adminform = new Form22(userlogin);
                    this.Close();
                    try
                    {
                        adminform.ShowDialog();
                    }
                    catch
                    {
                    }
                }
                else if (userlogin is Teacher)
                {
                    Form23 studentform = new Form23(userlogin);
                    this.Close();
                    try
                    {
                        studentform.ShowDialog();
                    }
                    catch { }
                }
                else
                {
                    //On lance la form élève
                    Form21 studentform = new Form21(userlogin);
                    this.Close();
                    try
                    {
                        studentform.ShowDialog();
                    }
                    catch { }
                }
            }
            catch
            {
                labelError.Text = "Identifiant ou mot de passe incorrect.";
                textBoxUser.Clear();
                textBoxPassword.Clear();
            }
        }
コード例 #2
0
ファイル: Form3.cs プロジェクト: gael42r/CompetencesApp
 private void buttonRemoveProof_Click(object sender, EventArgs e)
 {
     if (listBoxProof.SelectedItem != null)
     {
         foreach (Document docu in this.usercompetence.doclist)
         {
             if (docu.link == listBoxProof.SelectedItem.ToString())
             {
                 HttpRequests.DeleteDocument(this.usercompetence._id, docu._id);
                 listBoxProof.Items.Remove(listBoxProof.SelectedItem);
                 return;
             }
         }
     }
 }
コード例 #3
0
        private async void buttonRemove_Click(object sender, EventArgs e)
        {
            var selectedRessource = selectedCompetence.ressources[listBoxResources.SelectedIndex];

            if (listBoxResources.SelectedItem != null)
            {
                bool success = await HttpRequests.DeleteRessource(this.selectedCompetence._id, selectedRessource._id);

                if (success)
                {
                    this.selectedCompetence.ressources.RemoveAt(listBoxResources.SelectedIndex);
                    listBoxResources.Items.RemoveAt(listBoxResources.SelectedIndex);
                    richTextBoxDescription.Clear();
                }
            }
        }
コード例 #4
0
        private async void buttonValider_Click(object sender, EventArgs e)
        {
            var usercompetenceSelected = this.usercompetences[listBoxStudent.SelectedIndex];

            if (usercompetenceSelected != null)
            {
                usercompetenceSelected.doclist = await HttpRequests.GetDocumentsByUserCompetenceId(usercompetenceSelected._id);


                this.selectedCompetence.ressources = await HttpRequests.GetResourceByCompetenceId(this.selectedCompetence._id);



                Form3 formcompetence = new Form3(this.selectedCompetence, usercompetenceSelected, this.user);
                formcompetence.ShowDialog();
            }
        }
コード例 #5
0
        private async void comboBoxPromotion_SelectedIndexChanged(object sender, EventArgs e)
        {
            listBoxCompetencesBlocks.Items.Clear();
            listBoxCompetences.Items.Clear();
            try
            {
                var promo    = this.studentuser.promos.Find(item => item.name == comboBoxPromotion.Text);
                var response = await HttpRequests.GetPromotionsCompetenceBlocksById(promo._id);

                competenceBlocks = response;
                foreach (CompetenceBlock competenceblock in response)
                {
                    listBoxCompetencesBlocks.Items.Add(competenceblock.name);
                }
            }
            catch
            {
            }
        }
コード例 #6
0
        //public static async Task<User> UserLogin(string username, string password)
        //{
        //    List<string> list = new List<string>();
        //    list.Add(username);
        //    list.Add(password);
        //    HttpResponseMessage response = await client.PostAsJsonAsync(
        //        "http://" + host + "/login", list);
        //    response.EnsureSuccessStatusCode();
        //    Console.WriteLine(response.Content);
        //    var user = await response.Content.ReadAsAsync<User>();
        //    var userpromo = await HttpRequests.GetUsersPromotionById(user._id);
        //    var usercompetence = await HttpRequests.GetUsersCompetencesById(user._id);
        //    user.promos = userpromo;
        //    user.comps = usercompetence;

        //    return user;
        //}

        //public static async Task<User> UserLogin(string username, string password)
        //{
        //    List<string> list = new List<string>();
        //    list.Add(username);
        //    list.Add(password);

        //    HttpResponseMessage response = await client.PostAsJsonAsync("http://" + host + "/login", list);
        //    response.EnsureSuccessStatusCode();

        //    //Console.WriteLine(response.Content);

        //    var user = await response.Content.ReadAsAsync<User>();

        //    if (!user.isAdmin)
        //    {
        //        var userpromoslist = await HttpRequests.GetUsersPromotionById(user._id);
        //        user.promos = userpromoslist;
        //    }
        //    else
        //    {
        //        var userpromoslist = await HttpRequests.GetPromotions();
        //        user.promos = userpromoslist;
        //    }

        //    var usercompetenceslist = await HttpRequests.GetUsersCompetencesById(user._id);



        //    user.comps = usercompetenceslist;
        //    return user;
        //}

        public static async Task <dynamic> UserLogin(string username, string password)
        {
            string payload = JsonConvert.SerializeObject(new
            {
                username = username,
                password = password
            });
            var request       = new HttpRequestMessage(HttpMethod.Post, "http://" + host + "/login");
            var stringContent = new StringContent(payload, Encoding.UTF8, "application/json");

            request.Content = stringContent;


            var response = await client
                           .SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

            response.EnsureSuccessStatusCode(); // Ici il faut que tu check try catch, si ça fail c'est que le user s'est trompé de password ou serv off, faudra check comment on peut afficher ça

            // 404


            var userJObject = await response.Content.ReadAsAsync <JObject>();

            //Console.WriteLine(((bool)user.GetValue("isAdmin"))?"VRAI":"FAUX") ;

            var isAdmin    = false;
            var isTeacher  = false;
            var competence = new List <string>();

            try
            {
                isAdmin   = (bool)userJObject.GetValue("isAdmin");
                isTeacher = (bool)userJObject.GetValue("isTeacher");
            }
            catch (Exception e)
            {
            }


            if (isAdmin)
            {
                //var userpromoslist = await HttpRequests.GetPromotions();
                //user.promos = userpromoslist;

                var user = userJObject.ToObject <Admin>();
                user.competences = await GetCompetences();

                user.competenceblocks = await GetCompetenceBlocks();

                user.users = await GetUsers();

                user.promos = await GetPromotions();

                return(user);
            }
            else if (isTeacher)
            {
                var user = userJObject.ToObject <Teacher>();
                user.teacherCompetence = await GetAllTeacherCompetenceById(user._id);


                return(user);
            }
            else
            {
                var user = userJObject.ToObject <User>();

                var userpromoslist = await HttpRequests.GetUsersPromotionById(user._id);

                user.promos = userpromoslist;
                var usercompetenceslist = await HttpRequests.GetUsersCompetencesById(user._id);

                user.comps = usercompetenceslist;

                return(user);
            }
        }
コード例 #7
0
        private async void saveButton_Click(object sender, EventArgs e)
        {
            int selectedIndex = -1;

            switch (this.currentWindow)
            {
            case 0:
                selectedIndex = comboBoxPromotion.SelectedIndex;
                if (selectedIndex == -1)
                {
                    return;
                }
                Promotion selectedPromotion = this.adminuser.promos[selectedIndex];
                if (selectedPromotion == null)
                {
                    return;
                }
                await HttpRequests.PatchPromotionUsers(selectedPromotion._id, usersInPromotion);

                List <User> promoUsers = new List <User>();
                usersInPromotion.ForEach((user) => promoUsers.Add(user));
                this.adminuser.promos[selectedIndex].users = promoUsers;
                break;

            case 1:
                selectedIndex = comboBoxUsers.SelectedIndex;
                if (selectedIndex == -1)
                {
                    return;
                }
                User selectedUser = this.adminuser.users[selectedIndex];
                if (selectedUser == null)
                {
                    return;
                }
                if (!(selectedUser is Teacher))
                {
                    return;
                }
                Teacher selectedTeacher = selectedUser as Teacher;
                await HttpRequests.PatchTeacherCompetences(selectedUser._id, this.competenceOwnedByTeacher);

                List <Competence> teacherCompetences = new List <Competence>();
                competenceOwnedByTeacher.ForEach((competence) => teacherCompetences.Add(competence));
                selectedTeacher.teacherCompetence = teacherCompetences;
                break;

            case 2:
                selectedIndex = comboBoxCompetenceBlock.SelectedIndex;
                if (selectedIndex == -1)
                {
                    return;
                }
                CompetenceBlock selectedBlock = this.adminuser.competenceblocks[selectedIndex];
                if (selectedBlock == null)
                {
                    return;
                }
                await HttpRequests.PatchCompetenceBlockCompetence(selectedBlock._id, this.competenceInBlock);

                List <Competence> competences = new List <Competence>();
                competenceInBlock.ForEach((competence) => competences.Add(competence));
                this.adminuser.competenceblocks[selectedIndex].competence = competences;
                break;

            case 4:
                selectedIndex = comboBoxPromotion.SelectedIndex;
                if (selectedIndex == -1)
                {
                    return;
                }
                Promotion selectedPromotion1 = this.adminuser.promos[selectedIndex];
                if (selectedPromotion1 == null)
                {
                    return;
                }
                await HttpRequests.PatchPromotionCompetenceBlocks(selectedPromotion1._id, blockInPromotion);

                List <string> competenceBlocks = new List <string>();
                blockInPromotion.ForEach((competenceblock) => competenceBlocks.Add(competenceblock._id));
                selectedPromotion1.competenceBlock = competenceBlocks;
                break;

            default:

                break;
            }
        }
コード例 #8
0
        private async void deleteButton_Click(object sender, EventArgs e)
        {
            int  selectedIndex = -1;
            bool success       = false;

            switch (this.currentWindow)
            {
            case 0:
            case 4:
                selectedIndex = comboBoxPromotion.SelectedIndex;
                if (selectedIndex == -1)
                {
                    return;
                }
                var selectedPromotion = this.adminuser.promos[selectedIndex];
                if (selectedPromotion == null)
                {
                    return;
                }
                success = await HttpRequests.DeletePromotion(selectedPromotion._id);

                if (success)
                {
                    this.adminuser.promos.RemoveAt(selectedIndex);
                    comboBoxPromotion.Items.RemoveAt(selectedIndex);
                }
                // Delete promotion
                break;

            case 1:
                selectedIndex = comboBoxUsers.SelectedIndex;
                if (selectedIndex == -1)
                {
                    return;
                }
                var selectedUser = this.adminuser.users[selectedIndex];
                if (selectedUser == null)
                {
                    return;
                }
                success = await HttpRequests.DeleteUser(selectedUser._id);

                if (success)
                {
                    this.adminuser.users.RemoveAt(selectedIndex);
                    comboBoxUsers.Items.RemoveAt(selectedIndex);
                }
                // Delete User
                break;

            case 2:
                selectedIndex = comboBoxCompetenceBlock.SelectedIndex;
                if (selectedIndex == -1)
                {
                    return;
                }
                var selectedCompetenceBlock = this.adminuser.competenceblocks[selectedIndex];
                if (selectedCompetenceBlock == null)
                {
                    return;
                }
                success = await HttpRequests.DeleteCompetenceBlock(selectedCompetenceBlock._id);

                if (success)
                {
                    this.adminuser.competenceblocks.RemoveAt(selectedIndex);
                    comboBoxCompetenceBlock.Items.RemoveAt(selectedIndex);
                }
                // Delete CompetenceBlock
                break;

            case 3:
                selectedIndex = comboBoxCompetences.SelectedIndex;
                if (selectedIndex == -1)
                {
                    return;
                }
                var selectedCompetence = this.adminuser.competences[selectedIndex];
                if (selectedCompetence == null)
                {
                    return;
                }
                success = await HttpRequests.DeleteCompetence(selectedCompetence._id);

                if (success)
                {
                    this.adminuser.competences.RemoveAt(selectedIndex);
                    comboBoxCompetences.Items.RemoveAt(selectedIndex);
                }
                // Delete Competence
                break;

            default:
                break;
            }
        }