Exemplo n.º 1
0
        private ICollection <Movies> GetMoviesByName(string directorName)
        {
            var context  = new IMDBContext();
            var director = context.Directors.Single(d => d.FIO == directorName);

            return(director.Movies);
        }
Exemplo n.º 2
0
        private Guid GetDirectorIdByName(string directorName)
        {
            var context = new IMDBContext();
            var rec     = context.Directors.FirstOrDefault(d => d.FIO == directorName);

            if (rec != null)
            {
                return(rec.Id);
            }
            return(Guid.Empty);
        }
Exemplo n.º 3
0
        private void AddFilmInSQLCollenction(Film film)
        {
            using (IMDBContext context = new IMDBContext())
            {
                Guid dirId = GetDirectorIdByName(film.Director);

                if (dirId != Guid.Empty)
                {
                    context.Directors.Single(d => d.FIO == film.Director)
                    .Movies.Add(new Movies
                    {
                        Id          = Guid.NewGuid(),
                        Title       = film.Title,
                        Rating      = film.Rating,
                        DirectorId  = dirId,
                        Description = film.Description,
                        Poster      = film.Poster
                    });
                }
                else
                {
                    Guid newId = Guid.NewGuid();
                    context.Directors.Add(new Director
                    {
                        Id  = newId,
                        FIO = film.Director
                    });

                    context.Movies1.Add(new Movies
                    {
                        Id          = Guid.NewGuid(),
                        Title       = film.Title,
                        Rating      = film.Rating,
                        DirectorId  = newId,
                        Description = film.Description,
                        Poster      = film.Poster
                    });
                }

                context.SaveChanges();
            }
        }
Exemplo n.º 4
0
        private List <Director> GetDirectors()
        {
            var context = new IMDBContext();

            return(context.Directors.ToList());
        }