public async Task <IActionResult> Create(TrapCatchEventView trapCatchEvent) { if (ModelState.IsValid) { IQueryable <Manager> query = _context.Manager.Where(b => b.Name == trapCatchEvent.ManagerName && b.Password == trapCatchEvent.ManagerPassword); if (query.Count() == 0) { return(BadRequest("Bad Username Password Combo")); } var catchEvent = new TrapCatchEvent { date = trapCatchEvent.date, AnimalId = trapCatchEvent.AnimalId, ManagerId = query.First().Id, TrapId = trapCatchEvent.TrapId }; _context.Add(catchEvent); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AnimalId"] = new SelectList(_context.Animal, "Id", "Name", trapCatchEvent.AnimalId); ViewData["TrapId"] = new SelectList(_context.Trap, "Id", "Name", trapCatchEvent.TrapId); return(View(trapCatchEvent)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,date,TrapId,AnimalId,ManagerId")] TrapCatchEvent trapCatchEvent) { if (id != trapCatchEvent.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(trapCatchEvent); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TrapCatchEventExists(trapCatchEvent.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AnimalId"] = new SelectList(_context.Animal, "Id", "Name", trapCatchEvent.AnimalId); ViewData["ManagerId"] = new SelectList(_context.Manager, "Id", "Name", trapCatchEvent.ManagerId); ViewData["TrapId"] = new SelectList(_context.Trap, "Id", "Name", trapCatchEvent.TrapId); return(View(trapCatchEvent)); }