private void DeleteBtn(object sender, RoutedEventArgs e)
        {
            DogsBaseEntities db = new DogsBaseEntities();
            int dogID;

            if (!int.TryParse(ID_txt.Text, out dogID))
            {
                MessageBox.Show("Dog ID must be numeric", errorbox);
                return;
            }
            else if (dogID <= 0)
            {
                MessageBox.Show("There is no Dog with that id: " + dogID, errorbox);
            }
            else
            {
                Dog dogs      = new Dog();
                var deletedog =
                    from Dog in db.Dogs
                    where Dog.Id == dogID
                    select Dog;
                //// delete dog by id in ID_txt
                foreach (var Dog in deletedog)
                {
                    db.Dogs.Remove(Dog);
                }
                MessageBox.Show("Dog deleted successfully!", done);
                db.SaveChanges();
                dogProfileData.ItemsSource = dogsService.GetDogList();
                ID_txt.Text = String.Empty;
            }
        }
        public DogsWindow()
        {
            InitializeComponent();
            DogsBaseEntities db = new DogsBaseEntities();

            dogsService = new DogsService(db);
            dogProfileData.ItemsSource = dogsService.GetDogList();
        }
Example #3
0
        public AddDog()
        {
            InitializeComponent();
            DogsBaseEntities db = new DogsBaseEntities();

            dogsService          = new DogsService(db);
            AddDogDG.ItemsSource = dogsService.GetDogList();
        }
Example #4
0
        private void AddNewDog(object sender, RoutedEventArgs e)
        {
            int parsedInput;

            if (DogName_txt.Text == "")
            {
                MessageBox.Show("Please enter the dog's name", errorbox);
            }
            else if (DogBreed_txt.Text == "")
            {
                MessageBox.Show("Please enter the dog's breed", errorbox);
            }
            else if (DogOwner_txt.Text == "")
            {
                MessageBox.Show("Please enter  the dog's owner id", errorbox);
            }
            else if (!int.TryParse(DogOwner_txt.Text, out parsedInput))
            {
                MessageBox.Show("Dogs owner ID must be numeric", errorbox);
                return;
            }
            else
            {
                int ownerinput      = int.Parse(DogOwner_txt.Text);
                DogsBaseEntities db = new DogsBaseEntities();
                //DogsOwner dogsOwner = new DogsOwner();
                //var ownerid = db.DogsOwners.Single(o => ownerinput == o.Owner_id);

                Dog dogs = new Dog()
                {
                    Name     = DogName_txt.Text,
                    Breed    = DogBreed_txt.Text,
                    Owner_id = ownerinput,
                };

                db.Dogs.Add(dogs);
                db.SaveChanges();
                MessageBox.Show("Dog added successfully!", newdog);
                AddDogDG.ItemsSource = dogsService.GetDogList();
                DogName_txt.Text     = String.Empty;
                DogBreed_txt.Text    = String.Empty;
                DogOwner_txt.Text    = String.Empty;
            }
        }