public async Task <IActionResult> Choosecage1([Bind("ID,Name,Sex,ShopID,CageID,SpeciesID,Date,ColorID,Price")] Animal animal) { if (animal.CageID == null && animal.Name != null) { animal1 = animal; CagesDropDownList(animal.ShopID); return(View(animal)); } animal1.CageID = animal.CageID; if (animal1.CageID == null) { Animal animal2 = animal1; return(Choosecage(animal2)); } var animalToUpdate = _context.Animals .FirstOrDefault(a => a.ID == animal1.ID); try { animalToUpdate.CageID = animal1.CageID; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log.) ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); } return(Redirect("https://localhost:44324/Animals/Edit/" + animalToUpdate.ID)); }
public async Task <IActionResult> Create([Bind("Name,Adress")] Shop shop) { shop.ID = Guid.NewGuid().GetHashCode(); if (ModelState.IsValid) { _context.Add(shop); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(shop)); }
public async Task <IActionResult> Create([Bind("Number,Square")] Cage cage) { cage.ID = Guid.NewGuid().GetHashCode(); cage.ShopID = shopId; if (ModelState.IsValid) { _context.Add(cage); await _context.SaveChangesAsync(); return(Redirect("https://localhost:44324/Cages/Details/" + shopId)); } return(View(cage)); }
public async Task <IActionResult> Create([Bind("Name,LifeTime,Temperature")] Species species, string[] selectedFood) { species.ID = Guid.NewGuid().GetHashCode(); if (selectedFood != null) { species.SpeciesFood = new List <SpeciesFood>(); foreach (var food in selectedFood) { var foodToAdd = new SpeciesFood { SpeciesID = species.ID, FoodID = int.Parse(food), ID = Guid.NewGuid().GetHashCode() }; species.SpeciesFood.Add(foodToAdd); } } if (ModelState.IsValid) { _context.Add(species); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(species)); }