Exemplo n.º 1
0
 public IActionResult Create(TreinDetailViewModel vm)
 {
     if (ModelState.IsValid)
     {
         Trein   trein = converter.ViewModelToTrein(vm);
         decimal id    = repo.CreateTrein(trein);
         return(RedirectToAction("Details", new { id }));
     }
     return(View());
 }
Exemplo n.º 2
0
 public IActionResult Edit(int id)
 {
     try
     {
         TreinDetailViewModel vm = converter.TreinToViewModel(repo.GetTreinbyId(id));
         return(View(vm));
     }
     catch
     {
         return(RedirectToAction(nameof(Index)));
     }
 }
Exemplo n.º 3
0
        public TreinDetailViewModel TreinToViewModel(Trein t)
        {
            TreinDetailViewModel vm = new TreinDetailViewModel()
            {
                Id          = t.Id,
                MaxSnelheid = t.MaxSnelheid,
                Naam        = t.Naam,
                Actief      = t.Actief
            };

            return(vm);
        }
Exemplo n.º 4
0
        public Trein ViewModelToTrein(TreinDetailViewModel vm)
        {
            Trein t = new Trein()
            {
                Id          = vm.Id,
                MaxSnelheid = vm.MaxSnelheid,
                Naam        = vm.Naam,
                Actief      = vm.Actief
            };

            return(t);
        }
Exemplo n.º 5
0
 public IActionResult Edit(TreinDetailViewModel vm)
 {
     try
     {
         Trein trein  = converter.ViewModelToTrein(vm);
         bool  succes = repo.UpdateTrein(trein);
         if (succes)
         {
             return(RedirectToAction("Details", new { trein.Id }));
         }
         return(View());
     }
     catch
     {
         return(View());
     }
 }
Exemplo n.º 6
0
        public IActionResult Details(int id)
        {
            if (id < 1)
            {
                return(BadRequest("Id cannot be 0"));
            }

            Trein trein = repo.GetTreinbyId(id);

            if (trein == null)
            {
                return(BadRequest("Trein could not be found"));
            }

            TreinDetailViewModel vm = converter.TreinToViewModel(trein);

            return(View(vm));
        }