Beispiel #1
0
        private void addMovieDisk()
        {
            int id = Convert.ToInt32(dataAll[0, dataAll.CurrentCell.RowIndex].Value);

            MessageBox.Show(Convert.ToString(id));

            Movie mov  = db.Movies.Where(k => k.Id == id).FirstOrDefault();
            Disk  disk = db.Disks.Where(k => k.Id == Id_all.id_all).FirstOrDefault();

            MovieDisk movieDisk = new MovieDisk
            {
                MovieId = mov.Id,
                Movie   = mov,
                DiskId  = id,
                Disk    = disk
            };

            db.MovieDisks.Add(movieDisk);

            if (addText == null)
            {
                addText.Text = mov.Name;
            }
            else
            {
                addText.Text = "," + mov.Name;
            }

            var disk2 = new Disk();

            disk2.Movies = new Collection <MovieDisk>();
            disk2.Movies.Add(movieDisk);
            db.SaveChanges();
        }
Beispiel #2
0
        public void AddDisk(string name, string format, int copy, int cost)
        {
            using (Contex db = new Contex())
            {
                Disk disk = new Disk
                {
                    Name   = name,
                    cost   = cost,
                    format = format,
                    copy   = copy,
                };
                //diskGl = disk;
                db.Disks.Add(disk);
                db.SaveChanges();

                /*using (Contex My = new Contex())
                 * {*/
                for (int i = 0; i < ArrayMoviesDisk.movies.Count; i++)
                {
                    //var movie = ArrayMoviesDisk.movies[i];
                    int movieId = Convert.ToInt32(ArrayMoviesDisk.arrayList[i]);
                    //int movieId = movie.Id;
                    //Movie movie2 = My.Movies.Include(s => s.).First
                    //MessageBox.Show(movie2.Name);
                    Movie movie2 = db.Movies.First(s => s.Id == movieId);
                    //Movie movie = My.Movies.Where(k => k.Id == movieId).FirstOrDefault();
                    //Movie movie1 = movie;
                    int       diskId    = disk.Id;
                    MovieDisk movieDisk = new MovieDisk
                    {
                        MovieId = movieId,
                        DiskId  = diskId,
                    };
                    db.MovieDisks.Add(movieDisk);
                }
                db.SaveChanges();
                //}
            }
        }