Пример #1
0
        public async Task <IActionResult> CreateBrand(Brand brand)
        {
            if (ModelState.IsValid)
            {
                brand.DateAdded   = DateTime.Now;
                brand.DateUpdated = DateTime.Now;
                _context.Add(brand);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                return(RedirectToAction("Create"));
            }
            return(View(brand));
        }
Пример #2
0
        public async Task <IActionResult> Create(Schedule schedule)
        {
            var r = _context.Routes.Include(x => x.CityFromNavigation)
                    .Include(x => x.CityToNavigation)
                    .FirstOrDefault(x => x.RouteId == schedule.RouteId);
            var dist = CalcDist(r.CityFromNavigation, r.CityToNavigation);

            schedule.EndDateTime = CalcTime(schedule, dist);
            if (ModelState.IsValid)
            {
                schedule.DateAdded   = DateTime.Now;
                schedule.DateUpdated = DateTime.Now;
                _context.Add(schedule);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Route"] = new SelectList(_context.Routes
                                               .Include(x => x.CityFromNavigation)
                                               .Include(x => x.CityToNavigation), "RouteId", "RouteName", schedule.RouteId);
            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));
        }
Пример #3
0
        public ActionResult CalculatePrice(Ticket t)
        {
            var obj = _context.RouteStops.Include(x => x.City)
                      .Include(x => x.Route).FirstOrDefault(x => x.StopId == t.RouteStopFrom);
            var obj2 = _context.RouteStops.Include(x => x.City)
                       .Include(x => x.Route).FirstOrDefault(x => x.StopId == t.RouteStopTo);

            obj.DistanceToStop  = CalcDist(obj.Route.CityFromNavigation, obj.City);
            obj2.DistanceToStop = CalcDist(obj2.Route.CityFromNavigation, obj2.City);
            var      schedule  = tmpobj as Schedule;
            var      transport = _context.Transports.FirstOrDefault(x => x.TransportId == schedule.TransportId);
            DateTime startTime = CalcTime(schedule, obj);
            DateTime endTime   = CalcTime(schedule, obj2);

            t.ScheduleId = schedule.ScheduleId;
            t.Price      = (decimal)((transport.PricePerKm * (decimal?)(obj2.DistanceToStop - obj.DistanceToStop)));
            if (t.Price > 1000 && t.Price < 10000)
            {
                t.Price /= 10;
            }
            else if (t.Price > 10001)
            {
                t.Price /= 100;
            }
            t.RouteStopFrom = obj.StopId;
            t.RouteStopTo   = obj2.StopId;
            t.StartTime     = startTime;
            t.ArrivalTime   = endTime;
            t.DateAdded     = DateTime.Now;
            t.DateUpdated   = DateTime.Now;
            _context.Add(t);
            _context.SaveChanges();
            var tc = _context.Tickets.ToList().Last();

            return(RedirectToAction("Create", tc));
        }
Пример #4
0
        public async Task <IActionResult> Create(Route route)
        {
            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)
            {
                route.DateAdded   = DateTime.Now;
                route.DateUpdated = DateTime.Now;
                _context.Add(route);
                await _context.SaveChangesAsync();

                var r = _context.Routes.ToList().Last();
                AddStoping(r);
                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));
        }