// Salva informações no banco private void Save() { MovieModel movie = new MovieModel() { Title = txt_title.Text, OriginalTitle = txt_originaltitle.Text, ImgPath = txt_img.Text, Genre = (string)lb_genres.SelectedValue, Cast = new CastModel() { Main = lb_mains.Items.OfType <string>().ToList(), Others = lb_others.Items.OfType <string>().ToList() }, Provider = txt_provider.Text, ReleaseDate = (DateTime)dt_releaseddate.SelectedDate, Language = txt_language.Text, HasSubtitle = (bool)cb_hassubtitle.IsChecked, ScreenFormat = string.Format("{0}:{1}", txt_screenformatw.Text, txt_screenformath.Text), Units = (int)ud_units.Value, AgeRating = Convert.ToByte(lb_agerating.SelectedValue), Rating = (byte)GenerateRating(), Location = new LocationModel() { Stand = txt_stand.Text.ToUpper()[0], Shelf = (byte)ud_shelf.Value, Pos = (int)ud_pos.Value } }; if (!EditMode) { MovieModel.Save(movie); } else { movie.Id = SelectedMovie.MovieModel.Id; if (MovieModel.Replace(movie)) { MessageBox.Show("Filme atualizado!"); } else { MessageBox.Show("Erro ao atualizar filme!"); } } MovieStoreManager.Movies = MovieStoreManager.GetAllMovies(); Close(); }
private void Save(object sender, RoutedEventArgs e) { if (cb_clients.SelectedIndex == -1) { return; } WithDrawModel withdraw = new WithDrawModel() { MovieTitle = Movie.MovieModel.Title, ClientId = (cb_clients.SelectedItem as ClientModel).Id, Employee = Employee.Id, WithDrawReturn = (DateTime)dt_returndate.SelectedDate, WithDrawDate = DateTime.Today }; if (Movie.MovieModel.Units < 1) { MessageBox.Show("Não existem unidades disponíveis para este filme!", "Falta de unidades", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (WithDrawModel.Save(withdraw)) { // Decrementa unidades disponíveis do filme Movie.MovieModel.Units--; // Realiza update do filme com as unidades novas MovieModel.Replace(Movie.MovieModel); MovieStoreManager.Movies = MovieStoreManager.GetAllMovies(); MessageBox.Show("Retirada bem sucessida!"); txt_units.Text = Movie.MovieModel.Units.ToString(); ClearTxts(); UpdateTable(); } else { MessageBox.Show("Erro ao tentar retirar filme! Tente novamente."); } }