Пример #1
0
        // GET: Item/Edit/5
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var _toy = _toyRepository.GetToyById(id.Value);

            var model = new ToyViewModel()
            {
                Toy        = _toy,
                Producers  = FormHelper.GetFormProducers(_producerRepository.GetProducers()),
                Categories = FormHelper.GetFormCategories(_categoryRepository.GetCategories()),
                Producer   = _toy.Producer.Id,
                Category   = _toy.Category.Id,
                Conditions = FormHelper.GetFormCondition(),
                Condition  = (int)_toy.Condition
            };

            return(View(model));
        }
Пример #2
0
        public IEnumerable <Producer> GetProducers()
        {
            var result = _producerRepository.GetProducers();

            return(result);
        }
Пример #3
0
 // GET: Producers
 public ActionResult Index()
 {
     return(View(_producerRepository.GetProducers()));
 }
Пример #4
0
        // GET: Movies/Create
        public ActionResult Create(Movie movie)
        {
            CreateMovieViewModel model = new CreateMovieViewModel();

            if (movie.Name != null)
            {
                Populate     n           = new Populate();
                Composite    pop         = n.Popul(movie);
                Producer     newproducer = new Producer();
                List <Actor> newactors   = new List <Actor>();

                newproducer = pop.Producer;
                newactors   = pop.Actors;

                string   pname    = newproducer.Name;
                Producer producer = _producerRepository.GetProducers().FirstOrDefault(a => a.Name == pname);
                if (producer == null)
                {
                    _producerRepository.InsertProducer(newproducer);
                    _producerRepository.Save();
                }

                List <int> selectedActorIDs = new List <int>();


                List <Actor> actors     = _actorRepository.GetActors().ToList();
                List <Actor> tempActors = new List <Actor>();

                foreach (var b in newactors)
                {
                    string aname = b.Name;
                    Actor  actor = actors.FirstOrDefault(a => a.Name == aname);
                    if (actor == null)
                    {
                        tempActors.Add(b);
                    }
                }

                foreach (var b in tempActors)
                {
                    _actorRepository.InsertActor(b);
                    _actorRepository.Save();
                }

                actors = _actorRepository.GetActors().ToList();
                //foreach (var b in newactors)
                //    selectedActorIDs.Add(actors.FirstOrDefault(a => a.tmdb_id == b.tmdb_id).ID);

                List <int> toadd = (from na in newactors
                                    join a in actors on na.TmdbId equals a.TmdbId
                                    select a.Id).ToList();

                selectedActorIDs.AddRange(toadd);

                SelectList      producerslist = new SelectList(_producerRepository.GetProducers().OrderBy(i => i.Name), "Id", "Name", _producerRepository.GetProducers().FirstOrDefault(a => a.TmdbId == newproducer.TmdbId).Id);
                MultiSelectList actorslist    = new MultiSelectList(_actorRepository.GetActors().OrderBy(i => i.Name), "Id", "Name", selectedActorIDs);
                model.Name      = movie.Name;
                model.Plot      = movie.Plot;
                model.Year      = movie.Year;
                model.Image     = movie.Image;
                model.Producers = producerslist;
                model.Actors    = actorslist;
                model.TmdbId    = movie.TmdbId;
            }
            else
            {
                SelectList      producerslist = new SelectList(_producerRepository.GetProducers().OrderBy(i => i.Name), "Id", "Name");
                MultiSelectList actorslist    = new MultiSelectList(_actorRepository.GetActors().OrderBy(i => i.Name), "Id", "Name");
                model.Producers = producerslist;
                model.Actors    = actorslist;
            }

            return(View(model));
        }