Exemple #1
0
        public async Task <IActionResult> Edit(BreedViewModel breedModel)
        {
            Breed breed = await context.Breeds.FirstOrDefaultAsync(b => b.Id == breedModel.Id);

            if (breed == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                breed.Name = breedModel.Name;
                context.Update(breed);
                context.SaveChangesAsync();
            }
            return(Redirect($"/Breeds/Details/{breed.Id}"));
        }
Exemple #2
0
        public async Task <IActionResult> Edit(EditFormCatViewModel catModel)
        {
            Breed breed = context.Breeds.FirstOrDefault(b => b.Id == catModel.BreedId);
            Cat   cat   = context.Cats.FirstOrDefault(c => c.Id == catModel.Id);

            if (breed == null || cat == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                cat.Name     = catModel.Name;
                cat.Age      = catModel.Age;
                cat.BreedId  = catModel.BreedId;
                cat.ImageUrl = catModel.ImageUrl;
                context.Update(cat);
                context.SaveChanges();
            }
            ViewData["BreedId"] = new SelectList(context.Breeds, "Id", "Name", catModel.BreedId);
            return(Redirect($"/Cats/Details/{cat.Id}"));
        }