示例#1
0
        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);
            }
        }