Example #1
0
        public IActionResult AddSerial(SerialRegistrationViewModel serialModel)
        {
            var genres = serialModel.GenreOptions
                         .Where(g => g.IsSelected)
                         .Select(g => g.Name);

            if (ModelState.IsValid && genres.Count() > 0)
            {
                var serial = new Serial()
                {
                    Id      = serialModel.SerialId,
                    Name    = serialModel.Name,
                    Country = _countryService.GetCountryById((int)serialModel.SelectedCountryId)
                };

                _serialService.AddSerial(serial, genres);

                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 AddSerial()
        {
            var genres    = _genreService.GetAllGenres();
            var countries = _countryService.GetAllCountries();

            var serialViewModel = new SerialRegistrationViewModel()
            {
                Countries = countries.Select(c => new Select()
                {
                    Name = c.Name, Id = c.Id
                }).ToList(),
                GenreOptions = genres.Select(g => new Option()
                {
                    Name = g.Name
                }).ToList()
            };

            return(View(serialViewModel));
        }