private void PostUser_Submit_Button_Click(object sender, RoutedEventArgs e) { var takenFilmNames = _postPage.postUser_TakenFilms_ListBox.SelectedItems.OfType <string>(); HashSet <Film> takenFilms = new HashSet <Film>(); foreach (var item in takenFilmNames) { takenFilms.Add(_uof.Films.Get().Where(x => x.Name == item).First()); } try { var user = new User { FirstName = _postPage.postUser_FirstName_TextBox.Text, LastName = _postPage.postUser_LastName_TextBox.Text, TakenFilms = takenFilms, //TODO make setter for coef of multiplication for MoneyToPay calculation MoneyToPay = takenFilms.Count * 15, ReturnDate = _postPage.postUser_returnDate_DatePicker.DisplayDate }; var contactInfo = new ContactInfo { Adress = _postPage.postUser_Adress_TextBox.Text, Email = _postPage.postUser_Email_TextBox.Text, User = user, Phone = _postPage.postUser_Phone_TextBox.Text }; if (PostHelper.IsModelValid(user) && PostHelper.IsModelValid(contactInfo)) { _uof.ContactInfos.Insert(contactInfo); _uof.Commit(); PostHelper.ShowSuccesMessage("Operation succeded!"); return; } throw new Exception(); } catch (Exception) { MessageBox.Show("Error.Please, check if fields are written up correcrly.", "Error :(", MessageBoxButton.OK); } }
private void PostFilm_Submit_Button_Click(object sender, RoutedEventArgs e) { var selectedActorFullNames = _postPage.postFilm_MainActors_ListBox.SelectedItems.OfType <string>().ToList(); HashSet <MainActor> selectedActors = new HashSet <MainActor>(); foreach (var item in selectedActorFullNames) { string[] fName_lName = item.Split(' '); string firstName = fName_lName[0]; string lastName = fName_lName[1]; selectedActors.Add(_uof.Actors.Get().Where(x => x.FirstName == firstName && x.LastName == lastName).First()); } try { var model = new Film { Name = _postPage.postFilm_Name_TextBox.Text, Studio = _postPage.postFilm_Studio_TextBox.Text, DateOfRelease = _postPage.postFilm_SetDOR_DatePicker.SelectedDate ?? DateTime.Now, Director = _postPage.postFilm_Director_TextBox.Text, Summary = PostHelper.GetTextFromRichTextBox(_postPage.postFilm_Summary_RichTextBox), MainActors = selectedActors, Rating = 1, AmountOfAvailableExemplars = Int32.Parse(_postPage.postFilm_AvailbleAmount_TextBox.Text), AmountOfReleasedExemplars = Int32.Parse(_postPage.postFilm_NumOfReleased_TextBox.Text) }; if (PostHelper.IsModelValid(model)) { _uof.Films.Insert(model); _uof.Commit(); PostHelper.ShowSuccesMessage(); return; } throw new Exception(); } catch (Exception) { MessageBox.Show("Error.Please, check if fields are written up correcrly.", "Error :(", MessageBoxButton.OK); } }
private void PostActor_Submit_Button_Click(object sender, RoutedEventArgs e) { var selectedFilmNames = _postPage.postActor_Films_ListBox.SelectedItems.OfType <string>().ToList(); HashSet <Film> selectedFilms = new HashSet <Film>(); foreach (var item in selectedFilmNames) { selectedFilms.Add(_uof.Films.Get().Where(x => x.Name == item).First()); } try { var model = new MainActor() { FirstName = _postPage.postActor_FirstName_TextBox.Text, LastName = _postPage.postActor_LastName_TextBox.Text, Age = (byte)(((DateTime.Now - _postPage.postActor_SetDOB_DatePicker.SelectedDate).Value.Days) / 365), Films = selectedFilms }; if (PostHelper.IsModelValid(model)) { _uof.Actors.Insert(model); _uof.Commit(); PostHelper.ShowSuccesMessage(); return; } throw new Exception(); } catch (Exception exc) { //MessageBox.Show("Error.Please, check if fields are written up correcrly.", "Error :(", MessageBoxButton.OK); throw exc; } }