public IActionResult PostAddBusWithDriverToRoute(int routeId, BusWithDriverDto busWithDriverDto) { try { var newRouteBus = new RouteBus { BusID = busWithDriverDto.BusID, RouteID = routeId, BusDriverID = busWithDriverDto.BusDriverID, Status = 0 }; if (this._RouteBusRepository.SaveRouteBus(newRouteBus) > 0) { return(Ok(true)); } return(BadRequest(new BadRequestMessage { Message = new string[] { "The bus fails to add to the route.", "Tip: The bus must already exist.", "The bus driver must already exist.", "The route must already exist.", "The bus and bus driver is already in other rute" } })); } catch (Exception) { return(StatusCode(500, "Internal server error")); } }
public int SaveRouteBus(RouteBus routeBus) { //Is bus,driver and route exist. if ( (!this._Context.Busses.Where(o => o.ID == routeBus.BusID).Any()) || (!this._Context.Routes.Where(o => o.ID == routeBus.RouteID).Any()) || (!this._Context.BusDrivers.Where(o => o.ID == routeBus.BusDriverID).Any()) ) { return(0); } if (routeBus.ID == 0) { //Is bus and driver is already in other route if (this._Context.RouteBusses.Where(o => o.BusDriverID == routeBus.BusDriverID || o.BusID == routeBus.BusID).Any()) { return(0); } this._Context.RouteBusses.Add(routeBus); } else { var routeBusses = this._Context.RouteBusses .Where(o => o.ID == routeBus.ID).ToList(); if (routeBusses.Count <= 0) { return(0); } var dbEntry = routeBusses.First(); if (dbEntry != null) { dbEntry.RouteID = routeBus.RouteID; dbEntry.BusID = routeBus.BusID; dbEntry.BusDriverID = routeBus.BusDriverID; dbEntry.Status = routeBus.Status; dbEntry.Longitude = routeBus.Longitude; dbEntry.Latitude = routeBus.Latitude; } } return(this._Context.SaveChanges()); }
public int SaveRouteBus(RouteBus routeBus) { return(0); }