private void IstandsættelseOpdaterBtn_Click(object sender, RoutedEventArgs e) { //If statement that prevents updating a row if the inputs are empty if (OpdaterPris.Text.Any(char.IsDigit) == true && OpdaterArealAfHave.Text.Any(char.IsDigit) == true && !(OpdaterSlutDato.SelectedDate == null || OpdaterStartDato.SelectedDate == null || OpdaterPris.Text == "" || OpdaterArealAfHave.Text == "" || OpdaterBAO.Text == "")) { //opdateretOrdre is an action where m is a ordre entity //in the Istandsættelse table //It selects a ordre which has the same id as the variable we made earlier //And only selects one ordre* HaveService.Istandsættelse opdateretOrdre = (from i in _istandDb.Istandsættelse where i.Id == id select i).Single(); //Updating the movie columns with the text that is written in the input fields of the updatepage opdateretOrdre.Start_Dato = (DateTime)OpdaterStartDato.SelectedDate; opdateretOrdre.Slut_Dato = (DateTime)OpdaterSlutDato.SelectedDate; opdateretOrdre.Pris = int.Parse(OpdaterPris.Text); opdateretOrdre.Areal_Af_Have = int.Parse(OpdaterArealAfHave.Text); opdateretOrdre.Beskrivelse_af_Opgave = OpdaterBAO.Text; } //Saving the changes to the database _istandDb.SaveChanges(); //Adding the changes to the list of movies MainWindow.Istanddatagrid.ItemsSource = _istandDb.Istandsættelse.ToList(); //Hiding the window this.Hide(); }
public void insertBtn() { //Making a new movie entity HaveService.Istandsættelse nyOrdre = new HaveService.Istandsættelse() { //Making the columns equal the input fields text Kundeadresse = IstandsættelseAdresse.Text, Start_Dato = (DateTime)IstandsættelseStartDato.SelectedDate, Slut_Dato = (DateTime)IstandsættelseSlutDato.SelectedDate, Pris = int.Parse(IstandsættelsePris.Text), Areal_Af_Have = int.Parse(IstandsættelseArealAfHave.Text), Beskrivelse_af_Opgave = IstandsættelseBAO.Text, }; //For Unit Testing if (nyOrdre.Kundeadresse == IstandsættelseAdresse.Text) { hasSucceeded = true; } //Adding the new movie to the Movies table _istandDb.Istandsættelse.Add(nyOrdre); //Saving the changes made to the database entity _istandDb.SaveChanges(); //Adding the changes and all other table data to the datagrid MainWindow.Istanddatagrid.ItemsSource = _istandDb.Istandsættelse.ToList(); //Hiding the window this.Hide(); }