// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync(int?id, string[] selectedColors) { if (id == null) { return(NotFound()); } var dogToUpdate = await _context.Dog .Include(i => i.Breed) .Include(i => i.DogColors) .ThenInclude(i => i.Color) .FirstOrDefaultAsync(s => s.ID == id); if (dogToUpdate == null) { return(NotFound()); } if (await TryUpdateModelAsync <Dog>(dogToUpdate, "Dog", i => i.Image, i => i.Country, i => i.Weight, i => i.DateOfBirth, i => i.BreedID)) { UpdateDogColors(_context, selectedColors, dogToUpdate); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } //Apelam UpdateDogColors pentru a aplica informatiile din checkboxuri la entitatea Dogs care //este editata UpdateDogColors(_context, selectedColors, dogToUpdate); PopulateAssignedColorData(_context, dogToUpdate); return(Page()); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Breed).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BreedExists(Breed.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(string[] selectedColors) { var newDog = new Dog(); if (selectedColors != null) { newDog.DogColors = new List <DogColor>(); foreach (var col in selectedColors) { var colToAdd = new DogColor { ColorID = int.Parse(col) }; newDog.DogColors.Add(colToAdd); } } if (await TryUpdateModelAsync <Dog>(newDog, "Dog", i => i.Image, i => i.Country, i => i.Weight, i => i.DateOfBirth, i => i.BreedID)) { _context.Dog.Add(newDog); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateAssignedColorData(_context, newDog); return(Page()); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Color.Add(Color); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Dog = await _context.Dog.FindAsync(id); if (Dog != null) { _context.Dog.Remove(Dog); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }