public async Task <IActionResult> Edit(int id, [Bind("Id,ElectionId,CityId,VoterId")] ControlCoupon controlCoupon) { if (id != controlCoupon.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(controlCoupon); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ControlCouponExists(controlCoupon.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CityId"] = new SelectList(_context.City, "Id", "City1", controlCoupon.CityId); ViewData["ElectionId"] = new SelectList(_context.Election, "Id", "Id", controlCoupon.ElectionId); ViewData["VoterId"] = new SelectList(_context.Voter, "Id", "Id", controlCoupon.VoterId); return(View(controlCoupon)); }
public async Task <IActionResult> Create([Bind("Id,ElectionId,CityId,VoterId")] ControlCoupon controlCoupon) { if (ModelState.IsValid) { _context.Add(controlCoupon); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CityId"] = new SelectList(_context.City, "Id", "City1", controlCoupon.CityId); ViewData["ElectionId"] = new SelectList(_context.Election, "Id", "Id", controlCoupon.ElectionId); ViewData["VoterId"] = new SelectList(_context.Voter, "Id", "Id", controlCoupon.VoterId); return(View(controlCoupon)); }