private void boutonSupprimer_Click(object sender, RoutedEventArgs e)
        {
            if (selectedSociete != null)
            {
                Offre o = App.dbContext.Offres.FirstOrDefault(oTemp => oTemp.Annonceur.Identifiant == selectedSociete.Identifiant);

                if (o == null)
                {
                    try
                    {
                        App.dbContext.Societes.Remove(selectedSociete);
                        App.dbContext.SaveChanges();

                        Societes.Remove(selectedSociete);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
                else
                {
                    MessageBox.Show("Impossible de supprimer l'annonceur car il est rataché à une ou plusieurs offre(s)", "Erreur de suppression", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
        public societeControl()
        {
            this.DataContext = this;

            InitializeComponent();

            App.dbContext.Societes.ToList().ForEach(
                s => Societes.Add(s)
                );
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            Filieres           filGtr    = _dataContext.Filieres.Where(s => s.NomFiliere.Equals("Génie télécommunication et reseaux")).FirstOrDefault();
            List <GroupsModel> grpsModel = new List <GroupsModel>();


            if (filGtr != null)
            {
                List <Groupes> grps = _dataContext.Groupes.Where(g => g.Students.FirstOrDefault().IdFil == filGtr.IdFiliere).ToList();



                GroupsModel testModel;
                foreach (Groupes grp in grps)
                {
                    List <AspNetUsers> student = (from s in _dataContext.Students
                                                  join u in _dataContext.AspNetUsers
                                                  on s.IdUser equals u.Id
                                                  where (s.GroupId == grp.Id && s.IdFil == filGtr.IdFiliere)

                                                  select u).ToList();

                    testModel          = new GroupsModel();
                    testModel.id       = grp.Id;
                    testModel.sujet    = grp.Sujet;
                    testModel.students = student;
                    Societes societe = _dataContext.Societes.Where(s => grp.IdSociete == s.Id).FirstOrDefault();
                    if (societe != null)
                    {
                        testModel.ville = societe.Ville;
                    }
                    Professors professor = _dataContext.Professors.Where(s => grp.Idprof == s.Id).FirstOrDefault();
                    if (professor != null)
                    {
                        testModel.encadrant = _dataContext.AspNetUsers.Where(s => s.Id == professor.IdUser).FirstOrDefault();
                    }
                    grpsModel.Add(testModel);
                }
            }
            return(View(grpsModel));
        }
예제 #4
0
        public IActionResult addNewGroup(string[] stdid, string sujet, string sujetDesc, string nomSociete, string tele, string ville, string nomEnc, string mailEnc, string teleEnc)
        {
            Societes societe = new Societes
            {
                Nom           = nomSociete,
                Tele          = tele,
                Ville         = ville,
                NomEncadrant  = nomEnc,
                MailEncadrant = mailEnc,
                TeleEncadrant = teleEnc
            };

            db.Societes.Add(societe);
            db.SaveChanges();
            Groupes groupes = new Groupes();

            groupes.Sujet           = sujet;
            groupes.DesciptionSujet = sujetDesc;
            groupes.IdSociete       = societe.Id;
            db.Groupes.Add(groupes);
            db.SaveChanges();

            student.GroupId = groupes.Id;
            List <Students> students = db.Students.Where(std => std.IdFil.Equals(student.IdFil) && std.IdNiv.Equals(student.IdNiv) && std.GroupId == null).ToList();

            foreach (Students std in students)
            {
                string stringid = "std" + std.Id;
                if (Array.Exists(stdid, elt => elt.Equals(stringid)))
                {
                    Students etudiant = db.Students.Find(std.Id);
                    etudiant.GroupId = groupes.Id;
                }
            }
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        private void boutonEnregistrer_Click(object sender, RoutedEventArgs e)
        {
            if (selectedSociete != null)
            {
                Boolean isOk = true;
                int     num;
                Adresse adresse = selectedSociete.Adresse;
                this.UpdateSources();
                if (VerificationFormulaire())
                {
                    if (int.TryParse(this.textBoxAdresseNumero.Text, out num))
                    {
                        adresse.Numero = num;
                    }
                    else
                    {
                        isOk = false;
                    }

                    if (isOk == true)
                    {
                        if (selectedSociete is Annonceur)
                        {
                            if (radioAnnonceur.IsChecked == true)
                            {
                                try
                                {
                                    App.dbContext.SaveChangesAsync();
                                    MessageBox.Show("Annonceur enregistré", "Validation", MessageBoxButton.OK, MessageBoxImage.Information);
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                            }
                            else
                            {
                                try
                                {
                                    Diffuseur d = new Diffuseur();
                                    d.RaisonSociale = this.textBoxRaisonSociale.Text;
                                    d.Telephone     = this.textBoxTelephone.Text;
                                    d.Email         = this.textBoxEmail.Text;
                                    d.NumeroSiret   = this.textBoxSiret.Text;
                                    d.Adresse       = adresse;

                                    App.dbContext.Societes.Remove(selectedSociete);
                                    Societes.Remove(selectedSociete);

                                    App.dbContext.Societes.Add(d);
                                    App.dbContext.SaveChangesAsync();
                                    MessageBox.Show("Diffuseur enregistré", "Validation", MessageBoxButton.OK, MessageBoxImage.Information);

                                    Societes.Add(d);
                                    listeSociete.SelectedItem = d;
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                            }
                        }
                        else
                        {
                            if (radioDiffuseur.IsChecked == true)
                            {
                                try
                                {
                                    App.dbContext.SaveChangesAsync();
                                    MessageBox.Show("Diffuseur enregistré", "Validation", MessageBoxButton.OK, MessageBoxImage.Information);
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                            }
                            else
                            {
                                try
                                {
                                    Annonceur a = new Annonceur();
                                    a.RaisonSociale = this.textBoxRaisonSociale.Text;
                                    a.Telephone     = this.textBoxTelephone.Text;
                                    a.Email         = this.textBoxEmail.Text;
                                    a.NumeroSiret   = this.textBoxSiret.Text;
                                    a.Adresse       = adresse;

                                    App.dbContext.Societes.Remove(selectedSociete);
                                    Societes.Remove(selectedSociete);

                                    App.dbContext.Societes.Add(a);
                                    App.dbContext.SaveChangesAsync();
                                    MessageBox.Show("Annonceur enregistré", "Validation", MessageBoxButton.OK, MessageBoxImage.Information);

                                    Societes.Add(a);
                                    listeSociete.SelectedItem = a;
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                            }
                        }
                    }
                    else
                    {
                        this.labelErreurAdresseNumero.Visibility = System.Windows.Visibility.Visible;
                    }
                }
            }
        }