Esempio n. 1
0
 public void AddConsole(console console)
 {
     try
     {
         using (db_consolesEntities db = new db_consolesEntities())
         {
             Validate(console);
             if (db.consoles.Any(x => x.Short_Name == console.Short_Name))
             {
                 throw new ArgumentException("The console's short name already exists");
             }
             db.consoles.Add(console);
             db.SaveChanges();
             ListUpdated?.Invoke();
         }
     }
     catch (ArgumentException)
     {
         throw;
     }
     catch (Exception)
     {
         throw new Exception("Something wrong happened while adding a new console");
     }
 }
Esempio n. 2
0
 public void RemoveConsole(console console)
 {
     using (db_consolesEntities db = new db_consolesEntities())
     {
         if (db.consoles.FirstOrDefault(x => x.ID == console.ID) != null)
         {
             db.Entry(console).State = System.Data.EntityState.Deleted;
             db.SaveChanges();
             ListUpdated?.Invoke();
         }
     }
 }
Esempio n. 3
0
 private void Edit(object sender, RoutedEventArgs ev)
 {
     try
     {
         wndAddConsole newConsole      = new wndAddConsole();
         console       selectedConsole = (console)dgConsoles.SelectedItem;
         newConsole.Console      = admin.GetConsole(selectedConsole.ID);
         newConsole.consoleAdmin = admin;
         newConsole.isEdit       = true;
         newConsole.ShowDialog();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Console", MessageBoxButton.OK, MessageBoxImage.Information);
     }
 }
Esempio n. 4
0
 public void Update(console console)
 {
     try
     {
         using (db_consolesEntities db = new db_consolesEntities())
         {
             Validate(console);
             db.Entry(console).State = System.Data.EntityState.Modified;
             db.SaveChanges();
             ListUpdated?.Invoke();
         }
     }
     catch (ArgumentException)
     { throw; }
     catch (Exception)
     {
         throw new Exception("Something wrong happened while updating the console's info.");
     }
 }
Esempio n. 5
0
 public static void Validate(console console)
 {
     if (string.IsNullOrWhiteSpace(console.Console_Name))
     {
         throw new ArgumentException("It's necesary to enter the console's name");
     }
     if (console.Console_Name.Length > 50)
     {
         throw new ArgumentException("Console's name has to be smaller than 50 characters");
     }
     if (string.IsNullOrWhiteSpace(console.Short_Name))
     {
         throw new ArgumentException("It's necesary to enter the console's short name");
     }
     if (console.Short_Name.Length > 20)
     {
         throw new ArgumentException("Console's short name has to be smaller than 20 characters.");
     }
     if (console.Company == 0)
     {
         throw new ArgumentException("It's necesary to enter the console's company");
     }
 }
Esempio n. 6
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (isEdit)
            {
                DataContext    = Console;
                btnAdd.Content = "Update";
            }
            else
            {
                DataContext = new console();
            }

            try
            {
                cmbCompany.DisplayMemberPath = "Company_Name";
                cmbCompany.SelectedValuePath = "ID";
                cmbCompany.ItemsSource       = companyAdmin.GetCompanies();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Console");
                Close();
            }
        }
Esempio n. 7
0
 public wndAddConsole()
 {
     InitializeComponent();
     DataContext = new console();
 }