public IActionResult BusList()
 {
     if (HttpContext.Session.GetString("UserRole") != null)
     {
         var s       = _context.GetAllBuses();
         var busList = new List <BusVm>();
         int c       = 1;
         foreach (var item in s)
         {
             BusVm a = new BusVm
             {
                 BusId     = item.BusId,
                 BusNumber = item.BusNumber,
                 TotalSeat = item.TotalSeat,
                 CoachName = item.CoachName,
             };
             a.BusSerial = c;
             c++;
             busList.Add(a);
         }
         return(View(busList));
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
        public void DeleteBus(BusVm id)
        {
            var i = _context.Buses.AsNoTracking().Where(s => s.BusId == id.BusId).FirstOrDefault();

            if (i != null)
            {
                _context.Buses.Remove(i);
                _context.SaveChanges();
            }
        }
        public void UpdateBus(BusVm BusVm)
        {
            Bus bus = new Bus()
            {
                BusId     = BusVm.BusId,
                BusNumber = BusVm.BusNumber,
                CoachName = BusVm.CoachName,
                TotalSeat = BusVm.TotalSeat,
            };

            _context.Buses.Update(bus);
            _context.SaveChanges();
        }
        public BusVm GetBus(int id)
        {
            var i = _context.Buses.AsNoTracking().Where(s => s.BusId == id).FirstOrDefault();

            if (i == null)
            {
                i = new Bus();
            }
            BusVm sr = new BusVm {
                BusId     = i.BusId,
                BusNumber = i.BusNumber,
                TotalSeat = i.TotalSeat,
                CoachName = i.CoachName,
            };

            return(sr);
        }
 public IActionResult DeleteBus(BusVm a)
 {
     _context.DeleteBus(a);
     return(RedirectToAction("BusList"));
 }
 public IActionResult NewBus(BusVm v)
 {
     _context.AddNewBus(v);
     ModelState.Clear();
     return(View());
 }
 public IActionResult UpdateBus(BusVm v)
 {
     _context.UpdateBus(v);
     return(RedirectToAction("BusList"));
 }