void BorrowBookExecute(DataGrid _Books) { Book SelectedBook = null; // Try casting SelectedItem to Book - if it fails, there was nothing selected try { SelectedBook = (Book)_Books.SelectedItem; if (SelectedBook == null) { throw new Exception(); } } catch (Exception) { Message = "Uh Oh! Something went wrong. Make sure you've selected a desired Book!"; OnPropertyChanged("Message"); return; } if (SelectedBook.Stock < 1) { // Falltrough, no or invalid book selected Message = "This Book is out of Stock!"; OnPropertyChanged("Message"); return; } // Reset Message Message = ""; OnPropertyChanged("Message"); BorrowWindow _BorrowWindow = new BorrowWindow(); _BorrowWindow.DataContext = new BorrowWindowViewModel() { SelectedBook = SelectedBook, BorrowWindow = _BorrowWindow }; // ShowDialog returns when the Window is closed _LibrarianWindow.Hide(); _BorrowWindow.ShowDialog(); // TODO: Refactor to single Item update... (Needs new StoredProcedure) UpdateBorrows(); UpdateBooks(); _LibrarianWindow.Show(); }
private void AuthenticateExecute(IClosable _LoginWindow) { // Evaluate input mask command to generate Dummy Data; if (Uid == "$MAKE_DUMMY") { int Errors = DummyDataManager.Generate(); if (Errors == 0) { Message = "Executed. Dummy Data generated!"; } else { Message = $"Executed. At least {Errors} Columns weren't inserted!"; } OnPropertyChanged("Message"); return; } //else if (Uid == "$DELETE_DB") //{ // int Errors = DummyDataManager.DeleteAll(); // if (Errors == 0) Message = "Executed. Empties all Tables!"; // else Message = $"Executed. At least {Errors} Tables weren't emptied!"; // OnPropertyChanged("Message"); // return; //} // Get Name and LastName components from input string Regex RegexUid = new Regex(@"^(\S*)\.(\S*)\s*$"); Match Identity = RegexUid.Match(Uid.ToLower()); string Name = Identity.Groups[1].ToString(); string LastName = Identity.Groups[2].ToString(); if (Identity.Groups.Count < 2) { Message = $"Illegal Uid! Must match '{RegexUid.ToString()}'"; OnPropertyChanged("Message"); return; } // Authenticate the Librarian / Customer dynamic User = Access.Auth(Name, LastName, Password); Librarian _Librarian = null; Customer _Customer = null; // Try casting to Librarian and Customer to check who has logged in try { _Librarian = User; } catch (Exception) { /* Ignore */ } try { _Customer = User; } catch (Exception) { /* Ignore */ } if (_Librarian != null) { LibrarianWindow _LibrarianWindow = new LibrarianWindow(); _LibrarianWindow.DataContext = new LibrarianWindowViewModel() { User = _Librarian, LibrarianWindow = _LibrarianWindow }; _LibrarianWindow.Show(); _LoginWindow.Close(); } else if (_Customer != null) { CustomerWindow _CustomerWindow = new CustomerWindow(); _CustomerWindow.DataContext = new CustomerWindowViewModel() { User = _Customer }; _CustomerWindow.Show(); _LoginWindow.Close(); } else { // Falltrough, invalid login data Message = "Uh Oh! Something went wrong."; OnPropertyChanged("Message"); } }