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"); } }
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(); } } }
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); } }
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."); } }
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"); } }
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(); } }
public wndAddConsole() { InitializeComponent(); DataContext = new console(); }