public BookInfo(int bookId, int userId) { InitializeComponent(); //ad = adminMenu; //ud = userMenu; this.bookId = bookId; this.userId = userId; using (var db = new LibraryDBEntities()) { var book = db.Books.Find(bookId); BookName.Content = book.Name; BookAuthor.Content = book.Author.FName + " " + book.Author.LName; BookGenre.Content = book.Genre.Name; BookTheme.Content = book.Theme.Name; Description.Text = book.Description; Location.Content = book.Location.Name; var user = db.Users.Find(userId); if (user.RoleID == 1) { AddToWs.Visibility = Visibility.Collapsed; } if (book.Id % 2 == 0) { var uriSource = new Uri(@"/SoulMelody;component/Images/cover1.jpg", UriKind.Relative); Cover.Source = new BitmapImage(uriSource); } if (book.Id % 2 != 0) { var uriSource = new Uri(@"/SoulMelody;component/Images/cover2.jpg", UriKind.Relative); Cover.Source = new BitmapImage(uriSource); } if (book.Id % 3 == 0) { var uriSource = new Uri(@"/SoulMelody;component/Images/cover3.jpg", UriKind.Relative); Cover.Source = new BitmapImage(uriSource); } //else //{ // var uriSource = new Uri(@"/SoulMelody;component/Images/cover4.jpg", // UriKind.Relative); // Cover.Source = new BitmapImage(uriSource); //} } }
private void LoginBtn_Click(object sender, RoutedEventArgs e) { using (LibraryDBEntities db = new LibraryDBEntities()) { var login = Login.Text; var password = Password.Password; var loginSearch = from user in db.Users where user.Login == login select user; var userResult = loginSearch.FirstOrDefault(); try { if (Login.Text != "" && Password.Password != "") { if (userResult != null) { if (password == userResult.Password) { if (userResult.RoleID == 1) { AdminMenu menu = new AdminMenu(userResult.Id); menu.Show(); StartingUC startUC = new StartingUC(st); st.startGrid.Children.Clear(); st.startGrid.Children.Add(startUC); } if (userResult.RoleID == 2) { UserMenu menu = new UserMenu(userResult.Id); menu.Show(); StartingUC startUC = new StartingUC(st); st.startGrid.Children.Clear(); st.startGrid.Children.Add(startUC); } } else { MessageBox.Show("Wrong password!"); } } else { MessageBox.Show("Login not found!"); } } else { MessageBox.Show("Fill in all fields!"); } } catch (Exception exception) { MessageBox.Show(exception.Message); } } }