示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("IdPercorso,IdSottorete,IdStazioneOrigine,IdStazioneDestinazione,IdVia1,IdVia2,Distanza,Version")] PercorsiModel percorsiModel)
        {
            if (id != percorsiModel.IdPercorso)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(percorsiModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PercorsiModelExists(percorsiModel.IdPercorso))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(percorsiModel));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind(include: "IdPercorso,IdSottorete,Distanza,Versione")] PercorsiModel percorsiModel)
        {
            percorsiModel.IdStazioneOrigine      = System.Convert.ToInt32(Request.Form["drpOriginalStation"]);
            percorsiModel.IdStazioneDestinazione = System.Convert.ToInt32(Request.Form["drpDestinationStation"]);
            percorsiModel.IdVia1 = System.Convert.ToInt32(Request.Form["drpVia1Station"]);
            percorsiModel.IdVia2 = System.Convert.ToInt32(Request.Form["drpVia2Station"]);
            if (ModelState.IsValid)
            {
                _context.Add(percorsiModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PathService pathService = new PathService(_context);

            ViewBag.originalStationsList    = pathService.ReturnListStationsForDropDowns(percorsiModel.IdStazioneOrigine, false);
            ViewBag.destinationStationsList = pathService.ReturnListStationsForDropDowns(percorsiModel.IdStazioneDestinazione, false);
            ViewBag.via1StationsList        = pathService.ReturnListStationsForDropDowns(percorsiModel.IdVia1, true);
            ViewBag.via2StationsList        = pathService.ReturnListStationsForDropDowns(percorsiModel.IdVia2, true);
            return(View(percorsiModel));
        }
 public PercorsiViewModel(PercorsiModel percorso)
 {
     _percorso = percorso;
 }