Esempio n. 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));
            }
        }
        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));
            }
        }
Esempio n. 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));
        }