コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Photo,SpeciesId,Age,Info")] Cats cats)
        {
            int counter = 0;

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

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(cats));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Country,Wool,Size,Lifetime,Photo")] Species species)
        {
            int counter = 0;

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

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(species));
            }
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,name,sex,color")] Cats cats)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cats);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cats));
        }