#nullable disable using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.EntityFrameworkCore; using WebApplication1.Data; using WebApplication1.Models; namespace WebApplication1.Controllers { public class RuloosController : Controller { private readonly Ruloo2Context _context; public RuloosController(Ruloo2Context context) { _context = context; } // GET: Ruloos public async Task Index() { return View(await _context.Ruloo.ToListAsync()); } public IActionResult KinnitamataParingud() { return View(_context.Ruloo.Where(r => r.Kinnitatud == false)); } // GET: Ruloos/Details/5 public async Task Details(int? id) { if (id == null) { return NotFound(); } var ruloo = await _context.Ruloo .FirstOrDefaultAsync(m => m.Id == id); if (ruloo == null) { return NotFound(); } return View(ruloo); } public string SalvestusTeade() { return "andmed salvestatud"; } // GET: Ruloos/Create public IActionResult Create() { return View(); } // POST: Ruloos/Create // To protect from overposting attacks, enable the specific properties you want to bind to. // For more details, see http://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] public async Task Create([Bind("Id,Email,Pikkus,Laius")] Ruloo ruloo) { if (ModelState.IsValid) { ruloo.Kinnitatud = false; _context.Add(ruloo); await _context.SaveChangesAsync(); // return RedirectToAction(nameof(Index)); return RedirectToAction(nameof(SalvestusTeade)); } return View(ruloo); } // GET: Ruloos/Edit/5 public async Task Edit(int? id) { if (id == null) { return NotFound(); } var ruloo = await _context.Ruloo.FindAsync(id); if (ruloo == null) { return NotFound(); } return View(ruloo); } // POST: Ruloos/Edit/5 // To protect from overposting attacks, enable the specific properties you want to bind to. // For more details, see http://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] public async Task Edit(int id, [Bind("Id,Email,Pikkus,Laius,Kinnitatud")] Ruloo ruloo) { if (id != ruloo.Id) { return NotFound(); } if (ModelState.IsValid) { try { _context.Update(ruloo); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RulooExists(ruloo.Id)) { return NotFound(); } else { throw; } } return RedirectToAction(nameof(Index)); } return View(ruloo); } // GET: Ruloos/Delete/5 public async Task Delete(int? id) { if (id == null) { return NotFound(); } var ruloo = await _context.Ruloo .FirstOrDefaultAsync(m => m.Id == id); if (ruloo == null) { return NotFound(); } return View(ruloo); } // POST: Ruloos/Delete/5 [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] public async Task DeleteConfirmed(int id) { var ruloo = await _context.Ruloo.FindAsync(id); _context.Ruloo.Remove(ruloo); await _context.SaveChangesAsync(); return RedirectToAction(nameof(Index)); } private bool RulooExists(int id) { return _context.Ruloo.Any(e => e.Id == id); } } }