示例#1
0
        private void UpdateRelatedStudios(string[] selectedStudios, Filmes filmeToUpdate)
        {
            if (selectedStudios == null)
            {
                filmeToUpdate.Studios = new List<Studios>();
                return;
            }

            var selectedStudiosHS = new HashSet<string>(selectedStudios);
            var filmeStudios = new HashSet<int>(filmeToUpdate.Studios.Select(s => s.StudioID));

            foreach (var studio in unitOfWork.StudiosRepository.Get())
            {
                if (selectedStudiosHS.Contains(studio.StudioID.ToString()))
                {
                    if (!filmeStudios.Contains(studio.StudioID))
                    {
                        filmeToUpdate.Studios.Add(studio);
                    }
                }
                else
                {
                    if (filmeStudios.Contains(studio.StudioID))
                    {
                        filmeToUpdate.Studios.Remove(studio);
                    }
                }
            }
        }
示例#2
0
        private void UpdateRelatedGenres(string[] selectedGenres, Filmes filmeToUpdate)
        {
            if (selectedGenres == null)
            {
                filmeToUpdate.Generos = new List<Generos>();
            }
            else
            {
                var selectedGenresHS = new HashSet<string>(selectedGenres);
                var filmeGenres = new HashSet<int>(filmeToUpdate.Studios.Select(s => s.StudioID));

                foreach (var genre in unitOfWork.GenerosRepository.Get())
                {
                    if (selectedGenresHS.Contains(genre.GeneroID.ToString()))
                    {
                        if (!filmeGenres.Contains(genre.GeneroID))
                        {
                            filmeToUpdate.Generos.Add(genre);
                        }
                    }
                    else
                    {
                        if (filmeGenres.Contains(genre.GeneroID))
                        {
                            filmeToUpdate.Generos.Remove(genre);
                        }
                    }
                }
            }
        }
示例#3
0
        private void PopulateAssigned(Filmes filme = null)
        {
            if (filme == null)
            {
                filme = new Filmes();
            }
            var allGenres = unitOfWork.GenerosRepository.Get();
            var allStudios = unitOfWork.StudiosRepository.Get();
            var filmGenres = new HashSet<int>(filme.Generos.Select(g => g.GeneroID));
            var filmStudios = new HashSet<int>(filme.Studios.Select(s => s.StudioID));
            var viewModelGenres = new List<AssignedData>();
            var viewModelStudios = new List<AssignedData>();
            
            foreach (var genre in allGenres)
            {
                viewModelGenres.Add(new AssignedData
                {
                    ID = genre.GeneroID,
                    Description = genre.Descricao,
                    Assigned = filmGenres.Contains(genre.GeneroID)
                });
            }

            foreach (var studio in allStudios)
            {
                viewModelStudios.Add(new AssignedData
                {
                    ID = studio.StudioID,
                    Description = studio.Nome,
                    Assigned = filmStudios.Contains(studio.StudioID)
                });
            }
            
            ViewBag.Generos = viewModelGenres;
            ViewBag.Studios = viewModelStudios;
        }