public async Task <IActionResult> Edit(int id, [Bind("Id,StartCityId,EndCityId,DateUpdated")] RoutDTO rout)
        {
            if (id != rout.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _dbAccess.EditRout(rout);
                    _dbAccess.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RoutExists(rout.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            var cities = _dbAccess.GetCities();

            ViewData["EndCityId"]   = new SelectList(cities, "Id", "Name", rout.EndCityId);
            ViewData["StartCityId"] = new SelectList(cities, "Id", "Name", rout.StartCityId);
            return(View(rout));
        }
Exemple #2
0
        public void EditRout(RoutDTO routDto)
        {
            var rout = Context.Routes.Where(x => x.Id == routDto.Id).FirstOrDefault();

            rout.StartCityId = routDto.StartCityId;
            rout.EndCityId   = routDto.EndCityId;
            rout.DateUpdated = DateTime.Now;
        }
        public async Task <IActionResult> Create([Bind("Id,StartCityId,EndCityId,DateUpdated")] RoutDTO rout)
        {
            if (ModelState.IsValid)
            {
                _dbAccess.AddRout(rout.StartCityId, rout.EndCityId, rout.Distance);
                _dbAccess.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }
            var cities = _dbAccess.GetCities();

            ViewData["EndCityId"]   = new SelectList(cities, "Id", "Name", rout.EndCityId);
            ViewData["StartCityId"] = new SelectList(cities, "Id", "Name", rout.StartCityId);
            return(View(rout));
        }