Esempio n. 1
0
        private void removeUserPromotionButton_Click(object sender, EventArgs e)
        {
            int selectedIndex = listBoxPromotionUsers.SelectedIndex;

            if (selectedIndex == -1)
            {
                return;
            }
            switch (this.currentWindow)
            {
            case 0:
                User selectedUser = usersInPromotion[selectedIndex];
                if (selectedUser == null)
                {
                    return;
                }
                usersInPromotion.RemoveAt(selectedIndex);
                usersNotInPromotion.Add(selectedUser);

                listBoxNoPromotionUsers.Items.Add(selectedUser.surname + " " + selectedUser.firstName);
                break;

            case 1:
                Competence selected = competenceOwnedByTeacher[selectedIndex];
                if (selected == null)
                {
                    return;
                }
                competenceOwnedByTeacher.RemoveAt(selectedIndex);
                competenceNotOwnedByTeacher.Add(selected);
                listBoxNoPromotionUsers.Items.Add(selected.name);
                break;

            case 2:
                Competence selectedCompetence = competenceInBlock[selectedIndex];
                if (selectedCompetence == null)
                {
                    return;
                }
                competenceInBlock.RemoveAt(selectedIndex);
                competenceNotInBlock.Add(selectedCompetence);
                listBoxNoPromotionUsers.Items.Add(selectedCompetence.name);
                break;

            case 4:
                CompetenceBlock selectedBlock = blockInPromotion[selectedIndex];
                if (selectedBlock == null)
                {
                    return;
                }
                blockInPromotion.RemoveAt(selectedIndex);
                blockNotInPromotion.Add(selectedBlock);
                listBoxNoPromotionUsers.Items.Add(selectedBlock.name);
                break;

            default:
                return;
            }
            listBoxPromotionUsers.Items.RemoveAt(selectedIndex);
        }
Esempio n. 2
0
        private void comboBoxCompetenceBlock_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxCompetenceBlock.SelectedIndex == -1)
            {
                return;
            }
            int             selectedIndex           = comboBoxCompetenceBlock.SelectedIndex;
            CompetenceBlock selectedCompetenceBlock = this.adminuser.competenceblocks[selectedIndex];

            if (selectedCompetenceBlock == null)
            {
                return;
            }

            List <Competence> competenceNotInBlock = new List <Competence>();

            this.adminuser.competences.ForEach((competence) =>
            {
                if (!BlockContainsCompetence(selectedCompetenceBlock, competence._id))
                {
                    competenceNotInBlock.Add(competence);
                }
            });
            listBoxNoPromotionUsers.Items.Clear();
            listBoxPromotionUsers.Items.Clear();

            competenceNotInBlock.ForEach((competence) => listBoxNoPromotionUsers.Items.Add(competence.name));
            selectedCompetenceBlock.competence.ForEach((competence) => listBoxPromotionUsers.Items.Add(competence.name));
            this.competenceNotInBlock = competenceNotInBlock;
            List <Competence> competenceInBlock = new List <Competence>();

            selectedCompetenceBlock.competence.ForEach((competence) => competenceInBlock.Add(competence));
            this.competenceInBlock = competenceInBlock;
        }
Esempio n. 3
0
        private bool BlockContainsCompetence(CompetenceBlock competenceBlock, string competenceId)
        {
            bool contains = false;

            if (competenceBlock.competence == null)
            {
                return(false);
            }
            competenceBlock.competence.ForEach((competence) =>
            {
                if (competence._id == competenceId)
                {
                    contains = true;
                }
            });
            return(contains);
        }
Esempio n. 4
0
        public static async Task <CompetenceBlock> PatchCompetenceBlockCompetence(string blockId, List <Competence> competences)
        {
            string payload;


            List <string> competenceId = new List <string>();

            competences.ForEach((competence) => competenceId.Add(competence._id));

            payload = JsonConvert.SerializeObject(new
            {
                competence = competenceId,
            });


            var request       = new HttpRequestMessage(HttpMethod.Put, "http://" + host + "/competenceblocks/" + blockId + "/competences");
            var stringContent = new StringContent(payload, Encoding.UTF8, "application/json");

            request.Content = stringContent;


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

            response.EnsureSuccessStatusCode();
            CompetenceBlock block = new CompetenceBlock();

            try
            {
                block = await response.Content.ReadAsAsync <CompetenceBlock>();
            }
            catch
            {
                block.competence = await GetCompetenceBlocksCompetencesById(block._id);
            }
            return(block);
        }
Esempio n. 5
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;
            }
        }