Example #1
0
        public IActionResult EditSerial(int id, SerialEditViewModel serialModel)
        {
            var genres = serialModel.GenreOptions
                         .Where(g => g.IsSelected)
                         .Select(g => g.Name);

            if (ModelState.IsValid && genres.Count() > 0)
            {
                var selectedGenres = serialModel.GenreOptions.Where(g => g.IsSelected).Select(g => g.Name);

                _serialService.EditSerial(id, serialModel.Name, selectedGenres, (int)serialModel.SelectedCountryId);

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                var countries = _countryService.GetAllCountries();

                serialModel.Countries = countries.Select(c => new Select()
                {
                    Name = c.Name, Id = c.Id
                }).ToList();

                return(View(serialModel));
            }
        }
Example #2
0
        public IActionResult EditSerial(int id)
        {
            var serial       = _serialService.GetSerial(id);
            var serialGenres = _serialService.GetNamesOfGenres(id);
            var genres       = _genreService.GetAllGenres();

            var serialModel = new SerialEditViewModel()
            {
                SerialId          = serial.Id,
                Name              = serial.Name,
                SelectedCountryId = serial.CountryId,
                Countries         = _countryService.GetAllCountries().Select(c => new Select()
                {
                    Name = c.Name, Id = c.Id
                }).ToList(),
                GenreOptions = genres.Select(g => new Option()
                {
                    Name = g.Name, IsSelected = serialGenres.Contains(g.Name)
                }).ToList()
            };

            return(View(serialModel));
        }