public Ride CreateRide(Money price, int driverId, DriverDetails driverDetails, Address startPoint, Address destination) { var startRoute = _routeService.CreateRoute(startPoint); var destinationRoute = _routeService.CreateRoute(destination, startRoute); return(new Ride(price, driverId, driverDetails, startRoute, destinationRoute)); }
public NewRouteDTO CreateRoute(int driverId, int carId, int[] parcelIds) { NewRouteDTO dto; try { Route route = _routeService.CreateRoute(driverId, carId, parcelIds); foreach (RoutePoint point in route.RoutePoints) { _parcelService.AssignCourier(point.Parcel, driverId); _parcelService.ChangeParcelStatus(point.Parcel, Model.Enums.ParcelStatus.OnWayToTheCustomer); } dto = new NewRouteDTO() { Route = route, Status = Enums.NewRouteStatus.Success }; } catch (Exception ex) { dto = new NewRouteDTO() { ErrorMessage = ex.Message, Status = Enums.NewRouteStatus.Failure }; } return(dto); }
public ActionResult <Route> Post([FromBody] Route route) { try { return(Ok(_routeService.CreateRoute(route))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IActionResult Create([FromBody] RouteDto routeDto) { var userId = Convert.ToInt32(HttpContext.User.Identity.Name); List <string> routePoints = new List <string> { routeDto.FirstPoint, routeDto.LastPoint }; if (routeDto.MiddlePoints != null && routeDto.MiddlePoints.Length != 0) { routePoints.AddRange(routeDto.MiddlePoints); } _routeService.CreateRoute(routeDto.RouteName, routePoints, userId); return(Ok()); }
public void Post(RouteViewModel routeViewModel) { _routeService.CreateRoute(routeViewModel); }
public IActionResult CreateRoute([FromBody] RouteVM routeViewModel) { return(GetResult(() => _routeService.CreateRoute(routeViewModel.MapToRouteModel()), r => r)); }
//data are not deleted, depends on specific id private static void FindRouteTest() { try { stationService = Container.Resolve <IStationService>(); routeService = Container.Resolve <IRouteService>(); vehicleService = Container.Resolve <IVehicleService>(); companyService = Container.Resolve <ICompanyService>(); stationService.CreateStation(new StationDTO { Name = "Ceska", Town = "Brno" }); stationService.CreateStation(new StationDTO { Name = "Hlavni", Town = "Brno" }); stationService.CreateStation(new StationDTO { Name = "Olomoucka", Town = "Brno" }); stationService.CreateStation(new StationDTO { Name = "Klusackova", Town = "Brno" }); routeService.CreateRoute(new RouteDTO { Name = "First Route" }, companyId); routeService.CreateRoute(new RouteDTO { Name = "Second Route" }, companyId); var route = routeService.ListAllRoutes().Last(); var stations = stationService.GetAllStationsByTown("Brno"); int order = 1; foreach (var station in stations) { routeService.AddRouteStation(station.ID, route.ID, new RouteStationDTO { DepartFromFirstStation = DateTime.Today, DistanceFromPreviousStation = 2, TimeFromFirstStation = new TimeSpan(0, 5, 0), TimeToNextStation = new TimeSpan(0, 0, 0), Order = order }); order++; } } catch (ArgumentException e) { Console.WriteLine(e.Message); } //routeService.FindRoutesWithStations(1, 3, DateTime.Today); }
private static void TicketServiceTest() { customerService = Container.Resolve <ICustomerService>(); ticketService = Container.Resolve <ITicketService>(); stationService = Container.Resolve <IStationService>(); routeService = Container.Resolve <IRouteService>(); vehicleService = Container.Resolve <IVehicleService>(); Console.WriteLine("Testing ticket and route service"); routeService.CreateRoute(new RouteDTO { Name = "Tylova-Ceska" }, companyId); stationService.CreateStation(new StationDTO { Name = "Ceska", Town = "Brno" }); stationService.CreateStation(new StationDTO { Name = "Tylova", Town = "Brno" }); var stations = stationService.GetAllStationsByTown("Brno"); var routeId = routeService.ListAllRoutes().FirstOrDefault().ID; foreach (var station in stations) { if (station.Name.Equals("Ceska")) { routeService.AddRouteStation(station.ID, routeId, new RouteStationDTO { DepartFromFirstStation = null, DistanceFromPreviousStation = 0, TimeFromFirstStation = new TimeSpan(0, 0, 0), TimeToNextStation = new TimeSpan(0, 5, 0), }); } else { routeService.AddRouteStation(station.ID, routeId, new RouteStationDTO { DepartFromFirstStation = null, DistanceFromPreviousStation = 2, TimeFromFirstStation = new TimeSpan(0, 5, 0), TimeToNextStation = new TimeSpan(0, 0, 0), }); } } vehicleService.CreateVehicle(new VehicleDTO { LicencePlate = "a", VehicleType = VehicleType.Bus, SeatCount = 2 }, companyId); routeService.CreateSpecificRoute(routeId, DateTime.Now, vehicleService.GetVehicleIdByLicencePlate("a")); var listRouteStations = routeService.GetRouteStationsByRoute(routeId); int[] listRouteStationsForTicket = new int[2]; int i = 0; foreach (var routeStation in listRouteStations) { if (routeStation.DepartFromFirstStation != null) { listRouteStationsForTicket[i] = routeStation.ID; i++; } } customerService.CreateCustomer(new CustomerDTO { FirstName = "Josef", LastName = "Kosta", Email = "*****@*****.**" }); var customerDto = customerService.GetCustomerByEmail("*****@*****.**"); ticketService.CreateTicket(customerDto.ID, companyId, new TicketDTO { Departure = DateTime.Now + (new TimeSpan(2, 0, 0)), RouteName = "Ceska" }, routeService.ListEmptyProgramsOfRouteStations(listRouteStationsForTicket).First()); var ticketId = ticketService.ListAllTickets().FirstOrDefault().ID; ticketService.TicketReservation(ticketId); Console.WriteLine(ticketService.GetTicketById(ticketId).Price == 4 ? "OK: Ticket reservation works... sorry deadline in 1 hour and I managed to create ticket 10 minutes ago so no time for clever tests" : "NOK:Ticket does not work"); discountService = Container.Resolve <IDiscountService>(); discountService.CreateDiscount(new DiscountDTO { Value = 50, DiscountType = DiscountType.Student }, companyId); var discountId = discountService.ListDiscountsOfCompany(null, companyId).First().ID; ticketService.ClaimDiscount(ticketId, discountId, false, null); Console.WriteLine(ticketService.GetTicketById(ticketId).Price == 2 ? "OK: Ticket claim discount works... 10 min to deadline...." : "NOK:Ticket does not work"); ticketService.TicketRefund(ticketId); Console.WriteLine(ticketService.GetTicketById(ticketId).IsRefunded ? "OK: Ticket refund works... idk if this is worth 2 credits :/" : "NOK:Ticket does not work"); routeService.DeleteRoute(routeId); foreach (var station in stations) { stationService.DeleteStation(station.ID); } customerService.DeleteCustomer(customerDto.ID); }
public void CreateRoute(RouteDTO routeDTO, int companyId) { routeService.CreateRoute(routeDTO, companyId); }