public async Task <IActionResult> PutCat(Guid id, Cat cat)
        {
            if (id != cat.Id)
            {
                return(BadRequest());
            }

            _context.Entry(cat).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CatExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #2
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));
            }
        }
Example #4
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));
        }
        public async Task <IActionResult> PutSpecies(int id, Species species)
        {
            if (id != species.Id)
            {
                return(BadRequest());
            }
            int counter = 0;

            foreach (var g in _context.Species)
            {
                if (g.Name == species.Name)
                {
                    counter++; break;
                }
            }

            if (counter != 0)
            {
                ModelState.AddModelError("Spesies", "Така порода вже існує");
            }
            else
            {
                _context.Entry(species).State = EntityState.Modified;
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SpeciesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }