public async Task CreateBreed(CreateBreedFormViewModel breedModel) { Breed newBreed = new Breed() { Name = breedModel.Name, }; context.Add(newBreed); await context.SaveChangesAsync(); }
public async Task <bool> CreateCat(CreateCatViewModel catModel) { Breed breed = await context.Breeds.FirstOrDefaultAsync(b => b.Id == catModel.BreedId); if (breed == null) { return(false); } Cat newCat = new Cat() { Name = catModel.Name, Age = catModel.Age, BreedId = catModel.BreedId, Breed = breed, ImageUrl = catModel.ImageUrl }; context.Add(newCat); await context.SaveChangesAsync(); return(true); }
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}")); }