Example #1
0
        public void UpdateEmployee()
        {
            using (var db = new DataSmartDBContext())
            {
                var employeeToUpdate = db.Employee.Find(SelectedEmployee.EmployeeId);

                // Check wether the new value of EmployeeSIN is identical to an existing Employee EmployeeSIN since this property value should be unique
                if (db.Employee.Any(o => o.EmployeeId != Employee.EmployeeId & o.EmployeeSIN == Employee.EmployeeSIN))
                {
                    MessageBox.Show("Il existe deja un employé avec le meme ID dans la base de donnée", "DataSmart Info", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else // Else apply updates to the selected employee
                {
                    // Show a dialog box to confirm the action. if result is Yes then apply changes otherwise do nothing
                    var result = MessageBox.Show("Vous êtes sur le point de modifier les informations de la ligne séctionnée avec les informations affichées. " +
                                                 "Voulez vous poursuivre la modification?", "DataSmart Info", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                    if (result == MessageBoxResult.Yes)
                    {
                        // Update the selected entity property values with th new ones
                        db.Entry(employeeToUpdate).CurrentValues.SetValues(Employee);
                        db.SaveChanges();   // Save changes to the database
                        MessageBox.Show("Employé Mis À Jour", "DataSmart Info", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }
        }
Example #2
0
 /// <summary>
 ///  Method to update an Existing Entity of Product
 /// </summary>
 public void UpdateProduct()
 {
     using (var db = new DataSmartDBContext())
     {
         var productToUpdate = db.Produits.Find(SelectedProduct.ProductId);
         if (db.Produits.Any(o => o.ProductId != Product.ProductId & o.ProductName == Product.ProductName))
         {
             MessageBox.Show("Il existe deja un autre produit avec le meme nom dans la base de donnée", "DataSmart Info", MessageBoxButton.OK, MessageBoxImage.Information);
         }
         else
         {
             var result = MessageBox.Show("Vous êtes sur le point de modifier les informations de la ligne séctionnée avec les informations affichées. " +
                                          "Voulez vous poursuivre la modification?", "DataSmart Info", MessageBoxButton.YesNo, MessageBoxImage.Warning);
             if (result == MessageBoxResult.Yes)
             {
                 db.Entry(productToUpdate).CurrentValues.SetValues(Product);
                 db.SaveChanges();
                 MessageBox.Show("Produit Mis à Jour!", "DataSmart Info", MessageBoxButton.OK, MessageBoxImage.Information);
             }
         }
     }
 }