public IActionResult UpdateSchedule(int id) { if (HttpContext.Session.GetString("UserRole") == "1") { var bus = _context.Buses.AsNoTracking().ToList(); ViewBag.Bus = new SelectList(bus, "BusId", "CoachName"); var Route1 = _context.Places.AsNoTracking().ToList(); ViewBag.Road = new SelectList(Route1, "PlaceId", "PlaceName"); var s = _context.BusSchedules.AsNoTracking().Where(sa => sa.BusScheduleId == id).FirstOrDefault(); BusScheduleVm sp = new BusScheduleVm() { BusScheduleId = s.BusScheduleId, Destination = s.Destination, StartingFrom = s.StartingFrom, Time = s.Time, BusId = s.BusId, TicketPrice = s.TicketPrice }; return(View(sp)); } else { return(RedirectToAction("Index", "Home")); } }
public IActionResult DetailsSchedule(int id) { if (HttpContext.Session.GetString("UserRole") == "1") { var s = _context.BusSchedules.AsNoTracking().Where(sa => sa.BusScheduleId == id).Include(p => p.Bus).FirstOrDefault(); var Destination = _context.Places.Where(ss => ss.PlaceId == s.Destination).FirstOrDefault(); var Start = _context.Places.Where(ss => ss.PlaceId == s.StartingFrom).FirstOrDefault(); BusScheduleVm sp = new BusScheduleVm() { BusScheduleId = s.BusScheduleId, DestinationName = Destination.PlaceName, StartingFromName = Start.PlaceName, Time = s.Time, TicketPrice = s.TicketPrice, CoachName = s.Bus.CoachName }; return(View(sp)); } else { return(RedirectToAction("Index", "Home")); } }
public IActionResult DeleteSchedule(BusScheduleVm a) { var s = _context.BusSchedules.AsNoTracking().Where(sa => sa.BusScheduleId == a.BusScheduleId).FirstOrDefault(); _context.BusSchedules.Remove(s); _context.SaveChanges(); return(RedirectToAction("ScheduleList")); }
public IActionResult ScheduleList() { if (HttpContext.Session.GetString("UserRole") != null) { var ss = _context.BusSchedules.AsNoTracking().Include(sp => sp.Bus).ToList(); var p = _context.Places.AsNoTracking().ToList(); var pp = _context.Places.AsNoTracking().ToList(); var s = from a in ss join ab in p on a.StartingFrom equals ab.PlaceId join aaab in pp on a.Destination equals aaab.PlaceId select new { BusScheduleId = a.BusScheduleId, DestinationName = aaab.PlaceName, StartingFromName = ab.PlaceName, Time = a.Time, CoachName = a.Bus.CoachName, TicketPrice = a.TicketPrice }; var sent = new List <BusScheduleVm>(); int c = 1; foreach (var item in s) { BusScheduleVm sp = new BusScheduleVm() { BusScheduleId = item.BusScheduleId, DestinationName = item.DestinationName, StartingFromName = item.StartingFromName, Time = item.Time, Serial = c, CoachName = item.CoachName, TicketPrice = item.TicketPrice }; sent.Add(sp); c++; } return(View(sent)); } else { return(RedirectToAction("Index", "Home")); } }
public IActionResult AddSchedule(BusScheduleVm a) { BusSchedule s = new BusSchedule() { BusScheduleId = 0, Destination = a.Destination, StartingFrom = a.StartingFrom, Time = a.Time, BusId = a.BusId, TicketPrice = a.TicketPrice }; _context.BusSchedules.Add(s); _context.SaveChanges(); return(RedirectToAction("ScheduleList")); }
public IActionResult UpdateSchedule(BusScheduleVm a) { if (HttpContext.Session.GetString("UserRole") == "1") { BusSchedule s = new BusSchedule() { BusScheduleId = a.BusScheduleId, Destination = a.Destination, StartingFrom = a.StartingFrom, Time = a.Time, BusId = a.BusId, TicketPrice = a.TicketPrice }; _context.BusSchedules.Update(s); _context.SaveChanges(); return(RedirectToAction("ScheduleList")); } else { return(RedirectToAction("Index", "Home")); } }