コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Peoples peoples)
        {
            int counter = 0;

            foreach (var a in _context.Peoples)
            {
                if (a.Name == peoples.Name)
                {
                    counter++; break;
                }
            }
            if (counter != 0)
            {
                ModelState.AddModelError("Name", "Така людина вже існує");
                return(View(peoples));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    _context.Add(peoples);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["Id"] = new SelectList(_context.CartoonHeroes, "Id", "Name", peoples.Id);
                return(View(peoples));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,CountriesId")] FilmStudios filmStudios)
        {
            int counter = 0;

            foreach (var a in _context.FilmStudios)
            {
                if (a.Name == filmStudios.Name)
                {
                    counter++; break;
                }
            }
            if (counter != 0)
            {
                ModelState.AddModelError("Name", "Така студія вже існує");
                return(View(filmStudios));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    _context.Add(filmStudios);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["CountriesId"] = new SelectList(_context.Countries, "Id", "Name", filmStudios.CountriesId);
                return(View(filmStudios));
            }
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Countries countries)
        {
            int counter = 0;

            foreach (var a in _context.Countries)
            {
                if (a.Name == countries.Name)
                {
                    counter++; break;
                }
            }
            if (counter != 0)
            {
                ModelState.AddModelError("Name", "Така країна вже існує");
                return(View(countries));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    _context.Add(countries);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(countries));
            }
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("CartoonsId,AwardsId,Year")] CartoonAwards cartoonAwards)
        {
            // var cartaw = await _context.Cartoons.Include(c => c.Year).FirstOrDefaultAsync();
            var cartoon = (from c in _context.Cartoons
                           where c.Id == cartoonAwards.CartoonsId
                           select c).FirstOrDefault();

            if (cartoon.Year > cartoonAwards.Year)
            {
                ModelState.AddModelError("Year", "Некоректне значення");
                return(View(cartoonAwards));
            }
            else
            {
                if (ModelState.IsValid && cartoonAwards.Year > 0)
                {
                    _context.Add(cartoonAwards);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["AwardsId"]   = new SelectList(_context.Awards, "Id", "Name", cartoonAwards.AwardsId);
                ViewData["CartoonsId"] = new SelectList(_context.Cartoons, "Id", "Name", cartoonAwards.CartoonsId);

                return(View(cartoonAwards));
            }
        }
コード例 #5
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Genres genres)
        {
            if (ModelState.IsValid)
            {
                _context.Add(genres);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(genres));
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("Id,Name,Duration,Year,FilmStudiosId")] Cartoons cartoons)
        {
            int counter = 0;

            foreach (var a in _context.Cartoons)
            {
                if (a.Name == cartoons.Name)

                {
                    counter++; break;
                }
            }
            if (counter != 0)
            {
                ModelState.AddModelError("Name", "Такий мультик вже існує");
                ViewData["FilmStudiosId"] = new SelectList(_context.FilmStudios, "Id", "Name", cartoons.FilmStudiosId);
                return(View(cartoons));
            }
            else
            {
                if (cartoons.Year < 1900 || cartoons.Year > 2020)
                {
                    ModelState.AddModelError("Year", "Некоректне значення");
                    ViewData["FilmStudiosId"] = new SelectList(_context.FilmStudios, "Id", "Name", cartoons.FilmStudiosId);
                    return(View(cartoons));
                }
                else
                {
                    if (cartoons.Duration < 0)
                    {
                        ModelState.AddModelError("Duration", "Некоректне значення");
                        ViewData["FilmStudiosId"] = new SelectList(_context.FilmStudios, "Id", "Name", cartoons.FilmStudiosId);
                        return(View(cartoons));
                    }
                    else
                    {
                        if (ModelState.IsValid)
                        {
                            _context.Add(cartoons);
                            await _context.SaveChangesAsync();

                            return(RedirectToAction(nameof(Index)));
                        }
                        ViewData["FilmStudiosId"] = new SelectList(_context.FilmStudios, "Id", "Name", cartoons.FilmStudiosId);
                        return(View(cartoons));
                    }
                }
            }
        }
コード例 #7
0
        public async Task <IActionResult> Create(int id, string name, [Bind("Id,CartoonsId")] GenreCartoons genreCartoons)
        {
            GenreCartoons tg = new GenreCartoons();

            tg.GenresId            = id;
            genreCartoons.GenresId = id;
            tg.CartoonsId          = genreCartoons.CartoonsId;
            genreCartoons.GenresId = id;
            if (ModelState.IsValid)
            {
                _context.Add(genreCartoons);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", new { id, name }));
            }
            ViewData["CartoonsId"] = new SelectList(_context.Cartoons, "Id", "Name", genreCartoons.CartoonsId);
            return(RedirectToAction("Index", new { id, name }));
        }