public async Task <IActionResult> Edit(int id, [Bind("DepId,DepName")] Departements departements) { if (id != departements.DepId) { return(NotFound()); } if (ModelState.IsValid) { try { //_context.Update(departements); //await _context.SaveChangesAsync(); iDepatementService.Update(departements); } catch (DbUpdateConcurrencyException) { if (!DepartementsExists(departements.DepId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(departements)); }
public async Task <IActionResult> Post([FromBody] DepartementsViewModel departements) { if (ModelState.IsValid) { try { Departements _departements = Mapper.Map <Departements>(departements); //_departements.Name = _departements.Name.ToUpper(); // _unitOfWork.Departements.Add(_departements); _unitOfWork.BudjetDepartement.Add(new BudjetDepartement { Annees = DateTime.Now, LigneCapex = departements.BudjetCapex, LigneOpex = departements.BudjetOpex, DepartementsId = _departements.Id, Departements = _departements }); await _unitOfWork.SaveChangesAsync(); return(Ok("OK")); } catch (Exception ex) { return(BadRequest(ex.Data)); } } else { return(BadRequest(ModelState)); } }
private void button1_Click(object sender, EventArgs e) { try { if (departTxt.Text == "") { DynamicClasses.GetInstance().Alert("Champs vide détecté", DialogForms.FrmAlert.enmType.Error); } else if (UserSession.GetInstance().Fonction == "Secrétaire" || UserSession.GetInstance().Fonction == "SA") { Departements depart = new Departements(); depart.Id = id; depart.Departement = departTxt.Text; depart.SaveDatas(depart); DynamicClasses.GetInstance().Alert("Département save", DialogForms.FrmAlert.enmType.Success); departTxt.Clear(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public async Task <IActionResult> Put(int id, [FromBody] ServicesViewModel services) { if (ModelState.IsValid) { try { Services _services = Mapper.Map <Services>(services); Departements departements = _unitOfWork.Departements.GetSingleOrDefault(e => e.Id == services.departementsId); _services.Departements = departements; // _services.Name = _services.Name.ToUpper(); _unitOfWork.Services.Update(_services); await _unitOfWork.SaveChangesAsync(); return(Ok("OK")); } catch (Exception ex) { return(BadRequest(ex.Data)); } } else { return(BadRequest(ModelState)); } }
public async Task <IActionResult> Create([Bind("DepId,DepName")] Departements departements) { if (ModelState.IsValid) { iDepatementService.Insert(departements); return(RedirectToAction(nameof(Index))); } return(View(departements)); }
public async Task <IActionResult> Search(string SearchWord) { var departement = iDepatementService.FindBy(SearchWord); if (departement == null) { departement = new Departements(); ModelState.AddModelError("CustomError", "Not Found"); return(View(departement)); } ViewBag.Count = departement.Employees.Count(); return(View(departement)); }
public async Task <IActionResult> Delete(int id) { if (ModelState.IsValid) { try { Departements _departements = _unitOfWork.Departements.GetSingleOrDefault(e => e.Id == id); if (_departements != null) { _unitOfWork.Departements.Remove(_departements); BudjetDepartement _Bd = getBudejetByDepId(id); if (_Bd != null) { _unitOfWork.BudjetDepartement.Remove(_Bd); } await _unitOfWork.SaveChangesAsync(); return(Ok("OK")); } else { return(BadRequest()); } } catch (Exception ex) { return(BadRequest(ex.Data)); } } else { return(BadRequest(ModelState)); } }
public async Task <IActionResult> Put(int id, [FromBody] DepartementsViewModel departements) { if (ModelState.IsValid) { try { Departements _departements = Mapper.Map <Departements>(departements); BudjetDepartement _Bd = getBudejetByDepId(_departements.Id); if (_Bd != null) { _unitOfWork.BudjetDepartement.Update(_Bd); } else { _unitOfWork.BudjetDepartement.Add(new BudjetDepartement { LigneCapex = departements.BudjetCapex, LigneOpex = departements.BudjetOpex, Departements = _departements, Annees = DateTime.Now }); } _unitOfWork.Departements.Update(_departements); await _unitOfWork.SaveChangesAsync(); return(Ok("OK")); } catch (Exception ex) { return(BadRequest(ex.Data)); } } else { return(BadRequest(ModelState)); } }
private void buttonAffEmployesDsList_Click(object sender, RoutedEventArgs e) { if (connexion == null) { return; } Globals.ThisAddIn.Application.Cursor = Microsoft.Office.Interop.Excel.XlMousePointer.xlWait; var lstDep = new Departements(connexion).GetDepartements(rbNom.IsChecked == true); if (lstDep != null) { this.listBoxDep.ItemsSource = lstDep; // changer le nom du header dans la listBox (Nom ou Ville) : this.depVM.HeaderListBoxDepartement = (rbNom.IsChecked == true) ? "Nom" : "Ville"; } Globals.ThisAddIn.Application.Cursor = Microsoft.Office.Interop.Excel.XlMousePointer.xlDefault; // Pour une liste stubbé AVANT création (testing de la présentatiON) }
//Pour insérer un nouveau département dans la table departement private void buttonInsertDep_Click(object sender, RoutedEventArgs e) { //validations.. txtID txtNomDepartement txtVille //validation id int idDep = 0; if (txtID.Text.Trim() == "") { txtID.Background = System.Windows.Media.Brushes.Red; MessageBox.Show("Erreur. Le ID doit être saisie.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error); txtID.Background = System.Windows.Media.Brushes.White; return; } if ((!int.TryParse(txtID.Text.Trim(), out idDep))) { txtID.Background = System.Windows.Media.Brushes.Red; MessageBox.Show("Erreur. Le ID doit être une valeur numérique.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error); txtID.Background = System.Windows.Media.Brushes.White; return; } //validation departement if (txtNomDepartement.Text.Trim() == "" || txtNomDepartement.Text.Trim().Length > 15) { txtNomDepartement.Background = System.Windows.Media.Brushes.Red; MessageBox.Show("Erreur. Le nom du département doit être saisie et ce de manière valide. Le nombre de caractères maximales est 15.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error); txtNomDepartement.Background = System.Windows.Media.Brushes.White; return; } // validation ville if (txtVille.Text.Trim() == "" || txtVille.Text.Trim().Length > 20) { txtVille.Background = System.Windows.Media.Brushes.Red; MessageBox.Show("Erreur. Le nom de la ville doit être saisie et ce de manière valide. Le nombre de caractères maximales est 20.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error); txtVille.Background = System.Windows.Media.Brushes.White; return; } //insertion bd: int res = new Departements(connexion).Add(new Departement { id = idDep, nom = txtNomDepartement.Text.Trim(), ville = txtVille.Text.Trim() }); if (res > 0) { //succès, donc on actualise: this.buttonAffEmployesDsList_Click(sender, e); this.txtID.Text = ""; this.txtNomDepartement.Text = ""; this.txtVille.Text = ""; } else { MessageBox.Show("Erreur. L'insertion n'a pas été un succès. Veuillez corriger votre ID; cette valeur doit être unique.", "Erreur"); } }
public static void Seed(IApplicationBuilder applicationBuilder) { var scopeFactory = applicationBuilder.ApplicationServices.GetRequiredService <IServiceScopeFactory>(); using (var scope = scopeFactory.CreateScope()) { var context = scope.ServiceProvider.GetRequiredService <AppDbContext>(); if (!context.Departements.Any()) { context.Departements.AddRange(Departements.Select(c => c.Value)); } if (!context.Sensors.Any()) { context.AddRange ( new Sensor { Name = "SM-1", CurrentLevel = 45, IsOn = true, Departement = Departements["Mechanical Departement"] }, new Sensor { Name = "SM-2", CurrentLevel = 55, IsOn = true, Departement = Departements["Mechanical Departement"] }, new Sensor { Name = "SM-3", CurrentLevel = 65, IsOn = false, Departement = Departements["Mechanical Departement"] }, new Sensor { Name = "SE-1", CurrentLevel = 65, IsOn = false, Departement = Departements["Electrical Departement"] }, new Sensor { Name = "SE-2", CurrentLevel = 65, IsOn = false, Departement = Departements["Electrical Departement"] }, new Sensor { Name = "SE-3", CurrentLevel = 95, IsOn = false, Departement = Departements["Electrical Departement"] }, new Sensor { Name = "SE-4", CurrentLevel = 15, IsOn = true, Departement = Departements["Electrical Departement"] }, new Sensor { Name = "SC-1", CurrentLevel = 65, IsOn = false, Departement = Departements["Civil Departement"] }, new Sensor { Name = "SC-2", CurrentLevel = 75, IsOn = false, Departement = Departements["Civil Departement"] } , new Sensor { Name = "SC-3", CurrentLevel = 95, IsOn = true, Departement = Departements["Civil Departement"] } ); } context.SaveChanges(); } }
public void Update(Departements dep) { Departementservice.Update(dep); }
public void Insert(Departements dep) { Departementservice.Add(dep); }
public void Delete(Departements dep) { throw new NotImplementedException(); }