Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, Transport transport)
        {
            if (id != transport.TransportId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    transport.DateUpdated = DateTime.Now;
                    _context.Update(transport);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TransportExists(transport.TransportId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BrandId"]   = new SelectList(_context.Brands, "BrandId", "BrandName", transport.BrandId);
            ViewData["BusTypeId"] = new SelectList(_context.BusTypes, "BusTypeId", "TypeName", transport.BusTypeId);
            return(View(transport));
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id, Route route)
        {
            if (id != route.RouteId)
            {
                return(NotFound());
            }
            var cityfrom = _context.Cities.FirstOrDefault(x => x.CityId == route.CityFrom);
            var cityto   = _context.Cities.FirstOrDefault(x => x.CityId == route.CityTo);

            route.Mileage = (int?)CalcDist(cityfrom, cityto);
            if (ModelState.IsValid)
            {
                try
                {
                    route.DateUpdated = DateTime.Now;
                    _context.Update(route);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RouteExists(route.RouteId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CityFrom"] = new SelectList(_context.Cities, "CityId", "City1", route.CityFrom);
            ViewData["CityTo"]   = new SelectList(_context.Cities, "CityId", "City1", route.CityTo);
            return(View(route));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, Worker worker)
        {
            if (id != worker.WorkerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    worker.DateUpdated = DateTime.Now;
                    _context.Update(worker);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WorkerExists(worker.WorkerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RoleId"] = new SelectList(_context.Roles.Where(x => x.Role1 != "Admin"), "RoleId", "Role1", worker.RoleId);
            return(View(worker));
        }
Esempio n. 4
0
        public async Task <IActionResult> Edit(int id, Schedule schedule)
        {
            if (id != schedule.ScheduleId)
            {
                return(NotFound());
            }

            var s = _context.Schedules.FirstOrDefault(x => x.ScheduleId == id);
            var r = _context.Routes.Include(x => x.CityFromNavigation)
                    .Include(x => x.CityToNavigation)
                    .FirstOrDefault(x => x.RouteId == s.RouteId);
            var dist = CalcDist(r.CityFromNavigation, r.CityToNavigation);

            schedule.EndDateTime = CalcTime(schedule, dist);
            if (ModelState.IsValid)
            {
                try
                {
                    schedule.DateUpdated = DateTime.Now;
                    _context.Update(schedule);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ScheduleExists(schedule.ScheduleId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Transport"] = new SelectList(_context.Transports
                                                   .Include(x => x.Brand), "TransportId", "TransportName", schedule.TransportId);
            ViewData["Worker"] = new SelectList(_context.Workers.Include(x => x.Role)
                                                .Where(x => x.Role.Role1.Contains("Driver")), "WorkerId", "WorkerFullName", schedule.WorkerId);
            return(View(schedule));
        }